@openmrs/esm-form-engine-lib 4.3.1-pre.2715 → 4.3.1-pre.2719

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.
@@ -17,7 +17,9 @@ export const ObsAdapter = {
17
17
  async getPreviousValue (field, sourceObject, context) {
18
18
  const encounter = sourceObject ?? context.previousDomainObjectValue;
19
19
  if (encounter) {
20
- const value = extractFieldValue(field, findObsByFormField(flattenObsList(encounter.obs), assignedObsIds, field), true);
20
+ // the previous encounter's obs must not become this field's obs to edit or void;
21
+ // an obs already loaded for this encounter stays bound to the field
22
+ const value = extractFieldValue(field, findObsByFormField(flattenObsList(encounter.obs), assignedObsIds, field), false);
21
23
  if (!isEmpty(value)) {
22
24
  return {
23
25
  value,
@@ -63,6 +65,11 @@ export const ObsAdapter = {
63
65
  if (!isEmpty(value) && hasPreviousObsValueChanged(field, value)) {
64
66
  return gracefullySetSubmission(field, editObs(field, value), undefined);
65
67
  }
68
+ if (!isEmpty(value) && field.meta.initialValue?.omrsObject) {
69
+ // unchanged value on a stored obs: leave it alone, as falling through
70
+ // to constructObs would submit a uuid-less duplicate
71
+ return null;
72
+ }
66
73
  if (field.meta.initialValue?.omrsObject && isEmpty(value)) {
67
74
  return gracefullySetSubmission(field, undefined, voidObs(field.meta.initialValue.omrsObject));
68
75
  }
@@ -91,7 +98,9 @@ export const ObsAdapter = {
91
98
  if (obsList.length) {
92
99
  if (rendering == 'checkbox') {
93
100
  assignedObsIds.push(...obsList.map((obs)=>obs.uuid));
94
- field.meta.initialValue.omrsObject = makeFieldDirty ? obsList : null;
101
+ if (makeFieldDirty) {
102
+ field.meta.initialValue.omrsObject = obsList;
103
+ }
95
104
  return obsList.map((o)=>o.value.uuid);
96
105
  }
97
106
  const obs = obsList[0];
@@ -155,19 +164,18 @@ export function editObs(field, newValue) {
155
164
  };
156
165
  }
157
166
  function formatDateByPickerType(field, value) {
158
- if (field.datePickerFormat) {
159
- switch(field.datePickerFormat){
160
- case 'calendar':
161
- return dayjs(value).format('YYYY-MM-DD');
162
- case 'timer':
163
- return dayjs(value).format('HH:mm');
164
- case 'both':
165
- return dayjs(value).format('YYYY-MM-DDTHH:mmZ');
166
- default:
167
- return dayjs(value).format('YYYY-MM-DD');
168
- }
167
+ // fields that skip the schema transformer can arrive without a datePickerFormat,
168
+ // so fall back to the defaults the transformer applies per rendering
169
+ const datePickerFormat = field.datePickerFormat ?? (hasRendering(field, 'datetime') ? 'both' : 'calendar');
170
+ switch(datePickerFormat){
171
+ case 'timer':
172
+ return dayjs(value).format('HH:mm');
173
+ case 'both':
174
+ return dayjs(value).format('YYYY-MM-DDTHH:mmZ');
175
+ case 'calendar':
176
+ default:
177
+ return dayjs(value).format('YYYY-MM-DD');
169
178
  }
170
- return value;
171
179
  }
172
180
  export function hasPreviousObsValueChanged(field, newValue) {
173
181
  const previousObs = field.meta.initialValue?.omrsObject;
@@ -177,11 +185,9 @@ export function hasPreviousObsValueChanged(field, newValue) {
177
185
  if (codedTypes.includes(field.questionOptions.rendering)) {
178
186
  return previousObs.value.uuid !== newValue;
179
187
  }
180
- if (hasRendering(field, 'date')) {
181
- return dayjs(newValue).diff(dayjs(previousObs.value), 'D') !== 0;
182
- }
183
- if (hasRendering(field, 'datetime') || field.datePickerFormat === 'both') {
184
- return dayjs(newValue).diff(dayjs(previousObs.value), 'minute') !== 0;
188
+ if (field.questionOptions.rendering.startsWith('date')) {
189
+ // compare what would be submitted, at the precision of the date picker
190
+ return formatDateByPickerType(field, previousObs.value) !== formatDateByPickerType(field, newValue);
185
191
  }
186
192
  if (hasRendering(field, 'toggle')) {
187
193
  return previousObs.value.uuid === ConceptTrue !== newValue;
@@ -1 +1 @@
1
- {"version":3,"file":"obs-adapter.d.ts","sourceRoot":"","sources":["../../../src/adapters/obs-adapter.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,KAAK,UAAU,EACf,KAAK,SAAS,EAGd,KAAK,qBAAqB,EAC3B,MAAM,UAAU,CAA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,EAAE,KAAK,CAAC,UAAU,CAAC,EAC1B,aAAa,EAAE,MAAM,EAAE,EACvB,KAAK,EAAE,SAAS,GACf,UAAU,EAAE,CAmBd"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openmrs/esm-form-engine-lib",
3
- "version": "4.3.1-pre.2715",
3
+ "version": "4.3.1-pre.2719",
4
4
  "description": "React Form Engine for O3",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
@@ -15,6 +15,13 @@
15
15
  "!src/zscore-tests"
16
16
  ],
17
17
  "license": "MIT",
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git+https://github.com/openmrs/openmrs-esm-form-engine-lib.git"
21
+ },
22
+ "bugs": {
23
+ "url": "https://openmrs.atlassian.net/jira/software/c/projects/O3/boards/37"
24
+ },
18
25
  "homepage": "https://github.com/openmrs/openmrs-esm-form-engine-lib#readme",
19
26
  "scripts": {
20
27
  "lint": "eslint src --fix",
@@ -36,10 +36,12 @@ export const ObsAdapter: FormFieldValueAdapter = {
36
36
  async getPreviousValue(field: FormField, sourceObject: any, context: FormContextProps): Promise<ValueAndDisplay> {
37
37
  const encounter = sourceObject ?? (context.previousDomainObjectValue as OpenmrsEncounter);
38
38
  if (encounter) {
39
+ // the previous encounter's obs must not become this field's obs to edit or void;
40
+ // an obs already loaded for this encounter stays bound to the field
39
41
  const value = extractFieldValue(
40
42
  field,
41
43
  findObsByFormField(flattenObsList(encounter.obs), assignedObsIds, field),
42
- true,
44
+ false,
43
45
  );
44
46
  if (!isEmpty(value)) {
45
47
  return {
@@ -86,6 +88,11 @@ export const ObsAdapter: FormFieldValueAdapter = {
86
88
  if (!isEmpty(value) && hasPreviousObsValueChanged(field, value)) {
87
89
  return gracefullySetSubmission(field, editObs(field, value), undefined);
88
90
  }
91
+ if (!isEmpty(value) && field.meta.initialValue?.omrsObject) {
92
+ // unchanged value on a stored obs: leave it alone, as falling through
93
+ // to constructObs would submit a uuid-less duplicate
94
+ return null;
95
+ }
89
96
  if (field.meta.initialValue?.omrsObject && isEmpty(value)) {
90
97
  return gracefullySetSubmission(field, undefined, voidObs(field.meta.initialValue.omrsObject as OpenmrsObs));
91
98
  }
@@ -117,7 +124,9 @@ function extractFieldValue(field: FormField, obsList: OpenmrsObs[] = [], makeFie
117
124
  if (obsList.length) {
118
125
  if (rendering == 'checkbox') {
119
126
  assignedObsIds.push(...obsList.map((obs) => obs.uuid));
120
- field.meta.initialValue.omrsObject = makeFieldDirty ? obsList : null;
127
+ if (makeFieldDirty) {
128
+ field.meta.initialValue.omrsObject = obsList;
129
+ }
121
130
  return obsList.map((o) => o.value.uuid);
122
131
  }
123
132
  const obs = obsList[0];
@@ -185,20 +194,19 @@ export function editObs(field: FormField, newValue: any) {
185
194
  };
186
195
  }
187
196
 
188
- function formatDateByPickerType(field: FormField, value: Date) {
189
- if (field.datePickerFormat) {
190
- switch (field.datePickerFormat) {
191
- case 'calendar':
192
- return dayjs(value).format('YYYY-MM-DD');
193
- case 'timer':
194
- return dayjs(value).format('HH:mm');
195
- case 'both':
196
- return dayjs(value).format('YYYY-MM-DDTHH:mmZ');
197
- default:
198
- return dayjs(value).format('YYYY-MM-DD');
199
- }
197
+ function formatDateByPickerType(field: FormField, value: Date | string) {
198
+ // fields that skip the schema transformer can arrive without a datePickerFormat,
199
+ // so fall back to the defaults the transformer applies per rendering
200
+ const datePickerFormat = field.datePickerFormat ?? (hasRendering(field, 'datetime') ? 'both' : 'calendar');
201
+ switch (datePickerFormat) {
202
+ case 'timer':
203
+ return dayjs(value).format('HH:mm');
204
+ case 'both':
205
+ return dayjs(value).format('YYYY-MM-DDTHH:mmZ');
206
+ case 'calendar':
207
+ default:
208
+ return dayjs(value).format('YYYY-MM-DD');
200
209
  }
201
- return value;
202
210
  }
203
211
 
204
212
  export function hasPreviousObsValueChanged(field: FormField, newValue: any) {
@@ -209,11 +217,9 @@ export function hasPreviousObsValueChanged(field: FormField, newValue: any) {
209
217
  if (codedTypes.includes(field.questionOptions.rendering)) {
210
218
  return previousObs.value.uuid !== newValue;
211
219
  }
212
- if (hasRendering(field, 'date')) {
213
- return dayjs(newValue).diff(dayjs(previousObs.value), 'D') !== 0;
214
- }
215
- if (hasRendering(field, 'datetime') || field.datePickerFormat === 'both') {
216
- return dayjs(newValue).diff(dayjs(previousObs.value), 'minute') !== 0;
220
+ if (field.questionOptions.rendering.startsWith('date')) {
221
+ // compare what would be submitted, at the precision of the date picker
222
+ return formatDateByPickerType(field, previousObs.value) !== formatDateByPickerType(field, newValue);
217
223
  }
218
224
  if (hasRendering(field, 'toggle')) {
219
225
  return (previousObs.value.uuid === ConceptTrue) !== newValue;