@kenyaemr/esm-billing-app 5.4.7 → 5.4.8-pre.1663
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 +1 -1
- package/dist/1072.js +1 -1
- package/dist/1072.js.map +1 -1
- package/dist/2231.js +1 -1
- package/dist/2231.js.map +1 -1
- package/dist/2624.js +1 -1
- package/dist/2624.js.map +1 -1
- package/dist/2836.js +1 -0
- package/dist/2836.js.map +1 -0
- package/dist/301.js +1 -1
- package/dist/301.js.map +1 -1
- package/dist/3091.js +1 -1
- package/dist/3091.js.map +1 -1
- package/dist/3291.js +1 -0
- package/dist/3291.js.map +1 -0
- package/dist/3294.js +1 -1
- package/dist/3294.js.map +1 -1
- package/dist/3378.js +1 -1
- package/dist/3378.js.map +1 -1
- package/dist/3846.js +1 -0
- package/dist/3846.js.map +1 -0
- package/dist/4164.js +1 -0
- package/dist/4164.js.map +1 -0
- package/dist/5117.js +1 -1
- package/dist/5117.js.map +1 -1
- package/dist/5305.js +1 -0
- package/dist/5305.js.map +1 -0
- package/dist/5857.js +1 -0
- package/dist/5857.js.map +1 -0
- package/dist/6229.js +1 -0
- package/dist/6229.js.map +1 -0
- package/dist/6484.js +1 -0
- package/dist/6484.js.map +1 -0
- package/dist/6508.js +1 -1
- package/dist/6508.js.map +1 -1
- package/dist/6605.js +1 -1
- package/dist/6605.js.map +1 -1
- package/dist/7515.js +1 -1
- package/dist/7515.js.map +1 -1
- package/dist/8575.js +1 -0
- package/dist/8575.js.map +1 -0
- package/dist/9326.js +1 -1
- package/dist/9326.js.map +1 -1
- package/dist/9449.js +1 -1
- package/dist/9806.js +1 -1
- package/dist/9806.js.map +1 -1
- package/dist/9914.js +1 -0
- package/dist/9914.js.map +1 -0
- package/dist/kenyaemr-esm-billing-app.js +2 -2
- package/dist/kenyaemr-esm-billing-app.js.buildmanifest.json +278 -200
- package/dist/kenyaemr-esm-billing-app.js.map +1 -1
- package/dist/main.js +2 -2
- package/dist/main.js.map +1 -1
- package/dist/routes.json +1 -1
- package/package.json +3 -2
- package/src/billing-form/social-health-authority/type/index.ts +1 -0
- package/src/billing-tabs/billling-tabs.component.tsx +8 -1
- package/src/claims/claims-management/table/virtual-claim-preauth/utils/index.ts +3 -0
- package/src/claims/claims-wrap/claim-workspaces/attachements/claim-attachments-resource.ts +5 -2
- package/src/claims/claims-wrap/claim-workspaces/claim-submission/ClaimSubmitWorkspace.tsx +50 -12
- package/src/claims/claims-wrap/claim-workspaces/interventions/manage-interventions-workspace.tsx +1 -1
- package/src/claims/claims-wrap/claims-main-component.tsx +163 -33
- package/src/claims/claims-wrap/claims-main.resource.ts +12 -0
- package/src/claims/claims-wrap/claims-main.scss +16 -0
- package/src/claims/claims-wrap/type/index.ts +3 -0
- package/src/claims/overseas-referrals/overseas-referral-details.scss +13 -0
- package/src/claims/overseas-referrals/overseas-referral-details.workspace.tsx +85 -0
- package/src/claims/overseas-referrals/overseas-referral-form.scss +107 -0
- package/src/claims/overseas-referrals/overseas-referral-form.workspace.tsx +840 -0
- package/src/claims/overseas-referrals/overseas-referrals.component.tsx +336 -0
- package/src/claims/overseas-referrals/overseas-referrals.resource.test.ts +164 -0
- package/src/claims/overseas-referrals/overseas-referrals.resource.tsx +367 -0
- package/src/claims/overseas-referrals/overseas-referrals.scss +78 -0
- package/src/claims/overseas-referrals/overseas-referrals.utils.ts +31 -0
- package/src/claims/overseas-referrals/pending-referrals.component.tsx +337 -0
- package/src/claims/overseas-referrals/pending-referrals.test.tsx +157 -0
- package/src/claims/overseas-referrals/simple-table.component.tsx +83 -0
- package/src/index.ts +10 -0
- package/src/routes.json +10 -0
- package/src/visits/visits.resource.ts +15 -5
- package/translations/am.json +75 -0
- package/translations/en.json +78 -1
- package/translations/fr.json +75 -0
- package/translations/sw.json +75 -0
- package/dist/1187.js +0 -1
- package/dist/1187.js.map +0 -1
- package/dist/1346.js +0 -1
- package/dist/1346.js.map +0 -1
- package/dist/2034.js +0 -1
- package/dist/2034.js.map +0 -1
- package/dist/4156.js +0 -1
- package/dist/4156.js.map +0 -1
- package/dist/4266.js +0 -1
- package/dist/4266.js.map +0 -1
- package/dist/4818.js +0 -1
- package/dist/4818.js.map +0 -1
- package/dist/8332.js +0 -1
- package/dist/8332.js.map +0 -1
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
|
2
|
+
import { useTranslation } from 'react-i18next';
|
|
3
|
+
import dayjs from 'dayjs';
|
|
4
|
+
import {
|
|
5
|
+
Button,
|
|
6
|
+
DatePicker,
|
|
7
|
+
DatePickerInput,
|
|
8
|
+
InlineNotification,
|
|
9
|
+
Pagination,
|
|
10
|
+
Tab,
|
|
11
|
+
TabList,
|
|
12
|
+
TabPanel,
|
|
13
|
+
TabPanels,
|
|
14
|
+
Tabs,
|
|
15
|
+
Tag,
|
|
16
|
+
} from '@carbon/react';
|
|
17
|
+
import { Renew } from '@carbon/react/icons';
|
|
18
|
+
import { formatDate, useLayoutType } from '@openmrs/esm-framework';
|
|
19
|
+
import { shaErrorSubtitle } from '../../helpers/sha-error';
|
|
20
|
+
import { toTitleCase } from '../../utils';
|
|
21
|
+
import {
|
|
22
|
+
OVERSEAS_REFERRAL_STAGES,
|
|
23
|
+
type OverseasReferral,
|
|
24
|
+
type OverseasReferralStage,
|
|
25
|
+
useAllOverseasReferrals,
|
|
26
|
+
useOverseasReferralStageCounts,
|
|
27
|
+
usePendingOverseasReferrals,
|
|
28
|
+
} from './overseas-referrals.resource';
|
|
29
|
+
import PendingReferrals from './pending-referrals.component';
|
|
30
|
+
import SimpleTable from './simple-table.component';
|
|
31
|
+
import styles from './overseas-referrals.scss';
|
|
32
|
+
|
|
33
|
+
const PAGE_SIZES = [20, 50, 100];
|
|
34
|
+
const EMPTY = '—';
|
|
35
|
+
const DATE_PARAM_FORMAT = 'YYYY-MM-DD';
|
|
36
|
+
|
|
37
|
+
/** The URL query keys the filters are kept in, prefixed so they don't clash with the other billing tabs. */
|
|
38
|
+
const QUERY = {
|
|
39
|
+
stages: 'overseasStage',
|
|
40
|
+
includeSubmitted: 'overseasShowSubmitted',
|
|
41
|
+
fromDate: 'overseasFrom',
|
|
42
|
+
toDate: 'overseasTo',
|
|
43
|
+
} as const;
|
|
44
|
+
|
|
45
|
+
const formatMaybeDate = (value?: string) => {
|
|
46
|
+
const date = value ? new Date(value) : undefined;
|
|
47
|
+
return date && !Number.isNaN(date.getTime()) ? formatDate(date) : EMPTY;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const parseDateParam = (value: string | null) => {
|
|
51
|
+
const date = value ? dayjs(value, DATE_PARAM_FORMAT) : null;
|
|
52
|
+
return date?.isValid() ? date.toDate() : null;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
/** The one place the list reads a referral's fields; adjust here once the real response shape is confirmed. */
|
|
56
|
+
const toOverseasReferralRow = (referral: OverseasReferral) => ({
|
|
57
|
+
id: referral.guid,
|
|
58
|
+
dateCreated: formatMaybeDate(referral.date_created),
|
|
59
|
+
referralNumber: referral.referral_number ?? EMPTY,
|
|
60
|
+
beneficiary: referral.beneficiary_name ? toTitleCase(referral.beneficiary_name) : referral.beneficiary_id ?? EMPTY,
|
|
61
|
+
intervention: referral.intervention_name ?? referral.intervention_code ?? EMPTY,
|
|
62
|
+
destination: [referral.destination_facility, referral.destination_country].filter(Boolean).join(', ') || EMPTY,
|
|
63
|
+
status: referral.status ? <Tag type="gray">{toTitleCase(referral.status)}</Tag> : EMPTY,
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
/** Whether a referral was created within the range, by whole days; a referral without a date shows only unfiltered. */
|
|
67
|
+
const isWithinDates = (referral: OverseasReferral, fromDate: Date | null, toDate: Date | null) => {
|
|
68
|
+
if (!fromDate && !toDate) {
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
const created = referral.date_created ? dayjs(referral.date_created) : null;
|
|
72
|
+
if (!created?.isValid()) {
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
if (fromDate && created.isBefore(dayjs(fromDate).startOf('day'))) {
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
if (toDate && created.isAfter(dayjs(toDate).endOf('day'))) {
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
return true;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* The page's URL query, kept in sync with the address bar. This reads and replaces `window.location` directly
|
|
86
|
+
* rather than through react-router: the tab can render outside a `<Router>`, where `useSearchParams` throws.
|
|
87
|
+
*/
|
|
88
|
+
const useUrlSearchParams = () => {
|
|
89
|
+
const [searchParams, setParams] = useState(() => new URLSearchParams(window.location.search));
|
|
90
|
+
|
|
91
|
+
useEffect(() => {
|
|
92
|
+
// Back/forward, or another app changing the URL, should show here too.
|
|
93
|
+
const sync = () => setParams(new URLSearchParams(window.location.search));
|
|
94
|
+
window.addEventListener('popstate', sync);
|
|
95
|
+
return () => window.removeEventListener('popstate', sync);
|
|
96
|
+
}, []);
|
|
97
|
+
|
|
98
|
+
const setSearchParams = useCallback((change: (current: URLSearchParams) => URLSearchParams) => {
|
|
99
|
+
const next = change(new URLSearchParams(window.location.search));
|
|
100
|
+
const query = next.toString();
|
|
101
|
+
// Replace, not push: changing a filter shouldn't add a history entry.
|
|
102
|
+
window.history.replaceState(
|
|
103
|
+
window.history.state,
|
|
104
|
+
'',
|
|
105
|
+
`${window.location.pathname}${query ? `?${query}` : ''}${window.location.hash}`,
|
|
106
|
+
);
|
|
107
|
+
setParams(next);
|
|
108
|
+
}, []);
|
|
109
|
+
|
|
110
|
+
return [searchParams, setSearchParams] as const;
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
/** The Pending filters and the shared date range, read from and written to the URL query. */
|
|
114
|
+
const useOverseasReferralFilters = () => {
|
|
115
|
+
const [searchParams, setSearchParams] = useUrlSearchParams();
|
|
116
|
+
|
|
117
|
+
const filters = useMemo(() => {
|
|
118
|
+
const stages = (searchParams.get(QUERY.stages) ?? '')
|
|
119
|
+
.split(',')
|
|
120
|
+
.filter((stage): stage is OverseasReferralStage =>
|
|
121
|
+
(OVERSEAS_REFERRAL_STAGES as ReadonlyArray<string>).includes(stage),
|
|
122
|
+
);
|
|
123
|
+
return {
|
|
124
|
+
stages,
|
|
125
|
+
includeSubmitted: searchParams.get(QUERY.includeSubmitted) === 'true',
|
|
126
|
+
fromDate: parseDateParam(searchParams.get(QUERY.fromDate)),
|
|
127
|
+
toDate: parseDateParam(searchParams.get(QUERY.toDate)),
|
|
128
|
+
};
|
|
129
|
+
}, [searchParams]);
|
|
130
|
+
|
|
131
|
+
const update = (changes: Partial<Record<keyof typeof QUERY, string | null>>) =>
|
|
132
|
+
setSearchParams((current) => {
|
|
133
|
+
Object.entries(changes).forEach(([key, value]) => {
|
|
134
|
+
const param = QUERY[key as keyof typeof QUERY];
|
|
135
|
+
if (value) {
|
|
136
|
+
current.set(param, value);
|
|
137
|
+
} else {
|
|
138
|
+
current.delete(param);
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
return current;
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
return {
|
|
145
|
+
filters,
|
|
146
|
+
setStages: (stages: Array<OverseasReferralStage>) => update({ stages: stages.join(',') || null }),
|
|
147
|
+
setIncludeSubmitted: (includeSubmitted: boolean) => update({ includeSubmitted: includeSubmitted ? 'true' : null }),
|
|
148
|
+
setDates: (fromDate: Date | null, toDate: Date | null) =>
|
|
149
|
+
update({
|
|
150
|
+
fromDate: fromDate ? dayjs(fromDate).format(DATE_PARAM_FORMAT) : null,
|
|
151
|
+
toDate: toDate ? dayjs(toDate).format(DATE_PARAM_FORMAT) : null,
|
|
152
|
+
}),
|
|
153
|
+
};
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
interface SubmittedReferralsTableProps {
|
|
157
|
+
referrals: Array<OverseasReferral>;
|
|
158
|
+
isLoading: boolean;
|
|
159
|
+
hasError: boolean;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/** The referrals on SHA, paged in the browser. */
|
|
163
|
+
const SubmittedReferralsTable: React.FC<SubmittedReferralsTableProps> = ({ referrals, isLoading, hasError }) => {
|
|
164
|
+
const { t } = useTranslation();
|
|
165
|
+
const layout = useLayoutType();
|
|
166
|
+
const [page, setPage] = useState(1);
|
|
167
|
+
const [pageSize, setPageSize] = useState(PAGE_SIZES[0]);
|
|
168
|
+
|
|
169
|
+
// A narrower filter can leave the current page past the end; show the last page instead.
|
|
170
|
+
const lastPage = Math.max(1, Math.ceil(referrals.length / pageSize));
|
|
171
|
+
const currentPage = Math.min(page, lastPage);
|
|
172
|
+
const rows = referrals.slice((currentPage - 1) * pageSize, currentPage * pageSize).map(toOverseasReferralRow);
|
|
173
|
+
|
|
174
|
+
const headers = [
|
|
175
|
+
{ key: 'dateCreated', header: t('dateCreated', 'Date Created') },
|
|
176
|
+
{ key: 'referralNumber', header: t('referralNumber', 'Referral No.') },
|
|
177
|
+
{ key: 'beneficiary', header: t('beneficiary', 'Beneficiary') },
|
|
178
|
+
{ key: 'intervention', header: t('intervention', 'Intervention') },
|
|
179
|
+
{ key: 'destination', header: t('destination', 'Destination') },
|
|
180
|
+
{ key: 'status', header: t('status', 'Status') },
|
|
181
|
+
];
|
|
182
|
+
|
|
183
|
+
return (
|
|
184
|
+
<>
|
|
185
|
+
<SimpleTable
|
|
186
|
+
headers={headers}
|
|
187
|
+
rows={rows}
|
|
188
|
+
isLoading={isLoading}
|
|
189
|
+
rowCount={pageSize}
|
|
190
|
+
emptyMessage={hasError ? undefined : t('noSubmittedOverseasReferrals', 'No submitted overseas referrals')}
|
|
191
|
+
ariaLabel={t('submittedOverseasReferrals', 'Submitted overseas referrals')}
|
|
192
|
+
/>
|
|
193
|
+
<Pagination
|
|
194
|
+
page={currentPage}
|
|
195
|
+
pageSize={pageSize}
|
|
196
|
+
pageSizes={PAGE_SIZES}
|
|
197
|
+
totalItems={referrals.length}
|
|
198
|
+
onChange={({ page: newPage, pageSize: newPageSize }) => {
|
|
199
|
+
if (newPageSize !== pageSize) {
|
|
200
|
+
setPageSize(newPageSize);
|
|
201
|
+
setPage(1);
|
|
202
|
+
} else {
|
|
203
|
+
setPage(newPage);
|
|
204
|
+
}
|
|
205
|
+
}}
|
|
206
|
+
size={layout === 'tablet' ? 'lg' : 'sm'}
|
|
207
|
+
/>
|
|
208
|
+
</>
|
|
209
|
+
);
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
const OverseasReferrals: React.FC = () => {
|
|
213
|
+
const { t } = useTranslation();
|
|
214
|
+
const { filters, setStages, setIncludeSubmitted, setDates } = useOverseasReferralFilters();
|
|
215
|
+
const { fromDate, toDate } = filters;
|
|
216
|
+
const [pendingPage, setPendingPage] = useState(1);
|
|
217
|
+
const [pendingPageSize, setPendingPageSize] = useState(PAGE_SIZES[0]);
|
|
218
|
+
|
|
219
|
+
const referrals = useAllOverseasReferrals();
|
|
220
|
+
// The same request the Pending tab makes, so SWR shares it; used here only for the tab's count and refresh.
|
|
221
|
+
const pending = usePendingOverseasReferrals({ ...filters, page: pendingPage, pageSize: pendingPageSize });
|
|
222
|
+
const stageCounts = useOverseasReferralStageCounts();
|
|
223
|
+
|
|
224
|
+
// Changing any filter is a different list, so it starts from the first page.
|
|
225
|
+
const withFirstPage =
|
|
226
|
+
<T extends Array<unknown>>(change: (...args: T) => void) =>
|
|
227
|
+
(...args: T) => {
|
|
228
|
+
change(...args);
|
|
229
|
+
setPendingPage(1);
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
const submitted = useMemo(
|
|
233
|
+
() => referrals.referrals.filter((referral) => isWithinDates(referral, fromDate, toDate)),
|
|
234
|
+
[referrals.referrals, fromDate, toDate],
|
|
235
|
+
);
|
|
236
|
+
const isRefreshing = referrals.isValidating || pending.isValidating;
|
|
237
|
+
|
|
238
|
+
const refresh = () => {
|
|
239
|
+
referrals.mutate();
|
|
240
|
+
pending.mutate();
|
|
241
|
+
stageCounts.mutate();
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
return (
|
|
245
|
+
<div className={styles.container}>
|
|
246
|
+
<Tabs>
|
|
247
|
+
<div className={styles.tabsRow}>
|
|
248
|
+
<TabList aria-label={t('overseasReferralTabs', 'Overseas referral tabs')} contained activation="automatic">
|
|
249
|
+
<Tab>
|
|
250
|
+
{t('pending', 'Pending')}
|
|
251
|
+
{pending.total > 0 && (
|
|
252
|
+
<Tag type="warm-gray" size="sm" className={styles.tagCount}>
|
|
253
|
+
{pending.total}
|
|
254
|
+
</Tag>
|
|
255
|
+
)}
|
|
256
|
+
</Tab>
|
|
257
|
+
<Tab>
|
|
258
|
+
{t('submitted', 'Submitted')}
|
|
259
|
+
{submitted.length > 0 && (
|
|
260
|
+
<Tag type="green" size="sm" className={styles.tagCount}>
|
|
261
|
+
{submitted.length}
|
|
262
|
+
</Tag>
|
|
263
|
+
)}
|
|
264
|
+
</Tab>
|
|
265
|
+
</TabList>
|
|
266
|
+
|
|
267
|
+
<div className={styles.toolbar}>
|
|
268
|
+
<DatePicker
|
|
269
|
+
datePickerType="range"
|
|
270
|
+
dateFormat="d/m/Y"
|
|
271
|
+
value={[fromDate, toDate].filter(Boolean) as Array<Date>}
|
|
272
|
+
onChange={(dates) => withFirstPage(setDates)(dates[0] ?? null, dates[1] ?? null)}>
|
|
273
|
+
<DatePickerInput
|
|
274
|
+
id="overseas-referrals-date-from"
|
|
275
|
+
placeholder="dd/mm/yyyy"
|
|
276
|
+
labelText={t('fromDate', 'From')}
|
|
277
|
+
hideLabel
|
|
278
|
+
size="sm"
|
|
279
|
+
/>
|
|
280
|
+
<DatePickerInput
|
|
281
|
+
id="overseas-referrals-date-to"
|
|
282
|
+
placeholder="dd/mm/yyyy"
|
|
283
|
+
labelText={t('toDate', 'To')}
|
|
284
|
+
hideLabel
|
|
285
|
+
size="sm"
|
|
286
|
+
/>
|
|
287
|
+
</DatePicker>
|
|
288
|
+
{(fromDate || toDate) && (
|
|
289
|
+
<Button kind="ghost" size="sm" onClick={() => withFirstPage(setDates)(null, null)}>
|
|
290
|
+
{t('clearDates', 'Clear dates')}
|
|
291
|
+
</Button>
|
|
292
|
+
)}
|
|
293
|
+
<Button kind="tertiary" size="sm" renderIcon={Renew} disabled={isRefreshing} onClick={refresh}>
|
|
294
|
+
{isRefreshing ? t('refreshing', 'Refreshing…') : t('refresh', 'Refresh')}
|
|
295
|
+
</Button>
|
|
296
|
+
</div>
|
|
297
|
+
</div>
|
|
298
|
+
|
|
299
|
+
<TabPanels>
|
|
300
|
+
<TabPanel className={styles.tabPanel}>
|
|
301
|
+
<PendingReferrals
|
|
302
|
+
filters={filters}
|
|
303
|
+
onStagesChange={withFirstPage(setStages)}
|
|
304
|
+
onIncludeSubmittedChange={withFirstPage(setIncludeSubmitted)}
|
|
305
|
+
page={pendingPage}
|
|
306
|
+
pageSize={pendingPageSize}
|
|
307
|
+
onPageChange={(page, pageSize) => {
|
|
308
|
+
setPendingPage(page);
|
|
309
|
+
setPendingPageSize(pageSize);
|
|
310
|
+
}}
|
|
311
|
+
onReferralSubmitted={() => referrals.mutate()}
|
|
312
|
+
/>
|
|
313
|
+
</TabPanel>
|
|
314
|
+
<TabPanel className={styles.tabPanel}>
|
|
315
|
+
{referrals.error && (
|
|
316
|
+
<InlineNotification
|
|
317
|
+
kind="error"
|
|
318
|
+
lowContrast
|
|
319
|
+
hideCloseButton
|
|
320
|
+
title={t('errorLoadingOverseasReferrals', 'Error loading overseas referrals')}
|
|
321
|
+
subtitle={shaErrorSubtitle(referrals.error, t)}
|
|
322
|
+
/>
|
|
323
|
+
)}
|
|
324
|
+
<SubmittedReferralsTable
|
|
325
|
+
referrals={submitted}
|
|
326
|
+
isLoading={referrals.isLoading}
|
|
327
|
+
hasError={Boolean(referrals.error)}
|
|
328
|
+
/>
|
|
329
|
+
</TabPanel>
|
|
330
|
+
</TabPanels>
|
|
331
|
+
</Tabs>
|
|
332
|
+
</div>
|
|
333
|
+
);
|
|
334
|
+
};
|
|
335
|
+
|
|
336
|
+
export default OverseasReferrals;
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
3
|
+
import { renderHook, waitFor } from '@testing-library/react';
|
|
4
|
+
import { SWRConfig } from 'swr';
|
|
5
|
+
import { openmrsFetch } from '@openmrs/esm-framework';
|
|
6
|
+
import {
|
|
7
|
+
buildOverseasReferralFormData,
|
|
8
|
+
buildPendingReferralsQuery,
|
|
9
|
+
type NewOverseasReferral,
|
|
10
|
+
parseObsDatetime,
|
|
11
|
+
usePendingOverseasReferrals,
|
|
12
|
+
} from './overseas-referrals.resource';
|
|
13
|
+
|
|
14
|
+
const referral = (overrides: Partial<NewOverseasReferral> = {}): NewOverseasReferral => ({
|
|
15
|
+
consent_token: 'QRK3HA2Y56',
|
|
16
|
+
intervention_code: 'SHA-07-001',
|
|
17
|
+
items: [],
|
|
18
|
+
peer_reviewers: [],
|
|
19
|
+
clinical_information: { diagnoses: [], planned_procedures: [] },
|
|
20
|
+
attachments: [],
|
|
21
|
+
...overrides,
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
const json = (form: FormData, name: string) => JSON.parse(form.get(name) as string);
|
|
25
|
+
|
|
26
|
+
describe('buildOverseasReferralFormData', () => {
|
|
27
|
+
it('sends the required fields and leaves out empty optional text', () => {
|
|
28
|
+
const form = buildOverseasReferralFormData(referral({ urgency: '', referral_reason: ' ' }));
|
|
29
|
+
|
|
30
|
+
expect(form.get('consent_token')).toBe('QRK3HA2Y56');
|
|
31
|
+
expect(form.get('intervention_code')).toBe('SHA-07-001');
|
|
32
|
+
expect(form.has('urgency')).toBe(false);
|
|
33
|
+
expect(form.has('referral_reason')).toBe(false);
|
|
34
|
+
expect(form.has('items')).toBe(false);
|
|
35
|
+
expect(form.has('referring_doctor')).toBe(false);
|
|
36
|
+
expect(form.has('caregiver')).toBe(false);
|
|
37
|
+
expect(form.has('attachments')).toBe(false);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('sends the structured fields as JSON strings, not nested form fields', () => {
|
|
41
|
+
const doctor = {
|
|
42
|
+
identification_number: 'A1234',
|
|
43
|
+
identification_type: 'registration_number' as const,
|
|
44
|
+
regulation_body: 'KMPDC',
|
|
45
|
+
};
|
|
46
|
+
const form = buildOverseasReferralFormData(
|
|
47
|
+
referral({
|
|
48
|
+
urgency: 'URGENT',
|
|
49
|
+
admission_type: 'INPATIENT',
|
|
50
|
+
service_start: '2026-12-01T08:00:00+03:00',
|
|
51
|
+
items: [{ description: 'Bone marrow transplant package', unit_price: '250000.00', quantity: '1' }],
|
|
52
|
+
referring_doctor: doctor,
|
|
53
|
+
clinical_information: {
|
|
54
|
+
diagnoses: [{ icd11_code: '2A60', description: 'Acute myeloid leukaemia' }],
|
|
55
|
+
planned_procedures: [{ procedure_code: 'HSCT', description: 'Stem cell transplant' }],
|
|
56
|
+
clinical_notes: 'Relapsed after induction.',
|
|
57
|
+
},
|
|
58
|
+
caregiver: { full_name: 'Jane Doe', relationship: 'SPOUSE', phone_number: '+254700000000' },
|
|
59
|
+
}),
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
expect(form.get('urgency')).toBe('URGENT');
|
|
63
|
+
expect(form.get('service_start')).toBe('2026-12-01T08:00:00+03:00');
|
|
64
|
+
expect(typeof form.get('items')).toBe('string');
|
|
65
|
+
expect(json(form, 'items')).toEqual([
|
|
66
|
+
{ description: 'Bone marrow transplant package', unit_price: '250000.00', quantity: '1' },
|
|
67
|
+
]);
|
|
68
|
+
expect(json(form, 'referring_doctor')).toEqual(doctor);
|
|
69
|
+
// Sent even when empty, as SHA's example does.
|
|
70
|
+
expect(form.get('peer_reviewers')).toBe('[]');
|
|
71
|
+
expect(json(form, 'clinical_information')).toMatchObject({
|
|
72
|
+
diagnoses: [{ icd11_code: '2A60' }],
|
|
73
|
+
planned_procedures: [{ procedure_code: 'HSCT' }],
|
|
74
|
+
});
|
|
75
|
+
expect(json(form, 'caregiver')).toEqual({
|
|
76
|
+
full_name: 'Jane Doe',
|
|
77
|
+
relationship: 'SPOUSE',
|
|
78
|
+
phone_number: '+254700000000',
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('appends each file under attachments_files in the order of the attachments metadata, without a file_field_name', () => {
|
|
83
|
+
const referralForm = new File(['a'], 'referral.pdf', { type: 'application/pdf' });
|
|
84
|
+
const report = new File(['b'], 'report.pdf', { type: 'application/pdf' });
|
|
85
|
+
const form = buildOverseasReferralFormData(
|
|
86
|
+
referral({
|
|
87
|
+
attachments: [
|
|
88
|
+
{ document_type: 'SHA_REFERRAL_FORM', document_title: 'SHA Referral Form', file: referralForm },
|
|
89
|
+
{ document_type: 'SPECIALIST_MEDICAL_REPORT', document_title: 'Specialist Medical Report', file: report },
|
|
90
|
+
],
|
|
91
|
+
}),
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
expect(json(form, 'attachments')).toEqual([
|
|
95
|
+
{ document_type: 'SHA_REFERRAL_FORM', document_title: 'SHA Referral Form' },
|
|
96
|
+
{ document_type: 'SPECIALIST_MEDICAL_REPORT', document_title: 'Specialist Medical Report' },
|
|
97
|
+
]);
|
|
98
|
+
expect(form.getAll('attachments_files').map((file) => (file as File).name)).toEqual(['referral.pdf', 'report.pdf']);
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
describe('parseObsDatetime', () => {
|
|
103
|
+
it('reads an offset written without a colon', () => {
|
|
104
|
+
expect(parseObsDatetime('2026-11-20T10:15:00+0300')?.toISOString()).toBe('2026-11-20T07:15:00.000Z');
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it('is null for a missing or unreadable date', () => {
|
|
108
|
+
expect(parseObsDatetime(null)).toBeNull();
|
|
109
|
+
expect(parseObsDatetime('not a date')).toBeNull();
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
describe('usePendingOverseasReferrals', () => {
|
|
114
|
+
const wrapper = ({ children }: { children: React.ReactNode }) =>
|
|
115
|
+
React.createElement(SWRConfig, { value: { provider: () => new Map(), dedupingInterval: 0 } }, children);
|
|
116
|
+
|
|
117
|
+
it('asks for one page by limit and offset, with the dates as yyyy-MM-dd, and returns its rows and total', async () => {
|
|
118
|
+
vi.mocked(openmrsFetch).mockResolvedValue({
|
|
119
|
+
data: { success: true, total: 3, limit: 20, offset: 20, results: [{ patient_uuid: 'p-1', obs_uuid: 'o-1' }] },
|
|
120
|
+
} as any);
|
|
121
|
+
|
|
122
|
+
const { result } = renderHook(
|
|
123
|
+
() =>
|
|
124
|
+
usePendingOverseasReferrals({
|
|
125
|
+
fromDate: new Date(2026, 10, 1),
|
|
126
|
+
toDate: new Date(2026, 10, 20),
|
|
127
|
+
page: 2,
|
|
128
|
+
pageSize: 20,
|
|
129
|
+
}),
|
|
130
|
+
{ wrapper },
|
|
131
|
+
);
|
|
132
|
+
|
|
133
|
+
await waitFor(() => expect(result.current.total).toBe(3));
|
|
134
|
+
const url = new URL(String(vi.mocked(openmrsFetch).mock.calls.at(-1)[0]), 'http://localhost');
|
|
135
|
+
expect(url.pathname).toMatch(/\/virtualclaims\/referrals\/overseas\/pending-referrals$/);
|
|
136
|
+
expect(Object.fromEntries(url.searchParams)).toEqual({
|
|
137
|
+
limit: '20',
|
|
138
|
+
offset: '20',
|
|
139
|
+
from_date: '2026-11-01',
|
|
140
|
+
to_date: '2026-11-20',
|
|
141
|
+
});
|
|
142
|
+
expect(result.current.pendingReferrals).toEqual([{ patient_uuid: 'p-1', obs_uuid: 'o-1' }]);
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
describe('buildPendingReferralsQuery', () => {
|
|
147
|
+
it('leaves stage and include_submitted out by default, so the backend hides submitted referrals', () => {
|
|
148
|
+
expect(Object.fromEntries(buildPendingReferralsQuery({}, 1, 50))).toEqual({ limit: '50', offset: '0' });
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it('sends the chosen stages comma-separated and include_submitted when asked', () => {
|
|
152
|
+
const params = buildPendingReferralsQuery(
|
|
153
|
+
{ stages: ['READY_FOR_REFERRAL', 'CLAIM_NOT_SUBMITTED'], includeSubmitted: true },
|
|
154
|
+
3,
|
|
155
|
+
20,
|
|
156
|
+
);
|
|
157
|
+
expect(Object.fromEntries(params)).toEqual({
|
|
158
|
+
limit: '20',
|
|
159
|
+
offset: '40',
|
|
160
|
+
stage: 'READY_FOR_REFERRAL,CLAIM_NOT_SUBMITTED',
|
|
161
|
+
include_submitted: 'true',
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
});
|