lforms 29.3.0 → 33.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +261 -0
- package/README.md +97 -14
- package/changed-features.md +99 -0
- package/dist/lforms/LICENSE.md +70 -0
- package/dist/lforms/README.md +100 -0
- package/dist/lforms/fhir/R4/lformsFHIR.min.js +2 -0
- package/dist/lforms/fhir/R4/lformsFHIR.min.js.map +1 -0
- package/dist/lforms/fhir/STU3/lformsFHIR.min.js +2 -0
- package/dist/lforms/fhir/STU3/lformsFHIR.min.js.map +1 -0
- package/dist/lforms/fhir/lformsFHIRAll.min.js +2 -0
- package/dist/lforms/fhir/lformsFHIRAll.min.js.map +1 -0
- package/dist/lforms/webcomponent/assets/lib/zone.min.js +134 -0
- package/dist/lforms/webcomponent/down_arrow_gray_10_10.png +0 -0
- package/dist/lforms/webcomponent/favicon.ico +0 -0
- package/dist/lforms/webcomponent/index.html +9 -0
- package/dist/lforms/webcomponent/lhc-forms.js +2471 -0
- package/dist/lforms/webcomponent/magnifying_glass.png +0 -0
- package/dist/lforms/webcomponent/main.js +2464 -0
- package/dist/lforms/webcomponent/main.js.map +1 -0
- package/dist/lforms/webcomponent/polyfills.js +2 -0
- package/dist/lforms/webcomponent/polyfills.js.map +1 -0
- package/dist/lforms/webcomponent/runtime.js +2 -0
- package/dist/lforms/webcomponent/runtime.js.map +1 -0
- package/dist/lforms/webcomponent/scripts.js +3 -0
- package/dist/lforms/webcomponent/scripts.js.map +1 -0
- package/dist/lforms/webcomponent/styles.css +3 -0
- package/dist/lforms/webcomponent/styles.css.map +1 -0
- package/form_definition.md +382 -0
- package/lforms-33.2.0.tgz +0 -0
- package/package.json +94 -88
- package/r4-support.md +147 -0
- package/sdc-support.md +127 -0
- package/app/.npmignore +0 -3
- package/app/images/blank.gif +0 -0
- package/app/images/signal-stop.png +0 -0
- package/app/index.html +0 -10
- package/app/lforms.js +0 -56
- package/app/lforms.tpl.js +0 -964
- package/app/scripts/angular-packages.js +0 -11
- package/app/scripts/bootstrap-decorators.js +0 -31
- package/app/scripts/bower-index.js +0 -14
- package/app/scripts/fhir/R4/export.js +0 -33
- package/app/scripts/fhir/R4/fhirRequire.js +0 -36
- package/app/scripts/fhir/R4/lformsFHIR.js +0 -27260
- package/app/scripts/fhir/R4/sdc-export.js +0 -455
- package/app/scripts/fhir/R4/sdc-import.js +0 -483
- package/app/scripts/fhir/STU3/export.js +0 -27
- package/app/scripts/fhir/STU3/fhirRequire.js +0 -36
- package/app/scripts/fhir/STU3/lformsFHIR.js +0 -27291
- package/app/scripts/fhir/STU3/sdc-export.js +0 -493
- package/app/scripts/fhir/STU3/sdc-import.js +0 -494
- package/app/scripts/fhir/diagnostic-report.js +0 -707
- package/app/scripts/fhir/export-common.js +0 -209
- package/app/scripts/fhir/expression-processor.js +0 -670
- package/app/scripts/fhir/extensions/rendering-style.js +0 -23
- package/app/scripts/fhir/fhir-common.js +0 -3
- package/app/scripts/fhir/obs-prepop.mjs +0 -97
- package/app/scripts/fhir/runtime-common.js +0 -33
- package/app/scripts/fhir/sdc-common.js +0 -334
- package/app/scripts/fhir/sdc-export-common.js +0 -1046
- package/app/scripts/fhir/sdc-import-common.js +0 -1343
- package/app/scripts/fhir/versions.js +0 -8
- package/app/scripts/index.js +0 -20
- package/app/scripts/lforms-config.js +0 -12
- package/app/scripts/lforms-constants.js +0 -10
- package/app/scripts/lforms-controllers.js +0 -1196
- package/app/scripts/lforms-directives.js +0 -424
- package/app/scripts/lforms-index.js +0 -20
- package/app/scripts/lib/cross_browser.js +0 -21
- package/app/scripts/lib/lforms-data.js +0 -3591
- package/app/scripts/lib/lforms-hl7.js +0 -525
- package/app/scripts/lib/lforms-util.js +0 -1122
- package/app/scripts/lib/lforms-validate.js +0 -277
- package/app/scripts/lib/polyfill.js +0 -81
- package/app/scripts/themeList.js +0 -17
- package/app/styles/lforms.css +0 -1219
- package/app/styles/redmond-theme/README.txt +0 -2
- package/app/styles/redmond-theme/images/ui-bg_glass_75_d0e5f5_1x400.png +0 -0
- package/app/styles/redmond-theme/images/ui-bg_glass_85_dfeffc_1x400.png +0 -0
- package/app/styles/redmond-theme/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
- package/app/styles/redmond-theme/images/ui-bg_gloss-wave_55_5c9ccc_500x100.png +0 -0
- package/app/styles/redmond-theme/images/ui-bg_inset-hard_100_f5f8f9_1x100.png +0 -0
- package/app/styles/redmond-theme/images/ui-bg_inset-hard_100_fcfdfd_1x100.png +0 -0
- package/app/styles/redmond-theme/images/ui-icons_217bc0_256x240.png +0 -0
- package/app/styles/redmond-theme/images/ui-icons_2e83ff_256x240.png +0 -0
- package/app/styles/redmond-theme/images/ui-icons_469bdd_256x240.png +0 -0
- package/app/styles/redmond-theme/images/ui-icons_6da8d5_256x240.png +0 -0
- package/app/styles/redmond-theme/images/ui-icons_cd0a0a_256x240.png +0 -0
- package/app/styles/redmond-theme/images/ui-icons_d8e7f3_256x240.png +0 -0
- package/app/styles/redmond-theme/images/ui-icons_f9bd01_256x240.png +0 -0
- package/app/styles/redmond-theme/jquery-ui.css +0 -1311
- package/app/styles/redmond-theme/jquery-ui.min.css +0 -7
- package/app/styles/redmond-theme/theme.css +0 -443
- package/app/styles/themes.css +0 -1541
- package/app/styles/themes.css.map +0 -9
- package/app/styles/themes.scss +0 -411
- package/app/version.json +0 -1
- package/app/views/partials/attachment.html +0 -38
- package/app/views/partials/field-answers.html +0 -67
- package/app/views/partials/field-units.html +0 -24
- package/app/views/partials/form-controls.html +0 -19
- package/app/views/partials/form-header.html +0 -35
- package/app/views/partials/form-options.html +0 -50
- package/app/views/partials/form-title.html +0 -20
- package/app/views/partials/form-view.html +0 -13
- package/app/views/partials/item-options.html +0 -48
- package/app/views/partials/item.html +0 -126
- package/app/views/partials/itemPrefixAndText.html +0 -4
- package/app/views/partials/layout-horizontal.html +0 -156
- package/app/views/partials/layout-matrix.html +0 -145
- package/app/views/partials/popover-content.html +0 -1
- package/app/views/partials/repeating-button.html +0 -16
- package/app/views/partials/table-item.html +0 -30
- package/app/views/partials/template-table.html +0 -69
- package/app/views/partials/uib-popover-templates/uib-popover-template.html +0 -13
- package/app/views/partials/uib-popover-templates/uib-popover.html +0 -11
|
@@ -1,455 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A package to handle FHIR Questionnaire and SDC (STU2) Questionnaire and QuestionnaireResponse for LForms
|
|
3
|
-
*
|
|
4
|
-
* FHIR Questionnaire:
|
|
5
|
-
* https://www.hl7.org/fhir/questionnaire.html
|
|
6
|
-
*
|
|
7
|
-
* R4 Ballot (3.5) for comment:
|
|
8
|
-
* http://hl7.org/fhir/uv/sdc/2018Sep/sdc-questionnaire.html
|
|
9
|
-
* http://hl7.org/fhir/uv/sdc/2018Sep/sdc-questionnaireresponse.html
|
|
10
|
-
*
|
|
11
|
-
* It provides the following functions:
|
|
12
|
-
* convertLFormsToQuestionnaire()
|
|
13
|
-
* -- Convert existing LOINC panels/forms data in LForms format into FHIR (standard or SDC) Questionnaire data
|
|
14
|
-
* convertLFormsToQuestionnaireResponse()
|
|
15
|
-
* -- Generate FHIR (standard or SDC) QuestionnaireResponse data from captured data in LForms
|
|
16
|
-
*/
|
|
17
|
-
var sdcVersion = '2.7';
|
|
18
|
-
var fhirVersionNum = '4.0';
|
|
19
|
-
|
|
20
|
-
var self = {
|
|
21
|
-
|
|
22
|
-
SDCVersion: sdcVersion,
|
|
23
|
-
QProfile: 'http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire|'+sdcVersion,
|
|
24
|
-
QRProfile: 'http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaireresponse|'+sdcVersion,
|
|
25
|
-
stdQProfile: 'http://hl7.org/fhir/'+fhirVersionNum+'/StructureDefinition/Questionnaire',
|
|
26
|
-
stdQRProfile: 'http://hl7.org/fhir/'+fhirVersionNum+'/StructureDefinition/QuestionnaireResponse',
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Convert LForms captured data to a bundle consisting of a FHIR SDC
|
|
30
|
-
* QuestionnaireResponse and any extractable resources. (Currently this means
|
|
31
|
-
* any Observations that can be extracted via the observationLinkPeriod
|
|
32
|
-
* extension).
|
|
33
|
-
*
|
|
34
|
-
* @param lfData a LForms form object
|
|
35
|
-
* @param noExtensions a flag that a standard FHIR Questionnaire is to be created without any extensions.
|
|
36
|
-
* The default is false.
|
|
37
|
-
* @param subject A local FHIR resource that is the subject of the output resource.
|
|
38
|
-
* If provided, a reference to this resource will be added to the output FHIR
|
|
39
|
-
* resource when applicable.
|
|
40
|
-
* @returns an array of QuestionnaireResponse and Observations. Observations
|
|
41
|
-
* will have derivedFrom set to a temporary reference created for the returned
|
|
42
|
-
* QuestionnaireResponse (the first element of the array). The caller may
|
|
43
|
-
* wish to put all of the returned resources into a transaction Bundle for
|
|
44
|
-
* creating them on a FHIR server.
|
|
45
|
-
*/
|
|
46
|
-
convertLFormsToFHIRData: function(lfData, noExtensions, subject) {
|
|
47
|
-
var qr = this.convertLFormsToQuestionnaireResponse(lfData, noExtensions, subject);
|
|
48
|
-
if (!qr.id) {
|
|
49
|
-
qr.id = this._commonExport._getUniqueId(
|
|
50
|
-
qr.identifier && qr.identifier.value || 'QR')
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
var qrRef = 'QuestionnaireResponse/'+qr.id;
|
|
54
|
-
var rtn = [qr];
|
|
55
|
-
for (var i=0, len=lfData.itemList.length; i<len; ++i) {
|
|
56
|
-
var item = lfData.itemList[i];
|
|
57
|
-
if (self._getExtractValue(item) && item.value) {
|
|
58
|
-
var obs = this._commonExport._createObservation(item);
|
|
59
|
-
for (var j=0, jLen=obs.length; j<jLen; j++) {
|
|
60
|
-
// Following
|
|
61
|
-
// http://hl7.org/fhir/uv/sdc/2019May/extraction.html#observation-based-extraction
|
|
62
|
-
if (qr.basedOn)
|
|
63
|
-
obs[j].basedOn = qr.basedOn;
|
|
64
|
-
if (qr.partOf)
|
|
65
|
-
obs[j].partOf = qr.partOf;
|
|
66
|
-
if (qr.subject)
|
|
67
|
-
obs[j].subject = qr.subject;
|
|
68
|
-
if (qr.encounter)
|
|
69
|
-
obs[j].encounter = qr.encounter;
|
|
70
|
-
if (qr.authored) {
|
|
71
|
-
obs[j].effectiveDateTime = qr.authored;
|
|
72
|
-
obs[j].issued = qr.authored;
|
|
73
|
-
}
|
|
74
|
-
if (qr.author)
|
|
75
|
-
obs[j].performer = qr.author;
|
|
76
|
-
obs[j].derivedFrom = [{reference: qrRef}];
|
|
77
|
-
|
|
78
|
-
rtn.push(obs[j]);
|
|
79
|
-
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
return rtn;
|
|
84
|
-
},
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Proceses the LForms questionCardinality into FHIR.
|
|
89
|
-
* @param targetItem an item in Questionnaire
|
|
90
|
-
* @param item a LForms item
|
|
91
|
-
*/
|
|
92
|
-
_processQuestionCardinality: function(targetItem, item) {
|
|
93
|
-
if (item.questionCardinality) {
|
|
94
|
-
if (item.questionCardinality.max === "*") {
|
|
95
|
-
targetItem.repeats = true;
|
|
96
|
-
}
|
|
97
|
-
else if (parseInt(item.questionCardinality.max) > 1) {
|
|
98
|
-
targetItem.repeats = true;
|
|
99
|
-
targetItem.extension.push({
|
|
100
|
-
"url": "http://hl7.org/fhir/StructureDefinition/questionnaire-maxOccurs",
|
|
101
|
-
"valueInteger": parseInt(item.questionCardinality.max)
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
else {
|
|
106
|
-
// No default in R4
|
|
107
|
-
// targetItem.repeats = false;
|
|
108
|
-
}
|
|
109
|
-
},
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Handle special requirements for 'display' items
|
|
114
|
-
* @param targetItem an item in Questionnaire
|
|
115
|
-
* @param item a LForms item
|
|
116
|
-
* @private
|
|
117
|
-
*/
|
|
118
|
-
_handleSpecialConstraints: function(targetItem, item) {
|
|
119
|
-
//Display items cannot have a "code" asserted
|
|
120
|
-
//Required and repeat aren't permitted for display items
|
|
121
|
-
//Read-only can't be specified for "display" items
|
|
122
|
-
if (targetItem && item.dataType === "TITLE") {
|
|
123
|
-
delete targetItem.code;
|
|
124
|
-
delete targetItem.required;
|
|
125
|
-
delete targetItem.repeats;
|
|
126
|
-
delete targetItem.readOnly;
|
|
127
|
-
}
|
|
128
|
-
},
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* Process various restriction settings
|
|
133
|
-
* @param targetItem an item in FHIR SDC Questionnaire object
|
|
134
|
-
* @param item an item in LForms form object
|
|
135
|
-
* @private
|
|
136
|
-
*/
|
|
137
|
-
_handleRestrictions: function(targetItem, item) {
|
|
138
|
-
// http://hl7.org/fhir/StructureDefinition/minLength
|
|
139
|
-
// http://hl7.org/fhir/StructureDefinition/regex
|
|
140
|
-
// http://hl7.org/fhir/StructureDefinition/minValue
|
|
141
|
-
// http://hl7.org/fhir/StructureDefinition/maxValue
|
|
142
|
-
// http://hl7.org/fhir/StructureDefinition/maxDecimalPlaces, not supported yet
|
|
143
|
-
// http://hl7.org/fhir/StructureDefinition/maxSize, for attachment, not supported yet
|
|
144
|
-
// maxLength
|
|
145
|
-
if (item.restrictions) {
|
|
146
|
-
for (var key in item.restrictions) {
|
|
147
|
-
var value = item.restrictions[key];
|
|
148
|
-
var extValue = null;
|
|
149
|
-
var dataType = this._getAssumedDataTypeForExport(item);
|
|
150
|
-
var valueKey = this._getValueKeyByDataType("value", item);
|
|
151
|
-
|
|
152
|
-
switch (key) {
|
|
153
|
-
// http://hl7.org/fhir/StructureDefinition/minValue
|
|
154
|
-
// { // Must be >= this value
|
|
155
|
-
// // from Element: extension
|
|
156
|
-
// "url" : "http://hl7.org/fhir/StructureDefinition/minValue", // R!
|
|
157
|
-
// // value[x]: Value of extension. One of these 6:
|
|
158
|
-
// "valueDate" : "<date>" // R! Value of extension
|
|
159
|
-
// "valueDateTime" : "<dateTime>", // R! Value of extension
|
|
160
|
-
// "valueTime" : "<time>", // R! Value of extension
|
|
161
|
-
// "valueInstant" : "<instant>", // R! Value of extension
|
|
162
|
-
// "valueDecimal" : <decimal>, // R! Value of extension
|
|
163
|
-
// "valueInteger" : <integer>, // R! Value of extension
|
|
164
|
-
// }
|
|
165
|
-
case "minExclusive":
|
|
166
|
-
case "minInclusive":
|
|
167
|
-
// http://hl7.org/fhir/StructureDefinition/maxValue
|
|
168
|
-
case "maxExclusive":
|
|
169
|
-
case "maxInclusive":
|
|
170
|
-
extValue = this._exportMinMax(dataType, value, valueKey, key);
|
|
171
|
-
break;
|
|
172
|
-
// http://hl7.org/fhir/StructureDefinition/minLength
|
|
173
|
-
case "minLength":
|
|
174
|
-
if (dataType === "ST" || dataType === "TX" || dataType === "URL" ||
|
|
175
|
-
dataType === "QTY") {
|
|
176
|
-
extValue = {
|
|
177
|
-
"url":"http://hl7.org/fhir/StructureDefinition/minLength",
|
|
178
|
-
"valueInteger": parseInt(value)
|
|
179
|
-
};
|
|
180
|
-
}
|
|
181
|
-
break;
|
|
182
|
-
// maxLength, not an extension, directly on item
|
|
183
|
-
case "maxLength":
|
|
184
|
-
if (dataType === "ST" || dataType === "TX" || dataType === "URL" ||
|
|
185
|
-
dataType === "QTY") {
|
|
186
|
-
targetItem.maxLength = parseInt(value);
|
|
187
|
-
}
|
|
188
|
-
break;
|
|
189
|
-
// http://hl7.org/fhir/StructureDefinition/regex
|
|
190
|
-
case "pattern":
|
|
191
|
-
if (dataType === "ST" || dataType === "TX" ) {
|
|
192
|
-
extValue = {
|
|
193
|
-
"url":"http://hl7.org/fhir/StructureDefinition/regex",
|
|
194
|
-
"valueString": value
|
|
195
|
-
};
|
|
196
|
-
}
|
|
197
|
-
break
|
|
198
|
-
}
|
|
199
|
-
if (extValue) {
|
|
200
|
-
targetItem.extension.push(extValue);
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
},
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
/**
|
|
208
|
-
* Processes settings for a list field with choices.
|
|
209
|
-
* @param targetItem an item in FHIR SDC Questionnaire object
|
|
210
|
-
* @param item an item in the LForms form object
|
|
211
|
-
* @param noExtensions a flag that a standard FHIR Questionnaire is to be created without any extensions.
|
|
212
|
-
* The default is false.
|
|
213
|
-
*/
|
|
214
|
-
_handleChoiceField: function(targetItem, item, noExtensions) {
|
|
215
|
-
// an extension for the search url of the auto-complete field.
|
|
216
|
-
if(item.externallyDefined) {
|
|
217
|
-
this._handleExternallyDefined(targetItem, item);
|
|
218
|
-
}
|
|
219
|
-
// option, for answer list
|
|
220
|
-
else if (item.answers && !item.answerValueSet) {
|
|
221
|
-
// Make sure the answers did not come from answerExpression.
|
|
222
|
-
if (!item._fhirExt || !item._fhirExt[this.fhirExtAnswerExp])
|
|
223
|
-
targetItem.answerOption = this._handleAnswers(item, noExtensions);
|
|
224
|
-
}
|
|
225
|
-
else if (item.answerValueSet)
|
|
226
|
-
targetItem.answerValueSet = item.answerValueSet;
|
|
227
|
-
},
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
/**
|
|
231
|
-
* Process an item's answer list
|
|
232
|
-
* @param item an item in the LForms form object
|
|
233
|
-
* @param noExtensions a flag that a standard FHIR Questionnaire is to be created without any extensions.
|
|
234
|
-
* The default is false.
|
|
235
|
-
* @returns {Array}
|
|
236
|
-
* @private
|
|
237
|
-
*/
|
|
238
|
-
_handleAnswers: function(item, noExtensions) {
|
|
239
|
-
var optionArray = [];
|
|
240
|
-
for (var i=0, iLen=item.answers.length; i<iLen; i++) {
|
|
241
|
-
var answer = item.answers[i];
|
|
242
|
-
var option = {};
|
|
243
|
-
|
|
244
|
-
// needs an extension for label
|
|
245
|
-
if (!noExtensions) {
|
|
246
|
-
var ext = [];
|
|
247
|
-
if(answer.label) {
|
|
248
|
-
ext.push({
|
|
249
|
-
"url" : "http://hl7.org/fhir/StructureDefinition/questionnaire-optionPrefix",
|
|
250
|
-
"valueString" : answer.label
|
|
251
|
-
});
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
if (answer.score !== null && answer.score !== undefined) {
|
|
255
|
-
ext.push({
|
|
256
|
-
"url" : "http://hl7.org/fhir/StructureDefinition/ordinalValue",
|
|
257
|
-
"valueDecimal" : parseFloat(answer.score)
|
|
258
|
-
});
|
|
259
|
-
}
|
|
260
|
-
if(ext.length > 0) {
|
|
261
|
-
option.extension = ext;
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
// option's value supports integer, date, time, string and Coding
|
|
265
|
-
// for LForms, all answers are Coding
|
|
266
|
-
option.valueCoding = {};
|
|
267
|
-
if (answer.code) option.valueCoding.code = answer.code;
|
|
268
|
-
if (answer.text) option.valueCoding.display = answer.text;
|
|
269
|
-
|
|
270
|
-
if (answer.system) {
|
|
271
|
-
option.valueCoding.system = LForms.Util.getCodeSystem(answer.system);
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
optionArray.push(option);
|
|
275
|
-
}
|
|
276
|
-
return optionArray;
|
|
277
|
-
},
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
/**
|
|
281
|
-
* Process default values
|
|
282
|
-
* @param targetItem an item in FHIR SDC Questionnaire object
|
|
283
|
-
* @param item an item in LForms form object
|
|
284
|
-
* @private
|
|
285
|
-
*/
|
|
286
|
-
_handleInitialValues: function(targetItem, item) {
|
|
287
|
-
if(item.defaultAnswer === null || item.defaultAnswer === undefined || item.defaultAnswer === '') {
|
|
288
|
-
return;
|
|
289
|
-
}
|
|
290
|
-
// item.defaultAnswer could be an array of multiple default values or a single value
|
|
291
|
-
var defaultAnswers = (this._answerRepeats(item) && Array.isArray(item.defaultAnswer)) ?
|
|
292
|
-
item.defaultAnswer : [item.defaultAnswer];
|
|
293
|
-
|
|
294
|
-
var dataType = this._getAssumedDataTypeForExport(item);
|
|
295
|
-
var valueKey = this._getValueKeyByDataType("value", item);
|
|
296
|
-
var answer = null;
|
|
297
|
-
targetItem.initial = [];
|
|
298
|
-
|
|
299
|
-
// go through each default value and handle it based on the data type.
|
|
300
|
-
for(var i=0, iLen=defaultAnswers.length; i<iLen; i++ ) {
|
|
301
|
-
// dataType:
|
|
302
|
-
// boolean, decimal, integer, date, dateTime, instant, time, string, uri,
|
|
303
|
-
// Attachment, Coding, Quantity, Reference(Resource)
|
|
304
|
-
|
|
305
|
-
// for Coding
|
|
306
|
-
if (dataType === 'CWE' || dataType === 'CNE' ) {
|
|
307
|
-
// could be a code object or a string
|
|
308
|
-
if (typeof defaultAnswers[i] === 'object') {
|
|
309
|
-
var coding = {"code": defaultAnswers[i].code};
|
|
310
|
-
if(defaultAnswers[i].text !== undefined) {
|
|
311
|
-
coding.display = defaultAnswers[i].text;
|
|
312
|
-
}
|
|
313
|
-
// code system
|
|
314
|
-
var codeSystem = defaultAnswers[i].system || item.answerCodeSystem;
|
|
315
|
-
if (codeSystem) {
|
|
316
|
-
coding.system = LForms.Util.getCodeSystem(codeSystem);
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
answer = {};
|
|
320
|
-
answer[valueKey] = coding;
|
|
321
|
-
targetItem.initial.push(answer);
|
|
322
|
-
}
|
|
323
|
-
// user typed answer that is not on the answer list.
|
|
324
|
-
else if (typeof defaultAnswers[i] === 'string') {
|
|
325
|
-
targetItem.initial.push({
|
|
326
|
-
"valueString": defaultAnswers[i]
|
|
327
|
-
})
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
// for Quantity,
|
|
331
|
-
// [{
|
|
332
|
-
// // from Element: extension
|
|
333
|
-
// "value" : <decimal>, // Numerical value (with implicit precision)
|
|
334
|
-
// "comparator" : "<code>", // < | <= | >= | > - how to understand the value
|
|
335
|
-
// "unit" : "<string>", // Unit representation
|
|
336
|
-
// "system" : "<uri>", // Code System that defines coded unit form
|
|
337
|
-
// "code" : "<code>" // Coded form of the unit
|
|
338
|
-
// }]
|
|
339
|
-
else if (dataType === 'QTY') { // for now, handling only simple quantities without the comparators.
|
|
340
|
-
answer = {};
|
|
341
|
-
answer[valueKey] = this._makeQuantity(defaultAnswers[i], item.units);
|
|
342
|
-
targetItem.initial.push(answer);
|
|
343
|
-
}
|
|
344
|
-
// for boolean, decimal, integer, date, dateTime, instant, time, string, uri
|
|
345
|
-
else if (dataType === "INT" || dataType === "REAL" || dataType === "BL" ||
|
|
346
|
-
dataType === "TM" || dataType === "ST" || dataType === "TX" || dataType === "URL") {
|
|
347
|
-
answer = {};
|
|
348
|
-
answer[valueKey] = defaultAnswers[i];
|
|
349
|
-
targetItem.initial.push(answer);
|
|
350
|
-
}
|
|
351
|
-
else if (dataType === "DT" || dataType === "DTM") { // transform to FHIR date/datetime format.
|
|
352
|
-
var dateValue = LForms.Util.stringToDate(defaultAnswers[i]);
|
|
353
|
-
if(dateValue) {
|
|
354
|
-
dateValue = dataType === "DTM"?
|
|
355
|
-
LForms.Util.dateToDTMString(dateValue): LForms.Util.dateToDTStringISO(dateValue);
|
|
356
|
-
targetItem.initial.push({[valueKey]: dateValue});
|
|
357
|
-
}
|
|
358
|
-
else { // LForms.Util.stringToDate returns null on invalid string
|
|
359
|
-
// TODO: should save the errors or emitting events.
|
|
360
|
-
console.error(defaultAnswers[i] + ': Invalid date/datetime string as defaultAnswer for ' + item.questionCode);
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
// no support for reference
|
|
364
|
-
}
|
|
365
|
-
},
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
/**
|
|
369
|
-
* Process units list
|
|
370
|
-
* @param targetItem an item in FHIR SDC Questionnaire object
|
|
371
|
-
* @param item an item in LForms form object
|
|
372
|
-
* @private
|
|
373
|
-
*/
|
|
374
|
-
_handleLFormsUnits: function(targetItem, item) {
|
|
375
|
-
|
|
376
|
-
if (item.units && item.units.length > 0) {
|
|
377
|
-
var dataType = this._getAssumedDataTypeForExport(item);
|
|
378
|
-
if(dataType === "REAL" || dataType === "INT") {
|
|
379
|
-
|
|
380
|
-
targetItem.extension.push({
|
|
381
|
-
"url": this.fhirExtUrlUnit,
|
|
382
|
-
// Datatype with multiple units is quantity. There is only one unit here.
|
|
383
|
-
"valueCoding" : this._createFhirUnitCoding(item.units[0])
|
|
384
|
-
});
|
|
385
|
-
}
|
|
386
|
-
else if(dataType === 'QTY') {
|
|
387
|
-
var defUnit = this._getDefaultUnit(item.units);
|
|
388
|
-
// Skip if units are already set in default answer conversion.
|
|
389
|
-
if ((defUnit && defUnit.default) && !(targetItem.initial && targetItem.initial.length > 0)) {
|
|
390
|
-
// Use initial[].valueQuantity.unit to export the default unit.
|
|
391
|
-
if (!targetItem.initial) {
|
|
392
|
-
targetItem.initial = [];
|
|
393
|
-
}
|
|
394
|
-
var qty = {};
|
|
395
|
-
self._setUnitAttributesToFhirQuantity(qty, defUnit);
|
|
396
|
-
targetItem.initial.push({valueQuantity: qty});
|
|
397
|
-
}
|
|
398
|
-
for (var i=0, iLen=item.units.length; i<iLen; i++) {
|
|
399
|
-
var unit = item.units[i];
|
|
400
|
-
var fhirUnitExt = {
|
|
401
|
-
"url": this.fhirExtUrlUnitOption,
|
|
402
|
-
"valueCoding": self._createFhirUnitCoding(unit)
|
|
403
|
-
};
|
|
404
|
-
targetItem.extension.push(fhirUnitExt);
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
},
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
/**
|
|
412
|
-
* Process skip logic
|
|
413
|
-
* @param targetItem an item in FHIR SDC Questionnaire object
|
|
414
|
-
* @param item an item in LForms form object
|
|
415
|
-
* @param source a LForms form object
|
|
416
|
-
* @private
|
|
417
|
-
*/
|
|
418
|
-
_handleSkipLogic: function(targetItem, item, source) {
|
|
419
|
-
if (item.skipLogic) {
|
|
420
|
-
var enableWhen = [];
|
|
421
|
-
var rangeFound = false;
|
|
422
|
-
|
|
423
|
-
// ignore "ANY", "ALL" on item.skipLogic.logic
|
|
424
|
-
// ignore "show" on item.skipLogic.action
|
|
425
|
-
|
|
426
|
-
for (var i=0, iLen=item.skipLogic.conditions.length; i<iLen; i++) {
|
|
427
|
-
var condition = item.skipLogic.conditions[i];
|
|
428
|
-
var sourceItem = source._getSkipLogicSourceItem(item,condition.source);
|
|
429
|
-
let enableWhenRules = self._createEnableWhenRulesForSkipLogicCondition(condition, sourceItem);
|
|
430
|
-
|
|
431
|
-
if(enableWhenRules.length > 1) {
|
|
432
|
-
rangeFound = true;
|
|
433
|
-
}
|
|
434
|
-
enableWhen = enableWhen.concat(enableWhenRules);
|
|
435
|
-
}
|
|
436
|
-
|
|
437
|
-
if(rangeFound && item.skipLogic.conditions.length > 1) {
|
|
438
|
-
// TODO: Multiple skip logic conditons included with range specification is not supported with core FHIR.
|
|
439
|
-
// Use SDC extensions with fhirpath expressions, but not all fhirpath functionality is
|
|
440
|
-
// available yet. Revisit after implementation of variables, %resource etc. in fhirpath.
|
|
441
|
-
throw new Error('Multiple skip logic conditons included with range specification is not supported yet.');
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
targetItem.enableWhen = enableWhen;
|
|
445
|
-
if(item.skipLogic.logic === 'ALL' || rangeFound) {
|
|
446
|
-
targetItem.enableBehavior = 'all';
|
|
447
|
-
}
|
|
448
|
-
else if(enableWhen.length > 1) {
|
|
449
|
-
targetItem.enableBehavior = 'any';
|
|
450
|
-
}
|
|
451
|
-
}
|
|
452
|
-
}
|
|
453
|
-
};
|
|
454
|
-
|
|
455
|
-
export default self;
|