diff --git a/aidbox-notify-via-custom-resources/README.md b/aidbox-notify-via-custom-resources/README.md index 482d422..4ac0cc2 100644 --- a/aidbox-notify-via-custom-resources/README.md +++ b/aidbox-notify-via-custom-resources/README.md @@ -20,6 +20,8 @@ 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). @@ -27,7 +29,6 @@ For that we define the following custom resources: - [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) @@ -95,6 +96,7 @@ type: TutorNotification name: TutorNotification base: DomainResource kind: resource +ALLOW_FHIR_SCHEMA_FHIR_INCOMPATIBLE_EXTENSIONS: true derivation: specialization required: - sendAfter @@ -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 FHIR incompatible but allows us to put all template parameters in TutorNotification resource. ### Search Parameters diff --git a/aidbox-notify-via-custom-resources/bootstrap.js b/aidbox-notify-via-custom-resources/bootstrap.js index 25ecec2..9d51e5a 100644 --- a/aidbox-notify-via-custom-resources/bootstrap.js +++ b/aidbox-notify-via-custom-resources/bootstrap.js @@ -104,6 +104,12 @@ window.bootstrap = async () => { scalar: true, refers: ["Patient"], }, + templateParameters: { + scalar: true, + additionalProperties: { + type: "string", + }, + }, }, }, }, @@ -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 diff --git a/aidbox-notify-via-custom-resources/index.js b/aidbox-notify-via-custom-resources/index.js index 85c5838..4ca402d 100644 --- a/aidbox-notify-via-custom-resources/index.js +++ b/aidbox-notify-via-custom-resources/index.js @@ -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; }; @@ -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.", ); @@ -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);