@openmrs/esm-form-entry-app 13.0.2-pre.12995 → 13.0.2-pre.13005
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/.turbo/turbo-build.log +6 -6
- package/dist/3751.b68b13d625ff15f1.js +103 -0
- package/dist/3751.b68b13d625ff15f1.js.map +1 -0
- package/dist/8480.9ddc7c1755c947db.js +1 -0
- package/dist/{8480.9e852fe5a0ef03b8.js.map → 8480.9ddc7c1755c947db.js.map} +1 -1
- package/dist/{main.e00c4b7729f89376.js → main.2c72fe0fe073c046.js} +1 -1
- package/dist/{main.e00c4b7729f89376.js.map → main.2c72fe0fe073c046.js.map} +1 -1
- package/dist/openmrs-esm-form-entry-app.js +1 -1
- package/dist/routes.json +1 -1
- package/package.json +1 -1
- package/src/app/fe-wrapper/fe-wrapper.component.spec.ts +119 -1
- package/src/app/fe-wrapper/fe-wrapper.component.ts +31 -14
- package/src/app/form-creation/concept-reference-range-form.service.spec.ts +526 -0
- package/src/app/form-creation/concept-reference-range-form.service.ts +247 -0
- package/src/app/form-creation/form-creation.service.spec.ts +0 -116
- package/src/app/form-creation/form-creation.service.ts +6 -15
- package/src/app/form-schema/concept-reference-ranges.spec.ts +2 -128
- package/src/app/form-schema/concept-reference-ranges.ts +4 -70
- package/src/app/openmrs-api/concept-reference-range-resource.service.spec.ts +15 -0
- package/src/app/openmrs-api/concept-reference-range-resource.service.ts +18 -2
- package/src/app/types/index.ts +3 -8
- package/dist/6375.4e86ada6bfec23a6.js +0 -103
- package/dist/6375.4e86ada6bfec23a6.js.map +0 -1
- package/dist/8480.9e852fe5a0ef03b8.js +0 -1
|
@@ -0,0 +1,526 @@
|
|
|
1
|
+
import { fakeAsync, TestBed, tick } from '@angular/core/testing';
|
|
2
|
+
import { provideHttpClient } from '@angular/common/http';
|
|
3
|
+
import { provideHttpClientTesting } from '@angular/common/http/testing';
|
|
4
|
+
import {
|
|
5
|
+
AfeFormControl,
|
|
6
|
+
ArrayNode,
|
|
7
|
+
Form,
|
|
8
|
+
FormEntryModule,
|
|
9
|
+
FormFactory,
|
|
10
|
+
GroupNode,
|
|
11
|
+
NodeBase,
|
|
12
|
+
} from '@openmrs/ngx-formentry';
|
|
13
|
+
import { TranslateModule } from '@ngx-translate/core';
|
|
14
|
+
import moment from 'moment';
|
|
15
|
+
import { of, Subject, Subscription } from 'rxjs';
|
|
16
|
+
import { ConceptReferenceRangeFormService } from './concept-reference-range-form.service';
|
|
17
|
+
import { ConceptReferenceRangeResourceService } from '../openmrs-api/concept-reference-range-resource.service';
|
|
18
|
+
import { ConceptReferenceRange } from '../types';
|
|
19
|
+
|
|
20
|
+
describe('Reference ranges at the measurement date', () => {
|
|
21
|
+
let factory: FormFactory;
|
|
22
|
+
let service: ConceptReferenceRangeFormService;
|
|
23
|
+
let resource: jasmine.SpyObj<ConceptReferenceRangeResourceService>;
|
|
24
|
+
let subscription: Subscription;
|
|
25
|
+
const early = new Map<string, ConceptReferenceRange>([
|
|
26
|
+
[
|
|
27
|
+
'temperature-uuid',
|
|
28
|
+
{
|
|
29
|
+
uuid: 'early-range',
|
|
30
|
+
concept: 'temperature-uuid',
|
|
31
|
+
hiNormal: 35,
|
|
32
|
+
hiAbsolute: 40,
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
]);
|
|
36
|
+
const later = new Map<string, ConceptReferenceRange>([
|
|
37
|
+
[
|
|
38
|
+
'temperature-uuid',
|
|
39
|
+
{
|
|
40
|
+
uuid: 'later-range',
|
|
41
|
+
concept: 'temperature-uuid',
|
|
42
|
+
hiNormal: 40,
|
|
43
|
+
hiAbsolute: 50,
|
|
44
|
+
},
|
|
45
|
+
],
|
|
46
|
+
]);
|
|
47
|
+
|
|
48
|
+
function numericQuestion(id = 'temperature') {
|
|
49
|
+
return {
|
|
50
|
+
id,
|
|
51
|
+
label: 'Temperature',
|
|
52
|
+
type: 'obs',
|
|
53
|
+
alert: { useConceptReferenceRange: true },
|
|
54
|
+
questionOptions: { rendering: 'number', concept: 'temperature-uuid', min: '10' },
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function createForm(questions: unknown[] = [numericQuestion()], includeEncounterDate = true): Form {
|
|
59
|
+
const form = factory.createForm({
|
|
60
|
+
name: 'Vitals',
|
|
61
|
+
pages: [
|
|
62
|
+
{
|
|
63
|
+
label: 'Vitals',
|
|
64
|
+
sections: [
|
|
65
|
+
{
|
|
66
|
+
label: 'Vitals',
|
|
67
|
+
isExpanded: 'true',
|
|
68
|
+
questions: [
|
|
69
|
+
...(includeEncounterDate
|
|
70
|
+
? [{ id: 'encDate', type: 'encounterDatetime', questionOptions: { rendering: 'date' } }]
|
|
71
|
+
: []),
|
|
72
|
+
...questions,
|
|
73
|
+
],
|
|
74
|
+
},
|
|
75
|
+
],
|
|
76
|
+
},
|
|
77
|
+
],
|
|
78
|
+
});
|
|
79
|
+
if (includeEncounterDate) {
|
|
80
|
+
form.searchNodeByQuestionId('encDate')[0].control.setValue('2020-01-01T00:00:00Z');
|
|
81
|
+
}
|
|
82
|
+
return form;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function controlFor(form: Form, id = 'temperature', index = 0): AfeFormControl {
|
|
86
|
+
return controlOf(form.searchNodeByQuestionId(id)[index]);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function controlOf(node: NodeBase): AfeFormControl {
|
|
90
|
+
if (!(node.control instanceof AfeFormControl)) {
|
|
91
|
+
throw new Error('Expected a numeric control');
|
|
92
|
+
}
|
|
93
|
+
return node.control;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function vitalsGroup(rendering = 'group') {
|
|
97
|
+
return {
|
|
98
|
+
id: 'vitals',
|
|
99
|
+
label: 'Vitals',
|
|
100
|
+
type: 'obsGroup',
|
|
101
|
+
questionOptions: { rendering, concept: 'vitals-uuid' },
|
|
102
|
+
questions: [
|
|
103
|
+
numericQuestion(),
|
|
104
|
+
{ id: 'note', label: 'Note', type: 'obs', questionOptions: { rendering: 'text', concept: 'note-uuid' } },
|
|
105
|
+
],
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Loads an obs group saved at the encounter date into a group node, the way the obs adapter does.
|
|
111
|
+
*/
|
|
112
|
+
function loadSavedGroup(group: GroupNode, uuid: string, temperature: number) {
|
|
113
|
+
const obsDatetime = '2020-01-01T00:00:00.000+0000';
|
|
114
|
+
const temperatureObs = {
|
|
115
|
+
uuid: `${uuid}-temperature`,
|
|
116
|
+
concept: 'temperature-uuid',
|
|
117
|
+
obsDatetime,
|
|
118
|
+
value: temperature,
|
|
119
|
+
};
|
|
120
|
+
const noteObs = { uuid: `${uuid}-note`, concept: 'note-uuid', obsDatetime, value: 'Fine' };
|
|
121
|
+
group.initialValue = { uuid, concept: 'vitals-uuid', obsDatetime, groupMembers: [temperatureObs, noteObs] };
|
|
122
|
+
group.children['temperature'].initialValue = temperatureObs;
|
|
123
|
+
group.children['temperature'].control.setValue(temperature);
|
|
124
|
+
group.children['note'].initialValue = noteObs;
|
|
125
|
+
group.children['note'].control.setValue(noteObs.value);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Creates a form for an encounter saved on 2020-01-01 with a temperature of 37 recorded at the
|
|
130
|
+
* encounter date, loaded the way the obs adapter loads saved answers.
|
|
131
|
+
*/
|
|
132
|
+
function savedEncounterForm(showDate = false): Form {
|
|
133
|
+
const measurement = numericQuestion();
|
|
134
|
+
const form = createForm([
|
|
135
|
+
showDate ? { ...measurement, questionOptions: { ...measurement.questionOptions, showDate: true } } : measurement,
|
|
136
|
+
]);
|
|
137
|
+
const observation = { uuid: 'saved-obs', obsDatetime: '2020-01-01T00:00:00.000+0000', value: 37 };
|
|
138
|
+
form.valueProcessingInfo.encounterUuid = 'saved-encounter';
|
|
139
|
+
form.searchNodeByQuestionId('encDate')[0].initialValue = new Date('2020-01-01T00:00:00Z');
|
|
140
|
+
form.searchNodeByQuestionId('temperature')[0].initialValue = observation;
|
|
141
|
+
controlFor(form).setValue(observation.value);
|
|
142
|
+
if (showDate) {
|
|
143
|
+
form.searchNodeByQuestionId('complex_temperature')[0].initialValue = observation;
|
|
144
|
+
const date = form.searchNodeByQuestionId('date_temperature')[0];
|
|
145
|
+
date.initialValue = observation;
|
|
146
|
+
date.control.setValue(observation.obsDatetime);
|
|
147
|
+
}
|
|
148
|
+
return form;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function lastContext() {
|
|
152
|
+
return resource.getConceptReferenceRanges.calls.mostRecent().args[2];
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
beforeEach(() => {
|
|
156
|
+
resource = jasmine.createSpyObj<ConceptReferenceRangeResourceService>('ranges', ['getConceptReferenceRanges']);
|
|
157
|
+
resource.getConceptReferenceRanges.and.returnValue(of(early));
|
|
158
|
+
TestBed.configureTestingModule({
|
|
159
|
+
imports: [FormEntryModule, TranslateModule.forRoot()],
|
|
160
|
+
providers: [
|
|
161
|
+
provideHttpClient(),
|
|
162
|
+
provideHttpClientTesting(),
|
|
163
|
+
{ provide: ConceptReferenceRangeResourceService, useValue: resource },
|
|
164
|
+
],
|
|
165
|
+
});
|
|
166
|
+
factory = TestBed.inject(FormFactory);
|
|
167
|
+
service = TestBed.inject(ConceptReferenceRangeFormService);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
afterEach(() => subscription?.unsubscribe());
|
|
171
|
+
|
|
172
|
+
it('batches questions at the encounter date and refreshes when that date changes', fakeAsync(() => {
|
|
173
|
+
const form = createForm([numericQuestion(), numericQuestion('anotherTemperature')]);
|
|
174
|
+
const control = controlFor(form);
|
|
175
|
+
control.setValue(45);
|
|
176
|
+
subscription = service.connect(form, 'patient-uuid');
|
|
177
|
+
expect(service.isLoading(form)).toBe(true);
|
|
178
|
+
tick();
|
|
179
|
+
expect(resource.getConceptReferenceRanges).toHaveBeenCalledOnceWith('patient-uuid', ['temperature-uuid'], {
|
|
180
|
+
date: moment('2020-01-01T00:00:00Z').format(),
|
|
181
|
+
});
|
|
182
|
+
expect(control.valid).toBe(false);
|
|
183
|
+
expect(control.alerts[0].shown).toBe(true);
|
|
184
|
+
|
|
185
|
+
resource.getConceptReferenceRanges.and.returnValue(of(later));
|
|
186
|
+
form.searchNodeByQuestionId('encDate')[0].control.setValue('2021-01-01T00:00:00Z');
|
|
187
|
+
expect(service.isLoading(form)).toBe(true);
|
|
188
|
+
tick();
|
|
189
|
+
expect(resource.getConceptReferenceRanges.calls.mostRecent().args[2]).toEqual({
|
|
190
|
+
date: moment('2021-01-01T00:00:00Z').format(),
|
|
191
|
+
});
|
|
192
|
+
expect(control.valid).toBe(true);
|
|
193
|
+
control.setValue(5);
|
|
194
|
+
expect(control.valid).toBe(false);
|
|
195
|
+
expect(service.isLoading(form)).toBe(false);
|
|
196
|
+
}));
|
|
197
|
+
|
|
198
|
+
it('applies the range of a question that names its concept by reference', fakeAsync(() => {
|
|
199
|
+
const measurement = numericQuestion();
|
|
200
|
+
const form = createForm([
|
|
201
|
+
{ ...measurement, questionOptions: { ...measurement.questionOptions, concept: 'CIEL:5088' } },
|
|
202
|
+
]);
|
|
203
|
+
form.schema.conceptReferences = { 'CIEL:5088': { uuid: 'temperature-uuid', display: 'Temperature' } };
|
|
204
|
+
const control = controlFor(form);
|
|
205
|
+
control.setValue(45);
|
|
206
|
+
subscription = service.connect(form, 'patient-uuid');
|
|
207
|
+
tick();
|
|
208
|
+
expect(resource.getConceptReferenceRanges).toHaveBeenCalledOnceWith('patient-uuid', ['temperature-uuid'], {
|
|
209
|
+
date: moment('2020-01-01T00:00:00Z').format(),
|
|
210
|
+
});
|
|
211
|
+
expect(control.valid).toBe(false);
|
|
212
|
+
}));
|
|
213
|
+
|
|
214
|
+
it('applies the range of a question that uses the numeric rendering', fakeAsync(() => {
|
|
215
|
+
const measurement = numericQuestion();
|
|
216
|
+
const form = createForm([
|
|
217
|
+
{ ...measurement, questionOptions: { ...measurement.questionOptions, rendering: 'numeric' } },
|
|
218
|
+
]);
|
|
219
|
+
const control = controlFor(form);
|
|
220
|
+
control.setValue(45);
|
|
221
|
+
subscription = service.connect(form, 'patient-uuid');
|
|
222
|
+
tick();
|
|
223
|
+
expect(control.conceptReferenceRange).toBe(early.get('temperature-uuid'));
|
|
224
|
+
expect(control.valid).toBe(false);
|
|
225
|
+
}));
|
|
226
|
+
|
|
227
|
+
it('uses the observation context for a saved answer dated away from its encounter', fakeAsync(() => {
|
|
228
|
+
const form = createForm();
|
|
229
|
+
form.valueProcessingInfo.encounterUuid = 'historical-encounter';
|
|
230
|
+
form.searchNodeByQuestionId('encDate')[0].initialValue = new Date('2020-01-01T00:00:00Z');
|
|
231
|
+
form.searchNodeByQuestionId('temperature')[0].initialValue = {
|
|
232
|
+
uuid: 'historical-obs',
|
|
233
|
+
obsDatetime: '2019-06-01T00:00:00Z',
|
|
234
|
+
value: 37,
|
|
235
|
+
};
|
|
236
|
+
subscription = service.connect(form, 'patient-uuid');
|
|
237
|
+
tick();
|
|
238
|
+
expect(resource.getConceptReferenceRanges).toHaveBeenCalledWith('patient-uuid', ['temperature-uuid'], {
|
|
239
|
+
obs: 'historical-obs',
|
|
240
|
+
});
|
|
241
|
+
}));
|
|
242
|
+
|
|
243
|
+
it('uses a saved encounter context until the encounter date is edited', fakeAsync(() => {
|
|
244
|
+
const form = createForm();
|
|
245
|
+
form.valueProcessingInfo.encounterUuid = 'historical-encounter';
|
|
246
|
+
form.searchNodeByQuestionId('encDate')[0].initialValue = new Date('2020-01-01T00:00:00Z');
|
|
247
|
+
subscription = service.connect(form, 'patient-uuid');
|
|
248
|
+
tick();
|
|
249
|
+
expect(resource.getConceptReferenceRanges.calls.mostRecent().args[2]).toEqual({
|
|
250
|
+
encounter: 'historical-encounter',
|
|
251
|
+
});
|
|
252
|
+
form.searchNodeByQuestionId('encDate')[0].control.setValue('2021-01-01T00:00:00Z');
|
|
253
|
+
tick();
|
|
254
|
+
expect(resource.getConceptReferenceRanges.calls.mostRecent().args[2]).toEqual({
|
|
255
|
+
date: moment('2021-01-01T00:00:00Z').format(),
|
|
256
|
+
});
|
|
257
|
+
}));
|
|
258
|
+
|
|
259
|
+
it('batches unchanged saved answers under their encounter, even after the encounter date changes', fakeAsync(() => {
|
|
260
|
+
const form = createForm([numericQuestion(), numericQuestion('anotherTemperature')]);
|
|
261
|
+
form.valueProcessingInfo.encounterUuid = 'historical-encounter';
|
|
262
|
+
form.searchNodeByQuestionId('encDate')[0].initialValue = new Date('2020-01-01T00:00:00Z');
|
|
263
|
+
form.searchNodeByQuestionId('temperature')[0].initialValue = {
|
|
264
|
+
uuid: 'first-obs',
|
|
265
|
+
obsDatetime: '2020-01-01T00:00:00.000+0000',
|
|
266
|
+
value: 37,
|
|
267
|
+
};
|
|
268
|
+
form.searchNodeByQuestionId('anotherTemperature')[0].initialValue = {
|
|
269
|
+
uuid: 'second-obs',
|
|
270
|
+
obsDatetime: '2020-01-01T00:00:00.000+0000',
|
|
271
|
+
value: 38,
|
|
272
|
+
};
|
|
273
|
+
controlFor(form).setValue(37);
|
|
274
|
+
controlFor(form, 'anotherTemperature').setValue(38);
|
|
275
|
+
subscription = service.connect(form, 'patient-uuid');
|
|
276
|
+
tick();
|
|
277
|
+
expect(resource.getConceptReferenceRanges).toHaveBeenCalledOnceWith('patient-uuid', ['temperature-uuid'], {
|
|
278
|
+
encounter: 'historical-encounter',
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
form.searchNodeByQuestionId('encDate')[0].control.setValue('2021-01-01T00:00:00Z');
|
|
282
|
+
tick();
|
|
283
|
+
expect(resource.getConceptReferenceRanges).toHaveBeenCalledTimes(2);
|
|
284
|
+
expect(lastContext()).toEqual({ encounter: 'historical-encounter' });
|
|
285
|
+
}));
|
|
286
|
+
|
|
287
|
+
[
|
|
288
|
+
{ rendering: 'a plain answer', showDate: false },
|
|
289
|
+
{ rendering: 'an answer with its own date', showDate: true },
|
|
290
|
+
].forEach(({ rendering, showDate }) => {
|
|
291
|
+
it(`keeps ${rendering} at its saved date until an edit sends it with a moved encounter`, fakeAsync(() => {
|
|
292
|
+
const form = savedEncounterForm(showDate);
|
|
293
|
+
const control = controlFor(form);
|
|
294
|
+
subscription = service.connect(form, 'patient-uuid');
|
|
295
|
+
tick();
|
|
296
|
+
expect(lastContext()).toEqual({ encounter: 'saved-encounter' });
|
|
297
|
+
|
|
298
|
+
// Without an encounter date change, an edited answer is still saved at the encounter date.
|
|
299
|
+
control.setValue(38);
|
|
300
|
+
tick();
|
|
301
|
+
expect(resource.getConceptReferenceRanges).toHaveBeenCalledTimes(1);
|
|
302
|
+
control.setValue(37);
|
|
303
|
+
|
|
304
|
+
form.searchNodeByQuestionId('encDate')[0].control.setValue('2021-01-01T00:00:00Z');
|
|
305
|
+
tick();
|
|
306
|
+
expect(lastContext()).toEqual({ encounter: 'saved-encounter' });
|
|
307
|
+
|
|
308
|
+
control.setValue(38);
|
|
309
|
+
expect(service.isLoading(form)).toBe(true);
|
|
310
|
+
tick();
|
|
311
|
+
expect(lastContext()).toEqual({ date: moment('2021-01-01T00:00:00Z').format() });
|
|
312
|
+
|
|
313
|
+
control.setValue(37);
|
|
314
|
+
tick();
|
|
315
|
+
expect(lastContext()).toEqual({ encounter: 'saved-encounter' });
|
|
316
|
+
}));
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
it('moves an unchanged answer with its obs group when a sibling is edited', fakeAsync(() => {
|
|
320
|
+
const form = createForm([vitalsGroup()]);
|
|
321
|
+
form.valueProcessingInfo.encounterUuid = 'saved-encounter';
|
|
322
|
+
form.searchNodeByQuestionId('encDate')[0].initialValue = new Date('2020-01-01T00:00:00Z');
|
|
323
|
+
const group = form.searchNodeByQuestionId('vitals')[0];
|
|
324
|
+
if (!(group instanceof GroupNode)) {
|
|
325
|
+
throw new Error('Expected an obs group');
|
|
326
|
+
}
|
|
327
|
+
loadSavedGroup(group, 'saved-group', 37);
|
|
328
|
+
subscription = service.connect(form, 'patient-uuid');
|
|
329
|
+
tick();
|
|
330
|
+
form.searchNodeByQuestionId('encDate')[0].control.setValue('2021-01-01T00:00:00Z');
|
|
331
|
+
tick();
|
|
332
|
+
expect(lastContext()).toEqual({ encounter: 'saved-encounter' });
|
|
333
|
+
|
|
334
|
+
const note = form.searchNodeByQuestionId('note')[0].control;
|
|
335
|
+
note.setValue('Feverish');
|
|
336
|
+
expect(service.isLoading(form)).toBe(true);
|
|
337
|
+
tick();
|
|
338
|
+
expect(lastContext()).toEqual({ date: moment('2021-01-01T00:00:00Z').format() });
|
|
339
|
+
|
|
340
|
+
note.setValue('Fine');
|
|
341
|
+
tick();
|
|
342
|
+
expect(lastContext()).toEqual({ encounter: 'saved-encounter' });
|
|
343
|
+
}));
|
|
344
|
+
|
|
345
|
+
it('moves only the repeated group whose sibling is edited', fakeAsync(() => {
|
|
346
|
+
resource.getConceptReferenceRanges.and.callFake((_patient, _concepts, context) =>
|
|
347
|
+
of(context?.date ? later : early),
|
|
348
|
+
);
|
|
349
|
+
const form = createForm([vitalsGroup('repeating')]);
|
|
350
|
+
form.valueProcessingInfo.encounterUuid = 'saved-encounter';
|
|
351
|
+
form.searchNodeByQuestionId('encDate')[0].initialValue = new Date('2020-01-01T00:00:00Z');
|
|
352
|
+
const repeat = form.searchNodeByQuestionId('vitals')[0];
|
|
353
|
+
if (!(repeat instanceof ArrayNode)) {
|
|
354
|
+
throw new Error('Expected a repeating obs group');
|
|
355
|
+
}
|
|
356
|
+
const first = repeat.createChildNode();
|
|
357
|
+
const second = repeat.createChildNode();
|
|
358
|
+
loadSavedGroup(first, 'first-group', 37);
|
|
359
|
+
loadSavedGroup(second, 'second-group', 38);
|
|
360
|
+
subscription = service.connect(form, 'patient-uuid');
|
|
361
|
+
tick();
|
|
362
|
+
form.searchNodeByQuestionId('encDate')[0].control.setValue('2021-01-01T00:00:00Z');
|
|
363
|
+
tick();
|
|
364
|
+
expect(controlOf(first.children['temperature']).conceptReferenceRange).toBe(early.get('temperature-uuid'));
|
|
365
|
+
|
|
366
|
+
first.children['note'].control.setValue('Feverish');
|
|
367
|
+
tick();
|
|
368
|
+
expect(controlOf(first.children['temperature']).conceptReferenceRange).toBe(later.get('temperature-uuid'));
|
|
369
|
+
expect(controlOf(second.children['temperature']).conceptReferenceRange).toBe(early.get('temperature-uuid'));
|
|
370
|
+
}));
|
|
371
|
+
|
|
372
|
+
it('falls back to the encounter date when a separately dated answer has no date yet', fakeAsync(() => {
|
|
373
|
+
const measurement = numericQuestion();
|
|
374
|
+
const form = createForm([
|
|
375
|
+
{
|
|
376
|
+
...measurement,
|
|
377
|
+
questionOptions: { ...measurement.questionOptions, showDate: true },
|
|
378
|
+
},
|
|
379
|
+
]);
|
|
380
|
+
const control = controlFor(form);
|
|
381
|
+
control.setValue(45);
|
|
382
|
+
subscription = service.connect(form, 'patient-uuid');
|
|
383
|
+
tick();
|
|
384
|
+
expect(resource.getConceptReferenceRanges).toHaveBeenCalledOnceWith('patient-uuid', ['temperature-uuid'], {
|
|
385
|
+
date: moment('2020-01-01T00:00:00Z').format(),
|
|
386
|
+
});
|
|
387
|
+
expect(control.valid).toBe(false);
|
|
388
|
+
|
|
389
|
+
form.searchNodeByQuestionId('date_temperature')[0].control.setValue(new Date(Number.NaN));
|
|
390
|
+
tick();
|
|
391
|
+
expect(resource.getConceptReferenceRanges.calls.mostRecent().args[2]).toEqual({
|
|
392
|
+
date: moment('2020-01-01T00:00:00Z').format(),
|
|
393
|
+
});
|
|
394
|
+
expect(control.valid).toBe(false);
|
|
395
|
+
}));
|
|
396
|
+
|
|
397
|
+
it('keeps ranges at the date the encounter will be saved with while its date is blank or invalid', fakeAsync(() => {
|
|
398
|
+
const form = createForm();
|
|
399
|
+
const control = controlFor(form);
|
|
400
|
+
const encounterDate = form.searchNodeByQuestionId('encDate')[0].control;
|
|
401
|
+
subscription = service.connect(form, 'patient-uuid');
|
|
402
|
+
tick();
|
|
403
|
+
encounterDate.setValue(new Date(Number.NaN));
|
|
404
|
+
tick();
|
|
405
|
+
const context = resource.getConceptReferenceRanges.calls.mostRecent().args[2];
|
|
406
|
+
expect(Math.abs(moment().diff(context.date, 'seconds'))).toBeLessThan(5);
|
|
407
|
+
expect(control.conceptReferenceRange).toBe(early.get('temperature-uuid'));
|
|
408
|
+
|
|
409
|
+
form.valueProcessingInfo.encounterUuid = 'historical-encounter';
|
|
410
|
+
encounterDate.setValue('');
|
|
411
|
+
tick();
|
|
412
|
+
expect(resource.getConceptReferenceRanges.calls.mostRecent().args[2]).toEqual({
|
|
413
|
+
encounter: 'historical-encounter',
|
|
414
|
+
});
|
|
415
|
+
expect(control.conceptReferenceRange).toBe(early.get('temperature-uuid'));
|
|
416
|
+
}));
|
|
417
|
+
|
|
418
|
+
it('uses the saved encounter when the form has no encounter-date question', fakeAsync(() => {
|
|
419
|
+
const form = createForm([numericQuestion()], false);
|
|
420
|
+
form.valueProcessingInfo.encounterUuid = 'historical-encounter';
|
|
421
|
+
subscription = service.connect(form, 'patient-uuid');
|
|
422
|
+
tick();
|
|
423
|
+
expect(resource.getConceptReferenceRanges.calls.mostRecent().args[2]).toEqual({
|
|
424
|
+
encounter: 'historical-encounter',
|
|
425
|
+
});
|
|
426
|
+
}));
|
|
427
|
+
|
|
428
|
+
it('refreshes a separately dated observation when its measurement date is edited', fakeAsync(() => {
|
|
429
|
+
const measurement = numericQuestion();
|
|
430
|
+
const form = createForm([
|
|
431
|
+
{
|
|
432
|
+
...measurement,
|
|
433
|
+
questionOptions: { ...measurement.questionOptions, showDate: true },
|
|
434
|
+
},
|
|
435
|
+
]);
|
|
436
|
+
const observation = { uuid: 'historical-obs', obsDatetime: '2019-01-01T00:00:00Z', value: 37 };
|
|
437
|
+
form.searchNodeByQuestionId('complex_temperature')[0].initialValue = observation;
|
|
438
|
+
form.searchNodeByQuestionId('temperature')[0].initialValue = observation;
|
|
439
|
+
controlFor(form).setValue(observation.value);
|
|
440
|
+
const date = form.searchNodeByQuestionId('date_temperature')[0].control;
|
|
441
|
+
date.setValue(observation.obsDatetime);
|
|
442
|
+
subscription = service.connect(form, 'patient-uuid');
|
|
443
|
+
tick();
|
|
444
|
+
expect(resource.getConceptReferenceRanges.calls.mostRecent().args[2]).toEqual({ obs: 'historical-obs' });
|
|
445
|
+
date.setValue('2018-01-01T00:00:00Z');
|
|
446
|
+
tick();
|
|
447
|
+
expect(resource.getConceptReferenceRanges.calls.mostRecent().args[2]).toEqual({
|
|
448
|
+
date: moment('2018-01-01T00:00:00Z').format(),
|
|
449
|
+
});
|
|
450
|
+
}));
|
|
451
|
+
|
|
452
|
+
it('cancels stale responses and keeps submission pending even when a numeric answer changes', fakeAsync(() => {
|
|
453
|
+
const first = new Subject<Map<string, ConceptReferenceRange>>();
|
|
454
|
+
const second = new Subject<Map<string, ConceptReferenceRange>>();
|
|
455
|
+
resource.getConceptReferenceRanges.and.returnValues(first, second);
|
|
456
|
+
const form = createForm();
|
|
457
|
+
const control = controlFor(form);
|
|
458
|
+
subscription = service.connect(form, 'patient-uuid');
|
|
459
|
+
tick();
|
|
460
|
+
form.searchNodeByQuestionId('encDate')[0].control.setValue('2021-01-01T00:00:00Z');
|
|
461
|
+
first.next(early);
|
|
462
|
+
first.complete();
|
|
463
|
+
expect(service.isLoading(form)).toBe(true);
|
|
464
|
+
expect(control.conceptReferenceRange).toBeUndefined();
|
|
465
|
+
tick();
|
|
466
|
+
control.setValue(45);
|
|
467
|
+
expect(service.isLoading(form)).toBe(true);
|
|
468
|
+
second.next(later);
|
|
469
|
+
second.complete();
|
|
470
|
+
expect(service.isLoading(form)).toBe(false);
|
|
471
|
+
expect(control.valid).toBe(true);
|
|
472
|
+
}));
|
|
473
|
+
|
|
474
|
+
it('reports when pending ranges finish loading', fakeAsync(() => {
|
|
475
|
+
const response = new Subject<Map<string, ConceptReferenceRange>>();
|
|
476
|
+
resource.getConceptReferenceRanges.and.returnValue(response);
|
|
477
|
+
const form = createForm();
|
|
478
|
+
subscription = service.connect(form, 'patient-uuid');
|
|
479
|
+
let loaded = false;
|
|
480
|
+
service.whenLoaded(form).subscribe(() => (loaded = true));
|
|
481
|
+
tick();
|
|
482
|
+
expect(loaded).toBe(false);
|
|
483
|
+
|
|
484
|
+
response.next(early);
|
|
485
|
+
response.complete();
|
|
486
|
+
expect(loaded).toBe(true);
|
|
487
|
+
|
|
488
|
+
let loadedAgain = false;
|
|
489
|
+
service.whenLoaded(form).subscribe(() => (loadedAgain = true));
|
|
490
|
+
expect(loadedAgain).toBe(true);
|
|
491
|
+
}));
|
|
492
|
+
|
|
493
|
+
it('keeps schema validation when the server returns no range', fakeAsync(() => {
|
|
494
|
+
resource.getConceptReferenceRanges.and.returnValue(of(new Map()));
|
|
495
|
+
const form = createForm();
|
|
496
|
+
subscription = service.connect(form, 'patient-uuid');
|
|
497
|
+
tick();
|
|
498
|
+
const control = controlFor(form);
|
|
499
|
+
control.setValue(5);
|
|
500
|
+
expect(control.valid).toBe(false);
|
|
501
|
+
expect(control.alerts[0].shown).toBe(false);
|
|
502
|
+
expect(service.isLoading(form)).toBe(false);
|
|
503
|
+
}));
|
|
504
|
+
|
|
505
|
+
it('loads ranges for newly added repeated questions and stops listening when disconnected', fakeAsync(() => {
|
|
506
|
+
const form = createForm([
|
|
507
|
+
{
|
|
508
|
+
id: 'repeat',
|
|
509
|
+
type: 'obsGroup',
|
|
510
|
+
questionOptions: { rendering: 'repeating' },
|
|
511
|
+
questions: [numericQuestion()],
|
|
512
|
+
},
|
|
513
|
+
]);
|
|
514
|
+
subscription = service.connect(form, 'patient-uuid');
|
|
515
|
+
tick();
|
|
516
|
+
expect(resource.getConceptReferenceRanges).not.toHaveBeenCalled();
|
|
517
|
+
form.searchNodeByQuestionId('repeat')[0].createChildNode();
|
|
518
|
+
tick();
|
|
519
|
+
expect(controlFor(form).conceptReferenceRange).toBe(early.get('temperature-uuid'));
|
|
520
|
+
subscription.unsubscribe();
|
|
521
|
+
resource.getConceptReferenceRanges.calls.reset();
|
|
522
|
+
form.searchNodeByQuestionId('encDate')[0].control.setValue('2021-01-01T00:00:00Z');
|
|
523
|
+
tick();
|
|
524
|
+
expect(resource.getConceptReferenceRanges).not.toHaveBeenCalled();
|
|
525
|
+
}));
|
|
526
|
+
});
|