Skip to content

Commit

Permalink
Add additionalProperties to Notify via Custom Resources. Small fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
ryukzak committed Jul 24, 2024
1 parent 94353f3 commit 66b0060
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 6 deletions.
13 changes: 11 additions & 2 deletions aidbox-notify-via-custom-resources/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ For that we define the following custom resources:
## Objectives

1. Learn how to use [custom resources](https://docs.aidbox.app/storage-1/custom-resources/custom-resources-using-fhirschema?utm_source=github&utm_medium=readme&utm_campaign=app-examples-repo) via [FHIRSchema](https://github.com/fhir-schema/fhir-schema).
- How to use existing value set with additional constraints as element type.
- How to use FHIRSchema extension for additional properties.
2. Understand how to implement lock behavior via [FHIR condition update](https://build.fhir.org/http.html#cond-update).

<!-- markdown-toc start - Don't edit this section. Run M-x markdown-toc-refresh-toc -->
**Table of Contents**

- [Aidbox Notify via Custom Resources](#aidbox-notify-via-custom-resources)
- [Objectives](#objectives)
- [TOC](#toc)
- [Prerequisites](#prerequisites)
- [Setup Aidbox](#setup-aidbox)
- [FHIRSchema for Custom Resources](#fhirschema-for-custom-resources)
Expand Down Expand Up @@ -95,6 +96,7 @@ type: TutorNotification
name: TutorNotification
base: DomainResource
kind: resource
ALLOW_FHIR_SCHEMA_FHIR_INCOMPATIBLE_EXTENSIONS: true
derivation: specialization
required:
- sendAfter
Expand Down Expand Up @@ -134,9 +136,16 @@ elements:
type: Reference
scalar: true
refers: ["Patient"]
templateParameters:
scalar: true
additionalProperties:
type: string
```
Here we use the standard task status value set ([link](https://hl7.org/fhir/valueset-task-status.html)) for `TutorNotification.status`, but it contains too many codes, so we restrict them via the element-specific constraint.
In this FHIRShema:
- Here we use the standard task status value set ([link](https://hl7.org/fhir/valueset-task-status.html)) for `TutorNotification.status`, but it contains too many codes, so we restrict them via the element-specific constraint.
- Also, we use [additionalProperties FHIRSchema extensions](https://fhir-schema.github.io/fhir-schema/reference/extensions.html#additionalproperties?utm_source=github&utm_medium=readme&utm_campaign=app-examples-repo) which is <u>FHIR incompatible</u> but allows us to put all template parameters in TutorNotification resource.

### Search Parameters

Expand Down
8 changes: 7 additions & 1 deletion aidbox-notify-via-custom-resources/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ window.bootstrap = async () => {
scalar: true,
refers: ["Patient"],
},
templateParameters: {
scalar: true,
additionalProperties: {
type: "string",
},
},
},
},
},
Expand Down Expand Up @@ -198,7 +204,7 @@ window.bootstrap = async () => {
data: {
id: "welcome",
resourceType: "TutorNotificationTemplate",
template: "Hello user name: {{patient.name.given}}",
template: "Hello user name: {{patientName}}",
},
},
// Initial data: Patient
Expand Down
20 changes: 17 additions & 3 deletions aidbox-notify-via-custom-resources/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,21 @@ window.token = () => {
};

window.updateCurrentNotification = (notification, patient, template) => {
if (notification === undefined) {
return (document.getElementById("notification").innerHTML = "");
}
window.notification = notification;
window.patient = patient;
window.template = template;
const html = `id: ${notification.id}\n ${patient.name[0].given[0]} - ${notification.type} - ${notification.status} - ${notification.sendAfter}\n template: ${template.template}\n message: ${template.message}`;
const html = [
`id: ${notification.id}`,
` ${patient.name[0].given[0]} - ${notification.type} - ${notification.status} - ${notification.sendAfter}`,
` template: ${template.template}`,
` templateParameters: ${JSON.stringify(
notification.templateParameters,
)}`,
` message: ${notification.message}`,
].join("\n");
document.getElementById("notification").innerHTML = html;
};

Expand Down Expand Up @@ -81,6 +92,7 @@ window.getNotification = async () => {

const json = await response.json();
if (!json.entry || json.entry.length === 0) {
updateCurrentNotification();
return window.log(
"No requested sms notifications found. Request one first.",
);
Expand Down Expand Up @@ -151,15 +163,17 @@ window.sendNotification = async () => {

////////////////////////////////////////////////////////////
// Place for implementation of sending SMS
const templateParameters = { patientName: window.patient.name[0].given[0] };
const message = window.template.template.replace(
"{{patient.name.given}}",
window.patient.name[0].given[0],
"{{patientName}}",
templateParameters.patientName,
);

const notification = {
...window.notification,
status: "completed",
message: message,
templateParameters: templateParameters,
};

alert("Send SMS:\n\n" + notification.message);
Expand Down

0 comments on commit 66b0060

Please sign in to comment.