Skip to content

Commit

Permalink
mh
Browse files Browse the repository at this point in the history
  • Loading branch information
rob-reynolds committed May 18, 2024
1 parent 2e8b579 commit c31fb55
Showing 1 changed file with 13 additions and 126 deletions.
139 changes: 13 additions & 126 deletions example-smart-app/src/js/example-smart-app.js
Original file line number Diff line number Diff line change
@@ -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");
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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.");
Expand Down

0 comments on commit c31fb55

Please sign in to comment.