-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
502 lines (455 loc) · 18.4 KB
/
index.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
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="John D'Amore, More Informatics">
<title>CDA-FHIR Comparison Tool</title>
<link rel="icon" href="assets/favicon.ico" type="image/x-icon"/>
<link rel="canonical" href="https://getbootstrap.com/docs/5.0/examples/starter-template/">
<link href="/colors.css" rel="stylesheet">
<!-- Bootstrap core CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.4.1/dist/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<style>
textarea {
white-space: pre;
overflow: scroll;
overflow-x: scroll;
}
.inputCodeArea {
font-family: 'Courier New', Courier, monospace
}
.inputCodeArea, .lineCounter {
font-family: lucida console, courier new, courier, monospace;
margin: 0;
padding: 10px 0;
border-radius: 0;
resize: none;
font-size: 16px;
line-height: 1.2;
outline: none;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
.lineCounter:focus-visible,
.inputCodeArea:focus-visible {
outline:none;
}
.lineCounter {
display: flex;
border-color: transparent;
overflow-y: hidden;
text-align: right;
box-shadow: none;
color: #707070;
background-color: #d8d8d8;
position: absolute;
width: 3.5rem;
/* Determine appearance of line counter */
background-color:#3E3D32;
border-color:#3E3D32;
color:#928869;
}
.inputCodeArea {
padding-left: calc(3.5rem + 5px);
width:100%;
/* Determine appearance of code editor */
background-color:#272822;
border-color:#272822;
color:#ffffff;
}
</style>
</head>
<body>
<div class="col-lg-12 mx-auto p-3 py-md-5">
<!--
<header class="d-flex align-items-center pb-3 mb-5 border-bottom">
<a href="/" class="d-flex align-items-center text-dark text-decoration-none"></a>
</header>
-->
<main>
<h1><img src="/assets/cda-favicon.png" style="height:40px"> <mark class="color14">CDA</mark>-<mark class="color13">FHIR</mark> Visualizer Tool <img src="/assets/fhir.png" style="height:40px"></h1>
<p class="col-md-12">This beta tool allows users to submit a CDA entry and FHIR resource and visualize how the data flow using selective data highlighting. It does not provide a mapping between formats. For more on the HL7 projects for mapping CDA/FHIR, please see <a href="https://confluence.hl7.org/display/CGP/C-CDA+to+and+from+US+Core+Mapping">US C-CDA to and from US Core Mapping</a></p>
<hr class="col-md-12 mb-20">
<div class="mb-2">
<button id="allergyButton" class="btn btn-primary btn-lg px-4">Load Allergy example</button>
<button id="immunizationButton" class="btn btn-primary btn-lg px-4">Load Immunization example</button>
<button id="medicationButton" class="btn btn-primary btn-lg px-4">Load Medication example</button>
<button id="patientButton" class="btn btn-primary btn-lg px-4">Load Patient example</button>
<button id="problemButton" class="btn btn-primary btn-lg px-4">Load Problem example</button>
<button id="procedureButton" class="btn btn-primary btn-lg px-4">Load Procedure example</button>
</div>
<div class="mb-2">
<button id="clear" class="btn btn-danger btn-lg px-4">Clear</button>
<button id="formatButton" class="btn btn-secondary btn-lg px-4">Format XML & JSON</button>
<button id="submit" class="btn btn-success btn-lg px-4">Submit Code Below</button>
</div>
<div class="row g-5">
<div class="col-md-6">
<div style="height: 150px">
<h2>Place CDA Entry Here</h2>
<p>Document must contain only a single element. If you copy unformatted XML, please use "Format Code" button above before pressing "Submit". This tool does not validate CDA content and invalid CDA may not generate appropriate highlighting</p>
<!--
<div class="dropdown">
<button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton1" data-bs-toggle="dropdown" aria-expanded="false">
Dropdown button
</button>
<ul class="dropdown-menu" aria-labelledby="dropdownMenuButton1">
<li><a class="dropdown-item" href="#">TBD</a></li>
<li><a class="dropdown-item" href="#">TBD 2</a></li>
<li><a class="dropdown-item" href="#">TBD 3</a></li>
</ul>
</div>
-->
</div>
<textarea id="line1" class='lineCounter' readonly rows="100">1.</textarea>
<textarea id="code1" class="form-control inputCodeArea" rows="100"></textarea>
</div>
<div class="col-md-6">
<div style="height: 150px">
<h2>Place FHIR Resource Here</h2>
<p>Only a single FHIR resource should be included as JSON. If you copy unformatted JSON, please use "Format Code" button above before pressing "Submit". This tool does not validate FHIR content and only accepts JSON.</p>
<!--
<div class="dropdown">
<button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton2" data-bs-toggle="dropdown" aria-expanded="false">
Dropdown button
</button>
<ul class="dropdown-menu" aria-labelledby="dropdownMenuButton2">
<li><a class="dropdown-item" href="#">TBD</a></li>
<li><a class="dropdown-item" href="#">TBD 2</a></li>
<li><a class="dropdown-item" href="#">TBD 3</a></li>
</ul>
</div>
-->
</div>
<textarea id="line2" class='lineCounter' readonly rows="100">1.</textarea>
<textarea id="code2" class="form-control inputCodeArea" rows="100"></textarea>
</div>
</div>
<div class="mb-4"></div>
<div class="row g-5" id="highlightOutput" style="display:none;">
<div class="col-md-6">
<div>
<div class="d-flex justify-content-between align-items-center">
<h2>Highlighted CDA Entry Here</h2>
<button id="copyCDA" class="btn btn-secondary btn-sm">Copy CDA HTML to Clipboard</button>
</div>
<div id="cda" class="border codeArea"></div>
</div>
</div>
<div class="col-md-6">
<div>
<div class="d-flex justify-content-between align-items-center">
<h2>Highlighted FHIR Resource Here</h2>
<button id="copyFHIR" class="btn btn-secondary btn-sm">Copy FHIR HTML to Clipboard</button>
</div>
<div id="fhir" class="border codeArea"></div>
</div>
</div>
</div>
</main>
<footer class="pt-5 my-5 text-muted border-top">
Created by More Informatics, Inc. Code is available open-source in <a href="https://github.com/jddamore/cda-fhir-compare">this repository</a>
HL7, CDA, and FHIR are trademarks of Health Level Seven International.
</footer>
</div>
<!-- need full JQuery for AJAX -->
<script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
<!-- <script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script> -->
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.9.2/dist/umd/popper.min.js" ></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/js/bootstrap.min.js" integrity="sha384-Atwg2Pkwv9vp0ygtn1JAojH0nYbwNJLPhwyoVbhoPwBhjQPR5VtM2+xf0Uwh9KtT" crossorigin="anonymous"></script>
<script src="/assets/js/vkbeautify.js"></script>
<script>
$(function () {
var codeEditor1 = document.getElementById('code1');
var lineCounter1 = document.getElementById('line1');
codeEditor1.addEventListener('scroll', () => {
lineCounter1.scrollTop = codeEditor1.scrollTop;
lineCounter1.scrollLeft = codeEditor1.scrollLeft;
});
var codeEditor2 = document.getElementById('code2');
var lineCounter2 = document.getElementById('line2');
codeEditor2.addEventListener('scroll', () => {
lineCounter2.scrollTop = codeEditor2.scrollTop;
lineCounter2.scrollLeft = codeEditor2.scrollLeft;
});
var lineCountCache = 0;
var lineCountCache2 = 0;
function line_counter1(thing) {
var lineCount = codeEditor1.value.split('\n').length;
var outarr = new Array();
if (lineCountCache !== lineCount) {
for (var x = 0; x < lineCount; x++) {
outarr[x] = (x + 1) + '.';
}
thing.value = outarr.join('\n');
}
lineCountCache = lineCount;
}
function line_counter2(thing2) {
var lineCount2 = codeEditor2.value.split('\n').length;
var outarr2 = new Array();
if (lineCountCache2 !== lineCount2) {
for (var y = 0; y < lineCount2; y++) {
outarr2[y] = (y + 1) + '.';
}
thing2.value = outarr2.join('\n');
}
lineCountCache2 = lineCount2;
}
// Save the contents of codeEditor1 and codeEditor2 to localStorage
function saveContent() {
localStorage.setItem('cdaCompareLeft', codeEditor1.value);
localStorage.setItem('cdaCompareRight', codeEditor2.value);
}
// Load the contents of codeEditor1 and codeEditor2 from localStorage
function loadContent() {
if (localStorage.getItem('cdaCompareLeft')) {
codeEditor1.value = localStorage.getItem('cdaCompareLeft');
line_counter1(lineCounter1);
}
if (localStorage.getItem('cdaCompareRight')) {
codeEditor2.value = localStorage.getItem('cdaCompareRight');
line_counter2(lineCounter2);
}
}
// Call loadContent when the page loads
loadContent();
function handleKeyDown(event, editor) {
const TAB_SIZE = 2;
const value = editor.value;
const end = editor.selectionEnd;
const nothingSelected = editor.selectionStart === editor.selectionEnd;
if (event.key === 'Tab') {
event.preventDefault();
const tab = ' '.repeat(TAB_SIZE);
const start = value.lastIndexOf('\n', editor.selectionStart - 1) + 1;
const before = value.slice(0, start);
const after = value.slice(end);
const lines = value.slice(start, end).split('\n');
if (event.shiftKey) {
// Shift + Tab: Remove indentation
const newLines = lines.map(line => line.startsWith(tab) ? line.slice(TAB_SIZE) : line);
editor.value = before + newLines.join('\n') + after;
editor.selectionEnd = end - TAB_SIZE * lines.length;
editor.selectionStart = nothingSelected ? editor.selectionEnd : start;
} else {
// Tab: Add indentation
const newLines = lines.map(line => tab + line);
editor.value = before + newLines.join('\n') + after;
editor.selectionEnd = end + TAB_SIZE * lines.length;
editor.selectionStart = nothingSelected ? editor.selectionEnd : start;
}
saveContent();
}
if (event.key === 'Enter') {
event.preventDefault();
const start = editor.selectionStart;
const before = value.slice(0, start);
const lineStart = before.lastIndexOf('\n') + 1;
const currentLine = before.slice(lineStart);
const leadingSpaces = currentLine.match(/^\s*/)[0];
const after = value.slice(start);
editor.value = before + '\n' + leadingSpaces + after;
editor.selectionStart = editor.selectionEnd = start + 1 + leadingSpaces.length;
saveContent();
}
// Macs are stupid
if (event.key === 'Home') {
event.preventDefault();
const start = editor.selectionStart;
const lineStart = editor.value.lastIndexOf('\n', start - 1) + 1;
const firstNonWhitespace = editor.value.slice(lineStart).search(/\S|$/) + lineStart;
if (start === firstNonWhitespace) {
editor.selectionStart = editor.selectionEnd = lineStart;
} else {
editor.selectionStart = editor.selectionEnd = firstNonWhitespace;
}
}
if (event.key === 'End') {
event.preventDefault();
editor.selectionStart = editor.selectionEnd = editor.value.indexOf('\n', editor.selectionStart);
if (editor.selectionStart === -1) {
editor.selectionStart = editor.selectionEnd = editor.value.length;
}
}
}
codeEditor1.addEventListener('keydown', (event) => handleKeyDown(event, codeEditor1));
codeEditor2.addEventListener('keydown', (event) => handleKeyDown(event, codeEditor2));
codeEditor1.addEventListener('input', () => {
line_counter1(lineCounter1);
saveContent();
});
codeEditor2.addEventListener('input', () => {
line_counter2(lineCounter2);
saveContent();
});
var format = $('#formatButton');
format.click(function () {
var c1 = $('#code1').val();
$('#code1').val(vkbeautify.xml(c1, 2));
line_counter1(lineCounter1);
var c2 = $('#code2').val();
if (!JSONParseWithComments(c2)) return;
$('#code2').val(vkbeautify.json(c2, 2));
line_counter2(lineCounter2);
});
var clear = $('#clear');
clear.click(function () {
$('#code1').val(' ');
$('#code2').val(' ');
line_counter1(lineCounter1);
line_counter2(lineCounter2);
saveContent();
$('#highlightOutput').hide();
})
$('#allergyButton').click(function () {
getData('allergy')
});
$('#immunizationButton').click(function () {
getData('immunization')
});
$('#medicationButton').click(function () {
getData('medicationRequest')
});
$('#patientButton').click(function () {
getData('patient')
});
$('#problemButton').click(function () {
getData('problem')
});
$('#procedureButton').click(function () {
getData('procedure')
});
var getData = function (type) {
alert(`This is a reconciled example of ${type}.`);
$.ajax({
type: "get",
url: `/examples/ccda-fhir-project/Rec_${type}.txt`,
success: function(data) {
$('#code1').val(vkbeautify.xml(data, 2));
line_counter1(lineCounter1);
},
error: function(xhr, status) {
/* handle error here */
alert('error loading')
}
});
$.ajax({
type: "get",
url: `/examples/ccda-fhir-project/Rec_${type}.json`,
dataType: "json",
success: function(data) {
/* handle data here */
$('#code2').val(vkbeautify.json(data, 2));
line_counter2(lineCounter2);
},
error: function(xhr, status) {
alert('error loading')
}
});
}
var submitData = $('#submit');
submitData.click(function () {
var cda = $('#code1').val();
var fhir = $('#code2').val();
if(!cda) {
alert('ERROR: No CDA content included')
}
else if (!fhir){
alert('ERROR: No FHIR content included');
}
else {
let check = null;
try {
check = JSONParseWithComments(fhir, true); // JSON.parse(fhir);
}
catch(e){
alert('ERROR: FHIR is not proper JSON ' + e.message);
return;
}
if (check && !check.resource && !check.resourceType) {
alert('ERROR: FHIR not formatted properly (missing a resource or resourceType property)');
return;
}
let data = {
cda: cda,
fhir: fhir
};
$.ajax({
type: "post",
url: "/data",
data: data,
success: function(html) {
$('#cda').html($(html).find('#cda').html());
$('#fhir').html($(html).find('#fhir').html());
// Reapply the click event to all <mark> elements, including newly added ones
document.querySelectorAll('mark').forEach(function(mark) {
mark.addEventListener('click', function(event) {
event.stopPropagation();
var text = document.createTextNode(mark.innerText);
mark.parentNode.replaceChild(text, mark);
});
});
$('#highlightOutput').show();
$('html, body').animate({
scrollTop: $("#highlightOutput").offset().top
}, 1000);
},
error: function(xhr, status) {
alert('error with server')
}
});
}
});
});
function compareToast(message) {
var toast = document.createElement('div');
toast.className = 'compareToast';
toast.innerText = message;
document.body.appendChild(toast);
setTimeout(function() {
toast.style.transition = 'opacity 3s';
toast.style.opacity = '0';
setTimeout(function() {
document.body.removeChild(toast);
}, 7000);
}, 3000);
}
document.getElementById('copyCDA').addEventListener('click', function() {
var cdaContent = document.getElementById('cda').outerHTML;
navigator.clipboard.writeText(cdaContent).then(compareToast('CDA content copied to clipboard!'),
function(err) {
alert('Could not copy text: ', err);
});
});
document.getElementById('copyFHIR').addEventListener('click', function() {
var fhirContent = document.getElementById('fhir').outerHTML;
navigator.clipboard.writeText(fhirContent).then(compareToast('FHIR content copied to clipboard!'),
function(err) {
alert('Could not copy text: ', err);
});
});
function JSONParseWithComments(text, strip = false) {
const stripComments = (text) => {
return text.replace(/^\s+\/\/.*$/gm, '').replace(/^\s*\/\*[\s\S]*?\*\//gm, '');
};
try {
if (/\s+(\/\/|\/\*)/.test(text)) {
if (!strip) {
alert('JSON contains comments - Beautify without comments first; then add them back in');
return;
} else {
text = stripComments(text);
}
}
return JSON.parse(text);
} catch (e) {
throw new Error('Invalid JSON: ' + e.message);
}
}
</script>
</body>
</html>