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

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.
@@ -1,6 +1,6 @@
1
1
  import dayjs from "dayjs";
2
2
  import { ConceptTrue, codedTypes } from "../constants.js";
3
- import { hasRendering, gracefullySetSubmission, clearSubmission, flattenObsList, parseToLocalDateTime, formatDateAsDisplayString } from "../utils/common-utils.js";
3
+ import { hasRendering, gracefullySetSubmission, clearSubmission, flattenObsList, parseClockTime, parseToLocalDateTime, formatDateAsDisplayString } from "../utils/common-utils.js";
4
4
  import { isEmpty } from "../validators/form-validator.js";
5
5
  import { attachmentUrl, getAttachmentByUuid } from "@openmrs/esm-framework";
6
6
  // Temporarily holds observations that have already been bound with matching fields
@@ -103,7 +103,7 @@ export const ObsAdapter = {
103
103
  assignedObsIds.push(obs.uuid);
104
104
  if (typeof obs.value === 'string' || typeof obs.value === 'number') {
105
105
  if (rendering.startsWith('date')) {
106
- const dateObject = parseToLocalDateTime(obs.value);
106
+ const dateObject = field.datePickerFormat === 'timer' ? parseClockTime(obs.value) : parseToLocalDateTime(obs.value);
107
107
  if (makeFieldDirty) {
108
108
  const obsObject = field.meta.initialValue.omrsObject;
109
109
  obsObject.value = dayjs(dateObject).format('YYYY-MM-DD HH:mm');
@@ -162,7 +162,7 @@ function formatDateByPickerType(field, value) {
162
162
  case 'timer':
163
163
  return dayjs(value).format('HH:mm');
164
164
  case 'both':
165
- return dayjs(value).format('YYYY-MM-DD HH:mm');
165
+ return dayjs(value).format('YYYY-MM-DDTHH:mmZ');
166
166
  default:
167
167
  return dayjs(value).format('YYYY-MM-DD');
168
168
  }
@@ -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,EA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kBAAkB,CAChC,OAAO,EAAE,KAAK,CAAC,UAAU,CAAC,EAC1B,aAAa,EAAE,MAAM,EAAE,EACvB,KAAK,EAAE,SAAS,GACf,UAAU,EAAE,CAmBd"}
@@ -7,6 +7,13 @@ export declare function gracefullySetSubmission(field: FormField, newValue: any,
7
7
  export declare function hasSubmission(field: FormField): boolean;
8
8
  export declare function isViewMode(sessionMode: string): sessionMode is "view" | "embedded-view";
9
9
  export declare function parseToLocalDateTime(dateString: string): Date;
10
+ /**
11
+ * Reads a Time obs value. The backend returns Time obs as a datetime in its own timezone
12
+ * (e.g. `1970-01-01T22:00:00.000+0000`), but the value is a clock time, so the offset does not apply.
13
+ * Returns 1970-01-01 at that clock time in local time, without seconds, or an Invalid Date
14
+ * if the string has no `THH:mm` part.
15
+ */
16
+ export declare function parseClockTime(dateString: string): Date;
10
17
  /**
11
18
  * Returns `date` if it falls within the visit's start/stop window, otherwise the
12
19
  * visit's start datetime. This keeps default encounter datetimes valid when filling
@@ -1 +1 @@
1
- {"version":3,"file":"common-utils.d.ts","sourceRoot":"","sources":["../../../src/utils/common-utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,UAAU,EAAE,KAAK,SAAS,EAAE,KAAK,UAAU,EAAE,KAAK,UAAU,EAAE,MAAM,UAAU,CAAC;AAE7F,OAAO,EAAsC,KAAK,KAAK,EAAE,MAAM,wBAAwB,CAAC;AAExF,wBAAgB,cAAc,CAAC,OAAO,EAAE,UAAU,EAAE,GAAG,UAAU,EAAE,CAgBlE;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,WAEnE;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,SAAS,QAS/C;AAED,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,GAAG,EAAE,WAAW,EAAE,GAAG,OAWxF;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,SAAS,WAE7C;AAED,wBAA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ACrB,kBAAkB,KAAA,EAClB,iBAAiB,EAAE,CAAC,KAAK,EAAE,SAAS,KAAK,IAAI,GAAG,IAAI,QAuBrD;AAsBD;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,KAAA,OAmBjE;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,WAAW,GAAE,OAAe,QAW1E;AAED,eAAO,MAAM,yBAAyB,GAAI,OAAO,SAAS,EAAE,KAAK,GAAG;;;CA6BnE,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,QAAQ,WASlD;AA+CD;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,UAAU,EAAE,KAAK,EAAE,SAAS,eAGtE"}
@@ -1,6 +1,5 @@
1
- import dayjs from "dayjs";
2
1
  import { isEmpty } from "../validators/form-validator.js";
3
- import { formatDate } from "@openmrs/esm-framework";
2
+ import { formatDate, parseDate } from "@openmrs/esm-framework";
4
3
  export function flattenObsList(obsList) {
5
4
  const flattenedList = [];
6
5
  function flatten(obs) {
@@ -54,20 +53,16 @@ export function isViewMode(sessionMode) {
54
53
  return sessionMode === 'view' || sessionMode === 'embedded-view';
55
54
  }
56
55
  export function parseToLocalDateTime(dateString) {
57
- const dateObj = dayjs(dateString).toDate();
58
- if (isNaN(dateObj.getTime())) {
59
- return new Date(NaN);
60
- }
61
- try {
62
- const timePart = dateString.split('T')[1];
63
- if (timePart) {
64
- const localTimeTokens = timePart.split(':');
65
- dateObj.setHours(parseInt(localTimeTokens[0]), parseInt(localTimeTokens[1]), 0);
66
- }
67
- } catch (e) {
68
- console.error(e);
69
- }
70
- return dateObj;
56
+ return parseDate(dateString);
57
+ }
58
+ /**
59
+ * Reads a Time obs value. The backend returns Time obs as a datetime in its own timezone
60
+ * (e.g. `1970-01-01T22:00:00.000+0000`), but the value is a clock time, so the offset does not apply.
61
+ * Returns 1970-01-01 at that clock time in local time, without seconds, or an Invalid Date
62
+ * if the string has no `THH:mm` part.
63
+ */ export function parseClockTime(dateString) {
64
+ const [, hours, minutes] = /T(\d{2}):(\d{2})/.exec(dateString) ?? [];
65
+ return hours ? new Date(1970, 0, 1, Number(hours), Number(minutes)) : new Date(NaN);
71
66
  }
72
67
  /**
73
68
  * Returns `date` if it falls within the visit's start/stop window, otherwise the
@@ -1,5 +1,5 @@
1
1
  import { isEmpty } from "../validators/form-validator.js";
2
- import { parseToLocalDateTime } from "./common-utils.js";
2
+ import { parseClockTime, parseToLocalDateTime } from "./common-utils.js";
3
3
  import dayjs from "dayjs";
4
4
  import { ConceptFalse, ConceptTrue } from "../constants.js";
5
5
  export function shouldUseInlineLayout(renderingType, layoutType, workspaceLayout, sessionMode) {
@@ -146,7 +146,7 @@ export const extractObsValueAndDisplay = (field, obs)=>{
146
146
  }
147
147
  if (typeof omrsObs.value === 'string' || typeof omrsObs.value === 'number') {
148
148
  if (rendering === 'date' || rendering === 'datetime') {
149
- const dateObj = parseToLocalDateTime(`${omrsObs.value}`);
149
+ const dateObj = field.datePickerFormat === 'timer' ? parseClockTime(`${omrsObs.value}`) : parseToLocalDateTime(`${omrsObs.value}`);
150
150
  return {
151
151
  value: dateObj,
152
152
  display: dayjs(dateObj).format('YYYY-MM-DD HH:mm')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openmrs/esm-form-engine-lib",
3
- "version": "4.3.1-pre.2711",
3
+ "version": "4.3.1-pre.2715",
4
4
  "description": "React Form Engine for O3",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
@@ -13,6 +13,7 @@ import {
13
13
  gracefullySetSubmission,
14
14
  clearSubmission,
15
15
  flattenObsList,
16
+ parseClockTime,
16
17
  parseToLocalDateTime,
17
18
  formatDateAsDisplayString,
18
19
  } from '../utils/common-utils';
@@ -126,7 +127,10 @@ function extractFieldValue(field: FormField, obsList: OpenmrsObs[] = [], makeFie
126
127
  assignedObsIds.push(obs.uuid);
127
128
  if (typeof obs.value === 'string' || typeof obs.value === 'number') {
128
129
  if (rendering.startsWith('date')) {
129
- const dateObject = parseToLocalDateTime(obs.value as string);
130
+ const dateObject =
131
+ field.datePickerFormat === 'timer'
132
+ ? parseClockTime(obs.value as string)
133
+ : parseToLocalDateTime(obs.value as string);
130
134
  if (makeFieldDirty) {
131
135
  const obsObject = field.meta.initialValue.omrsObject as OpenmrsObs;
132
136
  obsObject.value = dayjs(dateObject).format('YYYY-MM-DD HH:mm');
@@ -189,7 +193,7 @@ function formatDateByPickerType(field: FormField, value: Date) {
189
193
  case 'timer':
190
194
  return dayjs(value).format('HH:mm');
191
195
  case 'both':
192
- return dayjs(value).format('YYYY-MM-DD HH:mm');
196
+ return dayjs(value).format('YYYY-MM-DDTHH:mmZ');
193
197
  default:
194
198
  return dayjs(value).format('YYYY-MM-DD');
195
199
  }
@@ -1,7 +1,6 @@
1
- import dayjs from 'dayjs';
2
1
  import { type FormSchema, type FormField, type OpenmrsObs, type RenderType } from '../types';
3
2
  import { isEmpty } from '../validators/form-validator';
4
- import { formatDate, type FormatDateOptions, type Visit } from '@openmrs/esm-framework';
3
+ import { formatDate, parseDate, type FormatDateOptions, type Visit } from '@openmrs/esm-framework';
5
4
 
6
5
  export function flattenObsList(obsList: OpenmrsObs[]): OpenmrsObs[] {
7
6
  const flattenedList: OpenmrsObs[] = [];
@@ -58,21 +57,18 @@ export function isViewMode(sessionMode: string) {
58
57
  }
59
58
 
60
59
  export function parseToLocalDateTime(dateString: string): Date {
61
- const dateObj = dayjs(dateString).toDate();
62
- if (isNaN(dateObj.getTime())) {
63
- return new Date(NaN);
64
- }
60
+ return parseDate(dateString);
61
+ }
65
62
 
66
- try {
67
- const timePart = dateString.split('T')[1];
68
- if (timePart) {
69
- const localTimeTokens = timePart.split(':');
70
- dateObj.setHours(parseInt(localTimeTokens[0]), parseInt(localTimeTokens[1]), 0);
71
- }
72
- } catch (e) {
73
- console.error(e);
74
- }
75
- return dateObj;
63
+ /**
64
+ * Reads a Time obs value. The backend returns Time obs as a datetime in its own timezone
65
+ * (e.g. `1970-01-01T22:00:00.000+0000`), but the value is a clock time, so the offset does not apply.
66
+ * Returns 1970-01-01 at that clock time in local time, without seconds, or an Invalid Date
67
+ * if the string has no `THH:mm` part.
68
+ */
69
+ export function parseClockTime(dateString: string): Date {
70
+ const [, hours, minutes] = /T(\d{2}):(\d{2})/.exec(dateString) ?? [];
71
+ return hours ? new Date(1970, 0, 1, Number(hours), Number(minutes)) : new Date(NaN);
76
72
  }
77
73
 
78
74
  /**
@@ -1,7 +1,7 @@
1
1
  import { type LayoutType } from '@openmrs/esm-framework';
2
2
  import type { FormField, FormPage, FormSection, SessionMode, FHIRObsResource, RenderType, FormSchema } from '../types';
3
3
  import { isEmpty } from '../validators/form-validator';
4
- import { parseToLocalDateTime } from './common-utils';
4
+ import { parseClockTime, parseToLocalDateTime } from './common-utils';
5
5
  import dayjs from 'dayjs';
6
6
  import { ConceptFalse, ConceptTrue } from '../constants';
7
7
 
@@ -191,7 +191,10 @@ export const extractObsValueAndDisplay = (field: FormField, obs: any) => {
191
191
  }
192
192
  if (typeof omrsObs.value === 'string' || typeof omrsObs.value === 'number') {
193
193
  if (rendering === 'date' || rendering === 'datetime') {
194
- const dateObj = parseToLocalDateTime(`${omrsObs.value}`);
194
+ const dateObj =
195
+ field.datePickerFormat === 'timer'
196
+ ? parseClockTime(`${omrsObs.value}`)
197
+ : parseToLocalDateTime(`${omrsObs.value}`);
195
198
  return { value: dateObj, display: dayjs(dateObj).format('YYYY-MM-DD HH:mm') };
196
199
  }
197
200
  return { value: omrsObs.value, display: omrsObs.value };