@openmrs/esm-form-engine-lib 4.2.2-pre.2682 → 4.2.2-pre.2689

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 +1 @@
1
- {"version":3,"file":"zscore-service.d.ts","sourceRoot":"","sources":["../../../src/utils/zscore-service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,UAAU,CAAC;AAE3C,KAAK,WAAW,GAAG,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC;AA6B9C;;;;GAIG;AACH,wBAAsB,oBAAoB,CAAC,QAAQ,EAAE,UAAU,iBAkB9D;AAUD,wBAAgB,qBAAqB,CAAC,MAAM,KAAA,EAAE,SAAS,KAAA,EAAE,OAAO,KAAA,eAU/D;AAED,wBAAgB,kBAAkB,CAAC,MAAM,KAAA,EAAE,SAAS,KAAA,EAAE,OAAO,KAAA,OAsB5D;AAED,wBAAgB,eAAe,CAAC,MAAM,KAAA,EAAE,SAAS,KAAA,EAAE,OAAO,KAAA,OAWzD"}
1
+ {"version":3,"file":"zscore-service.d.ts","sourceRoot":"","sources":["../../../src/utils/zscore-service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,UAAU,CAAC;AAE3C,KAAK,WAAW,GAAG,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC;AA6B9C;;;;GAIG;AACH,wBAAsB,oBAAoB,CAAC,QAAQ,EAAE,UAAU,iBAkB9D;AAiBD,wBAAgB,qBAAqB,CAAC,MAAM,KAAA,EAAE,SAAS,KAAA,EAAE,OAAO,KAAA,eAU/D;AAED,wBAAgB,kBAAkB,CAAC,MAAM,KAAA,EAAE,SAAS,KAAA,EAAE,OAAO,KAAA,OAuB5D;AAED,wBAAgB,eAAe,CAAC,MAAM,KAAA,EAAE,SAAS,KAAA,EAAE,OAAO,KAAA,OAazD"}
@@ -56,12 +56,17 @@ function getTable(name) {
56
56
  }
57
57
  return table;
58
58
  }
59
+ /**
60
+ * The under-5 tables (the WHO child growth standards) go up to day 1,856, and the 5 to 19 year tables (the WHO
61
+ * growth reference) start at 61 months.
62
+ */ const lastDayOfUnderFiveTables = 1856;
63
+ const firstMonthOfOlderChildTables = 61;
59
64
  export function getWeightForHeightRef(gender, birthDate, refdate) {
60
65
  const age = getAge(birthDate, refdate, 'years');
61
- if (gender === 'F' && age < 5) {
66
+ if (gender === 'F' && age !== null && age < 5) {
62
67
  return getTable('wflFemaleBelow5');
63
68
  }
64
- if (gender === 'M' && age < 5) {
69
+ if (gender === 'M' && age !== null && age < 5) {
65
70
  return getTable('wflMaleBelow5');
66
71
  }
67
72
  return null;
@@ -70,20 +75,21 @@ export function getHeightForAgeRef(gender, birthDate, refdate) {
70
75
  const age = getAge(birthDate, refdate, 'years');
71
76
  const ageInMonths = getAge(birthDate, refdate, 'months');
72
77
  const ageInDays = getAge(birthDate, refdate, 'days');
78
+ const olderChildMonth = Math.max(ageInMonths, firstMonthOfOlderChildTables);
73
79
  if (gender === 'F') {
74
- if (age < 5) {
80
+ if (ageInDays !== null && ageInDays <= lastDayOfUnderFiveTables) {
75
81
  return getScoreReference(getTable('hfaFemaleBelow5'), 'Day', ageInDays);
76
82
  }
77
- if (age >= 5 && age < 18) {
78
- return getScoreReference(getTable('hfaFemale5Above'), 'Month', ageInMonths);
83
+ if (ageInDays > lastDayOfUnderFiveTables && age < 18) {
84
+ return getScoreReference(getTable('hfaFemale5Above'), 'Month', olderChildMonth);
79
85
  }
80
86
  }
81
87
  if (gender === 'M') {
82
- if (age < 5) {
88
+ if (ageInDays !== null && ageInDays <= lastDayOfUnderFiveTables) {
83
89
  return getScoreReference(getTable('hfaMaleBelow5'), 'Day', ageInDays);
84
90
  }
85
- if (age >= 5 && age < 18) {
86
- return getScoreReference(getTable('hfaMale5Above'), 'Month', ageInMonths);
91
+ if (ageInDays > lastDayOfUnderFiveTables && age < 18) {
92
+ return getScoreReference(getTable('hfaMale5Above'), 'Month', olderChildMonth);
87
93
  }
88
94
  }
89
95
  return null;
@@ -91,11 +97,13 @@ export function getHeightForAgeRef(gender, birthDate, refdate) {
91
97
  export function getBmiForAgeRef(gender, birthDate, refdate) {
92
98
  const age = getAge(birthDate, refdate, 'years');
93
99
  const ageInMonths = getAge(birthDate, refdate, 'months');
94
- if (gender === 'F' && age >= 5 && age < 18) {
95
- return getScoreReference(getTable('bfaFemale5Above'), 'Month', ageInMonths);
100
+ const ageInDays = getAge(birthDate, refdate, 'days');
101
+ const olderChildMonth = Math.max(ageInMonths, firstMonthOfOlderChildTables);
102
+ if (gender === 'F' && ageInDays > lastDayOfUnderFiveTables && age < 18) {
103
+ return getScoreReference(getTable('bfaFemale5Above'), 'Month', olderChildMonth);
96
104
  }
97
- if (gender === 'M' && age >= 5 && age < 18) {
98
- return getScoreReference(getTable('bfaMale5Above'), 'Month', ageInMonths);
105
+ if (gender === 'M' && ageInDays > lastDayOfUnderFiveTables && age < 18) {
106
+ return getScoreReference(getTable('bfaMale5Above'), 'Month', olderChildMonth);
99
107
  }
100
108
  return null;
101
109
  }
@@ -108,6 +116,9 @@ function getAge(birthdate, refDate, ageIn) {
108
116
  if (birthdate && refDate && ageIn) {
109
117
  const todayMoment = dayjs(refDate);
110
118
  const birthDateMoment = dayjs(birthdate);
119
+ if (!todayMoment.isValid() || !birthDateMoment.isValid()) {
120
+ return null;
121
+ }
111
122
  return todayMoment.diff(birthDateMoment, ageIn);
112
123
  }
113
124
  return null;