forked from jddamore/IPSviewer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathips_view.html
339 lines (322 loc) · 15.1 KB
/
ips_view.html
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css"
integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.3/css/all.css" integrity="sha384-UHRtZLI+pbxtHCWp1t77Bi1L4ZtiqrqD80Kn4Z8NTSRyMA2Fd33n5dQ8lWUE00s/" crossorigin="anonymous">
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"
integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49"
crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"
integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy"
crossorigin="anonymous"></script>
<script src="https://unpkg.com/[email protected]/dist/squirrelly.min.js"></script>
<!-- Custom CSS-->
<link rel="stylesheet" href="assets/css/custom.css">
<title>IPS Viewer</title>
</head>
<body style="margin: 10px;">
<script type="text/javascript">
$(document).ready(function () {
$("#submit").click(function () {
updateFromText();
});
var loadEjemplo = function(file) {
var jqxhr = $.getJSON(file, function() {
//console.log( "success" );
})
.done(function(data) {
$('#ipsInput').val(JSON.stringify(data));
update(data);
})
.fail(function(e) {
console.log( "error",e );
});
};
$('#clearSample').click(function () {
clearData();
$('.data').empty();
})
$("#loadSample").click(function () {
$.getJSON('./samples/sample.json', function() {
console.log( "success" );
})
.done(function(data) {
$('#ipsInput').val(JSON.stringify(data));
update(data);
})
.fail(function(e) {
console.log( "error",e );
});
// document.getElementById("ipsInput").value = 'sample';
// updateFromText();
});
});
mode = "Entries";
Sqrl.autoEscaping(false);
const clearData = function () {
document.getElementById("ipsInput").value = "";
}
var render = function(templateName, data, targetLocation) {
if (templateName === 'Patient') {
if (!data.custodian) data.custodian = {};
if (!data.custodian.name) data.custodian.name = '[NOT FOUND]';
if (!data.custodian.address || !data.custodian.address[0]) {
data.custodian.address = [{city: '', country: ''}];
}
}
if (mode == "Entries") {
var jqxhr = $.get("templates/" + templateName + ".html", function() {})
.done(function(template) {
// console.log(template);
// console.log(data);
var templateResult = Sqrl.Render(template, data);
$("#" + targetLocation).html(templateResult);
}).fail(function(e) {
console.log( "error",e );
});
} else {
var content = { titulo: data.title, div: "No text defined." };
if (!content.titulo) content.titulo = data.resourceType;
if (data.text) content.div = data.text.div;
var jqxhr = $.get("templates/Text.html", function() {})
.done(function(template) {
var templateResult = Sqrl.Render(template, content);
$("#" + targetLocation).html(templateResult);
}).fail(function(e) {
console.log( "error",e );
});
}
};
var updateFromText = function() {
var ipsTxt = $('#ipsInput').val();
// console.log(ipsTxt);
if (ipsTxt) {
try {
var ips = JSON.parse(ipsTxt);
update(ips);
} catch (e) {
console.log(e);
alert("Invalid IPS - " + e);
}
}
};
var getEntry = function(ips, fullUrl) {
var result;
ips.entry.forEach(function(entry) {
if (entry.fullUrl.includes(fullUrl)) {
console.log(`match ${fullUrl}`);
result = entry.resource;
}
// Attempt to match based on resource and uuid
else {
let newMatch = fullUrl
if (entry.resource && entry.resource.resourceType) {
// remove the resource from reference
newMatch = newMatch.replace(entry.resource.resourceType, '');
// remove slash
newMatch = newMatch.replace(/\//g, '');
// console.log(newMatch);
}
if (entry.fullUrl.includes(newMatch)) {
console.log(`match uuid ${newMatch}`);
result = entry.resource;
}
}
});
if (!result) {
console.log(`missing reference ${fullUrl}`);
result = {};
}
return result;
};
var update = function(ips) {
$(".output").html("");
ips.entry.forEach(function(entry) {
if (!entry.resource) console.log(entry);
if (entry.resource.resourceType == "Composition") {
var composition = entry.resource;
let patient = {};
if (composition.custodian && composition.custodian.reference) {
console.log(composition.custodian.reference);
composition.custodian = getEntry(ips, composition.custodian.reference);
}
else {
console.log('no custodian reference');
composition.custodian = {};
}
if (composition.subject && composition.subject.reference) {
console.log(composition.subject.reference);
patient = getEntry(ips, composition.subject.reference);
}
else console.log('no subject reference');
render("Composition", composition, "Composition");
console.log('Patient Card');
if (patient) {
console.log(patient)
render("Patient", patient, "Patient");
}
alertMissingComposition = false;
composition.section.forEach(function(section) {
if (!section || !section.code || !section.code.coding || !section.code.coding[0])
{
alertMissingComposition = true;
console.log('Section is missing coding information');
}
else if (section.code.coding[0].code == "11450-4") {
console.log('Problems Section');
section.problems = [];
section.entry.forEach(function(problem) {
console.log(problem.reference)
section.problems.push(getEntry(ips, problem.reference));
});
render("Problems", section, "Problems");
}
else if (section.code.coding[0].code == "48765-2") {
console.log('Allergies Section');
section.allergies = [];
section.entry.forEach(function(allergy) {
console.log(allergy.reference)
let allergy2 = getEntry(ips, allergy.reference);
if (!allergy2.category) allergy2.category = [' '];
if (!allergy2.type) allergy2.type = ' ';
section.allergies.push(allergy2);
});
render("Allergies", section, "Allergies");
}
else if (section.code.coding[0].code == "10160-0") {
console.log('Medications Section');
section.medications = [];
section.entry.forEach(function(medication) {
console.log(medication.reference);
var statement = getEntry(ips, medication.reference);
// console.log(statement)
var medicationReference;
if (statement.medicationReference && statement.medicationReference.reference) medicationReference = getEntry(ips, statement.medicationReference.reference);
else if (statement.medicationCodeableConcept) medicationReference = { code: statement.medicationCodeableConcept };
else medicationReference = {code: { coding: [ { system: '', display: '', code: '' } ] } }
// console.log(medicationReference);
section.medications.push({
statement: statement,
medication: medicationReference
});
});
render("Medications", section, "Medications");
}
else if (section.code.coding[0].code == "11369-6") {
console.log('Immunizations Section');
section.immunizations = [];
section.entry.forEach(function(immunization) {
console.log(immunization.reference);
section.immunizations.push(getEntry(ips, immunization.reference));
});
render("Immunizations", section, "Immunizations");
}
else if (section.code.coding[0].code == "30954-2") {
console.log('Observations Section');
section.observations = [];
section.entry.forEach(function(observation) {
console.log(observation.reference);
section.observations.push(getEntry(ips, observation.reference));
});
render("Observations", section, "Observations");
}
});
if (alertMissingComposition) alert('Missing coding information in Composition resource. Rendering may be incomplete.')
}
});
};
</script>
<h1>International Patient Summary (IPS) Viewer for Connectathon</h1>
<div>
Links to <a href="https://hl7.org/fhir/uv/ips/">published Implementation Guide</a>, the <a href="http://build.fhir.org/ig/HL7/fhir-ips/">latest CI build</a> and <a href="http://build.fhir.org/ig/HL7/fhir-ips/branches/connectathon-2/index.html">Connectathon-2 branch</a>
</div>
<div>
Please note that this tool is an open-source project under development. It only renders the following sections of IPS bundles: Allergies, Immunizations, Medications, Problems and Results
</div>
<hr>
<div><h2>Submit Data</h2>This is for test data only. <strong style="color:red">Please do not submit PHI.</strong></div>
<div style="float:clear"></div>
<div class="container" style="margin:15px;">
<div class="row">
<form class="col col-md-8">
<div class="form-group">
<label for="ipsInput">Paste your IPS here:</label>
<br>
<textarea id="ipsInput" rows="8" style="width: 100%; max-width: 100%;"></textarea>
</div>
<button type="button" id="clearSample" class="btn btn-danger">Clear</button>
<button type="button" id="submit" class="btn btn-primary">View IPS</button>
<span class="dropdown">
<button class="btn btn-secondary dropdown-toggle" id="mode" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Displaying Entries
</button>
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
<a class="dropdown-item" href="javascript:mode='Entries'; $('#mode').html('Displaying Entries Content'); updateFromText();">
Display Entries
</a>
<a class="dropdown-item" href="javascript:mode='Text'; $('#mode').html('Displaying Text'); updateFromText();">
Display Text
</a>
</div>
</span>
</form>
<div class="col col-md-4">
<br />
<button type="button" id="loadSample" class= "btn btn-success">Try a sample</button>
<br />
<a href="https://github.com/jddamore/IPSviewer/tree/main/samples" target="_blank">Repository of IPS Samples</a>
</div>
</div>
</div>
<hr>
<h2>View IPS</h2>
<div class="container" style="margin:15px;">
<div class="row">
<div class="row col-md-12" style="margin: 15px;">
<div class="col-md-6 output data" id="Composition">
</div>
<div class="col-md-6 output data" id="Patient">
</div>
</div>
<div class="row col-md-12" style="margin: 15px;">
<div class="col-md-12 output data" id="Allergies">
</div>
<div class="col-md-12 output data" id="Problems">
</div>
</div>
<div class="row col-md-12" style="margin: 15px;">
<div class="col-md-12 output data" id="Medications">
</div>
</div>
</div>
<div class="row">
<div class="row col-md-12" style="margin: 15px;">
<div class="col-md-12 output data" id="Immunizations">
</div>
</div>
<div class="row col-md-12" style="margin: 15px;">
<div class="col-md-12 output data" id="Observations">
</div>
</div>
</div>
</div>
</div>
<footer>
<lead>Originally created by Diego Kaminker and Fernando Campos. Modified in 2021 by John D'Amore</lead>
<br />
<lead>Based on <a href="https://salud-ar.github.io/IPS-Argentina/demo.html">prior work</a> from <a href="https://github.com/SALUD-AR/IPS-Argentina">this repository</a></lead>
<br />
<lead>Licensed according to Apache 2.0. See <a href="https://github.com/jddamore/IPSviewer">current code repository</a> for details</lead>
<br />
<lead>Hosted by <a href="https://www.moreinformatics.com">More Informatics, Inc.</a></lead>
</footer>
</body>
</html>