diff --git a/example-smart-app/src/js/example-smart-app.js b/example-smart-app/src/js/example-smart-app.js index f42b370170..2fc4c31148 100644 --- a/example-smart-app/src/js/example-smart-app.js +++ b/example-smart-app/src/js/example-smart-app.js @@ -1,126 +1,5 @@ // example-smart-app.js -const questionnaire = { - "resourceType": "Questionnaire", - "id": "311M", - "meta": { - "versionId": "4", - "lastUpdated": "2024-05-10T15:35:59.356+00:00", - "source": "#6kpooEBakwv4dTIe", - "profile": [ - "http://hl7.org/fhir/4.0/StructureDefinition/Questionnaire" - ], - "tag": [ - { "code": "lformsVersion: 29.0.0" }, - { "code": "lformsVersion: 34.0.2" }, - { "code": "lformsVersion: 34.3.1" } - ] - }, - "title": "Columbia - suicide severity rating scale screener - recent [C-SSRS]", - "status": "draft", - "copyright": "© 2011 Dr. Kelly Posner, first author of the scale. Used with permission", - "code": [ - { - "system": "http://loinc.org", - "code": "93373-9", - "display": "Columbia - suicide severity rating scale screener - recent [C-SSRS]" - } - ], - "item": [ - { - "linkId": "/93246-7", - "text": "Have you wished you were dead or wished you could go to sleep and not wake up?", - "type": "choice", - "answerOption": [ - { "valueCoding": { "code": "LA33-6", "display": "Yes" } }, - { "valueCoding": { "code": "LA32-8", "display": "No" } } - ] - }, - { - "linkId": "/93247-5", - "text": "Have you actually had any thoughts of killing yourself?", - "type": "choice", - "answerOption": [ - { "valueCoding": { "code": "LA33-6", "display": "Yes" } }, - { "valueCoding": { "code": "LA32-8", "display": "No" } } - ] - }, - { - "linkId": "/93248-3", - "text": "Have you been thinking about how you might do this?", - "type": "choice", - "enableWhen": [ - { - "question": "/93247-5", - "operator": "=", - "answerCoding": { "code": "LA33-6", "display": "Yes" } - } - ], - "answerOption": [ - { "valueCoding": { "code": "LA33-6", "display": "Yes" } }, - { "valueCoding": { "code": "LA32-8", "display": "No" } } - ] - }, - { - "linkId": "/93249-1", - "text": "Have you had these thoughts and had some intention of acting on them?", - "type": "choice", - "enableWhen": [ - { - "question": "/93247-5", - "operator": "=", - "answerCoding": { "code": "LA33-6", "display": "Yes" } - } - ], - "answerOption": [ - { "valueCoding": { "code": "LA33-6", "display": "Yes" } }, - { "valueCoding": { "code": "LA32-8", "display": "No" } } - ] - }, - { - "linkId": "/93250-9", - "text": "Have you started to work out or worked out the details of how to kill yourself? Do you intend to carry out this plan?", - "type": "choice", - "enableWhen": [ - { - "question": "/93247-5", - "operator": "=", - "answerCoding": { "code": "LA33-6", "display": "Yes" } - } - ], - "answerOption": [ - { "valueCoding": { "code": "LA33-6", "display": "Yes" } }, - { "valueCoding": { "code": "LA32-8", "display": "No" } } - ] - }, - { - "linkId": "/93267-3", - "text": "Have you ever done anything, started to do anything, or prepared to do anything to end your life?", - "type": "choice", - "answerOption": [ - { "valueCoding": { "code": "LA33-6", "display": "Yes" } }, - { "valueCoding": { "code": "LA32-8", "display": "No" } } - ] - }, - { - "linkId": "/93269-9", - "text": "Was this within the past 3 months?", - "type": "choice", - "enableWhen": [ - { - "question": "/93267-3", - "operator": "=", - "answerCoding": { "code": "LA33-6", "display": "Yes" } - } - ], - "answerOption": [ - { "valueCoding": { "code": "LA33-6", "display": "Yes" } }, - { "valueCoding": { "code": "LA32-8", "display": "No" } } - ] - } - ] -}; - function createQuestionnaireForm(questionnaire) { console.log("Creating form..."); const form = document.getElementById("questionnaire-form"); @@ -153,7 +32,7 @@ function createQuestionnaireForm(questionnaire) { console.log("Form HTML:", form.innerHTML); // Debugging log to inspect form HTML } -function submitQuestionnaire(patientId) { +function submitQuestionnaire(patientId, questionnaire) { console.log("Submitting form..."); const form = document.getElementById("questionnaire-form"); const formData = new FormData(form); @@ -213,14 +92,22 @@ function submitQuestionnaire(patientId) { function onReady(smart) { if (smart.hasOwnProperty('patient')) { var patient = smart.patient; - patient.read().done(function(pt) { - console.log("Patient ID:", pt.id); + var patientPromise = patient.read(); + var questionnairePromise = smart.api.read({type: 'Questionnaire', id: '311M'}); + + $.when(patientPromise, questionnairePromise).done(function(patientData, questionnaireData) { + var patient = patientData[0]; + var questionnaire = questionnaireData[0]; + + console.log("Patient ID:", patient.id); + console.log("Questionnaire:", questionnaire); + createQuestionnaireForm(questionnaire); document.getElementById("submit-button").onclick = function() { - submitQuestionnaire(pt.id); + submitQuestionnaire(patient.id, questionnaire); }; }).fail(function(error) { - console.error("Failed to read patient data:", error); + console.error("Failed to read data:", error); }); } else { console.error("SMART FHIR client does not have patient context.");