-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathhandlebarsTest.html
123 lines (93 loc) · 3.28 KB
/
handlebarsTest.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
<html>
<head>
<title>Handlebar test</title>
<script src="js/libs/handlebars-v4.1.2.js"></script>
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css"/>
<script id="main-template" type="text/x-handlebars-template">
<h2>{{composition.title}}</h2>
<div class="row">
<div class="col-md-2">
Author:
</div>
<div class="col-md-10">
{{composition.author.display}}
</div>
</div>
<div class="row">
<div class="col-md-2">
Patient
</div>
<div class="col-md-10">
{{#patient patient}}{{/patient}}
</div>
</div>
<div class="row">
<div class="col-md-2">
Medications List
</div>
<div class="col-md-10">
{{#medication_list composition.medications}}{{/medication_list}}
</div>
</div>
<div class="row">
<div class="col-md-2">
Problem List
</div>
<div class="col-md-10">
{{#problem_list composition.problems}}{{/problem_list}}
</div>
</div>
</script>
<!-- Display the patient details-->
<script id="patient-template" type="text/x-handlebars-template">
<div><strong>{{name}}</strong></div>
<div>{{gender}} {{birthDate}}</div>
</script>
<!-- Display a single problem-->
<script id="condition-template" type="text/x-handlebars-template">
<div>
<b>{{name}}</b>
</div>
</script>
<!-- Display a single medication-->
<script id="medication-template" type="text/x-handlebars-template">
<div>
<b>{{name}}</b>
</div>
</script>
</head>
<body style="padding: 8px">
<div id="result"></div>
<script>
let mainTemplate = Handlebars.compile(document.getElementById('main-template').innerHTML)
let patient_template = Handlebars.compile(document.getElementById('patient-template').innerHTML)
let condition_template = Handlebars.compile(document.getElementById('condition-template').innerHTML)
let medication_template = Handlebars.compile(document.getElementById('medication-template').innerHTML)
Handlebars.registerHelper('patient',function(pat) {
return patient_template(pat)
});
Handlebars.registerHelper('problem_list',function(problems) {
console.log(problems)
let html = ""
problems.forEach(function(problem) {
html += condition_template(problem)
});
return html
});
Handlebars.registerHelper('medication_list',function(meds) {
let html = ""
meds.forEach(function(med) {
html += medication_template(med)
});
return html
});
let doc = {};
doc.composition = {author: {"display":"Dr Marcus Welby"},title:"Discharge Summary"};
doc.composition.problems = [{name:"asthma"},{name:"diabetes"}];
doc.composition.medications = [{name:"Atenolol 25mg mane"},{name:"Frusemide 40mg mane"}];
doc.patient = {name:'John Doe',gender:"male",birthDate:"1955-12-16"}
let html = mainTemplate(doc)
document.getElementById('result').innerHTML = html;
</script>
</body>
</html>