-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathget-data.js
49 lines (41 loc) · 1.56 KB
/
get-data.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
function getPatientName (pt) {
if (pt.name) {
var names = pt.name.map(function(name) {
return name.given.join(" ") + " " + name.family.join(" ");
});
return names.join(" / ")
} else {
return "anonymous";
}
}
function getMedicationName (medCodings) {
var coding = medCodings.find(function(c){
return c.system == "http://www.nlm.nih.gov/research/umls/rxnorm";
});
return coding && coding.display || "Unnamed Medication(TM)"
}
function displayPatient (pt) {
document.getElementById('patient_name').innerHTML = getPatientName(pt);
}
var med_list = document.getElementById('med_list');
function displayMedication (medCodings) {
med_list.innerHTML += "<li> " + getMedicationName(medCodings) + "</li>";
}
// Create a FHIR client (server URL, patient id in `demo`)
var smart = FHIR.client(demo),
pt = smart.patient;
// Create a patient banner by fetching + rendering demographics
smart.patient.read().then(function(pt) {
displayPatient (pt);
});
// A more advanced query: search for active Prescriptions, including med details
smart.patient.api.fetchAllWithReferences({type: "MedicationOrder"},["MedicationOrder.medicationReference"]).then(function(results, refs) {
results.forEach(function(prescription){
if (prescription.medicationCodeableConcept) {
displayMedication(prescription.medicationCodeableConcept.coding);
} else if (prescription.medicationReference) {
var med = refs(prescription, prescription.medicationReference);
displayMedication(med && med.code.coding || []);
}
});
});