@sasindi/radiologytestscheduling 0.0.0-stage → 1.0.2
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/LICENSE +354 -0
- package/README.md +166 -2
- package/dist/117.js +1 -0
- package/dist/117.js.map +1 -0
- package/dist/197.js +1 -0
- package/dist/197.js.map +1 -0
- package/dist/206.css +1 -0
- package/dist/206.css.map +1 -0
- package/dist/206.js +39 -0
- package/dist/206.js.map +1 -0
- package/dist/237.js +1 -0
- package/dist/237.js.map +1 -0
- package/dist/29.js +1 -0
- package/dist/29.js.map +1 -0
- package/dist/362.js +1 -0
- package/dist/362.js.map +1 -0
- package/dist/410.js +1 -0
- package/dist/410.js.map +1 -0
- package/dist/480.js +1 -0
- package/dist/480.js.map +1 -0
- package/dist/517.js +1 -0
- package/dist/517.js.map +1 -0
- package/dist/538.js +1 -0
- package/dist/538.js.map +1 -0
- package/dist/540.css +1 -0
- package/dist/540.css.map +1 -0
- package/dist/559.js +1 -0
- package/dist/559.js.map +1 -0
- package/dist/570.js +60 -0
- package/dist/570.js.map +1 -0
- package/dist/578.js +1 -0
- package/dist/578.js.map +1 -0
- package/dist/647.js +1 -0
- package/dist/647.js.map +1 -0
- package/dist/652.js +1 -0
- package/dist/652.js.map +1 -0
- package/dist/668.js +1 -0
- package/dist/668.js.map +1 -0
- package/dist/749.js +1 -0
- package/dist/749.js.map +1 -0
- package/dist/809.js +22 -0
- package/dist/809.js.map +1 -0
- package/dist/813.js +1 -0
- package/dist/813.js.map +1 -0
- package/dist/898.js +1 -0
- package/dist/898.js.map +1 -0
- package/dist/974.css +1 -0
- package/dist/974.css.map +1 -0
- package/dist/974.js +1 -0
- package/dist/974.js.map +1 -0
- package/dist/976.js +1 -0
- package/dist/976.js.map +1 -0
- package/dist/977.js +1 -0
- package/dist/977.js.map +1 -0
- package/dist/98.js +1 -0
- package/dist/98.js.map +1 -0
- package/dist/openmrs-esm-radiologytestscheduling.js +3 -0
- package/dist/openmrs-esm-radiologytestscheduling.js.map +1 -0
- package/dist/routes.json +1 -0
- package/package.json +101 -4
- package/src/config-schema.ts +21 -0
- package/src/constants.ts +1 -0
- package/src/declarations.d.ts +23 -0
- package/src/index.ts +28 -0
- package/src/radiology-test-scheduling.component.tsx +711 -0
- package/src/radiology-test-scheduling.resource.ts +339 -0
- package/src/radiology-test-scheduling.scss +396 -0
- package/src/root.component.test.tsx +12 -0
- package/src/root.component.tsx +13 -0
- package/src/root.scss +5 -0
- package/src/routes.json +12 -0
- package/src/types.ts +100 -0
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
import { openmrsFetch, restBaseUrl } from '@openmrs/esm-framework';
|
|
2
|
+
import {
|
|
3
|
+
SchedulingOrderDTO,
|
|
4
|
+
PatientDemographics,
|
|
5
|
+
InstituteOption,
|
|
6
|
+
ExamRoom,
|
|
7
|
+
RadiologyOrder,
|
|
8
|
+
} from './types';
|
|
9
|
+
|
|
10
|
+
// In-memory cache for location and user displays to speed up table population
|
|
11
|
+
const locationCache = new Map<string, string>();
|
|
12
|
+
const userCache = new Map<string, string>();
|
|
13
|
+
const patientBasicCache = new Map<string, { name: string; gender: string; age: string | number }>();
|
|
14
|
+
|
|
15
|
+
export interface SessionInfo {
|
|
16
|
+
userUuid: string;
|
|
17
|
+
personUuid: string;
|
|
18
|
+
locationUuid: string;
|
|
19
|
+
locationName: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Resolves current user session, person attribute "Institute Id", and location name.
|
|
24
|
+
*/
|
|
25
|
+
export async function fetchCurrentSessionAndInstitute(): Promise<SessionInfo> {
|
|
26
|
+
const sessionRes = await openmrsFetch(`${restBaseUrl}/session`);
|
|
27
|
+
const sessionData = sessionRes.data;
|
|
28
|
+
const userUuid = sessionData?.user?.uuid || '';
|
|
29
|
+
const personUuid = sessionData?.user?.person?.uuid || '';
|
|
30
|
+
|
|
31
|
+
let resolvedLocationUuid = sessionData?.sessionLocation?.uuid || '';
|
|
32
|
+
let resolvedLocationName = sessionData?.sessionLocation?.display || '';
|
|
33
|
+
|
|
34
|
+
if (personUuid) {
|
|
35
|
+
try {
|
|
36
|
+
const personRes = await openmrsFetch(`${restBaseUrl}/person/${personUuid}`);
|
|
37
|
+
const attributes = personRes.data?.attributes || [];
|
|
38
|
+
for (const attr of attributes) {
|
|
39
|
+
const display: string = attr.display || '';
|
|
40
|
+
if (display.includes('=')) {
|
|
41
|
+
const [key, val] = display.split('=');
|
|
42
|
+
if (key.trim() === 'Institute Id' && val && val.trim()) {
|
|
43
|
+
resolvedLocationUuid = val.trim();
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
} catch (e) {
|
|
49
|
+
console.warn('Could not load person attributes', e);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (resolvedLocationUuid && (!resolvedLocationName || resolvedLocationUuid !== sessionData?.sessionLocation?.uuid)) {
|
|
54
|
+
try {
|
|
55
|
+
const locRes = await openmrsFetch(`${restBaseUrl}/location/${resolvedLocationUuid}`);
|
|
56
|
+
resolvedLocationName = locRes.data?.display || resolvedLocationName;
|
|
57
|
+
locationCache.set(resolvedLocationUuid, resolvedLocationName);
|
|
58
|
+
} catch (e) {
|
|
59
|
+
console.warn('Could not load location details', e);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return {
|
|
64
|
+
userUuid,
|
|
65
|
+
personUuid,
|
|
66
|
+
locationUuid: resolvedLocationUuid,
|
|
67
|
+
locationName: resolvedLocationName,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Fetch list of hospitals / institutes.
|
|
73
|
+
* Standard OpenMRS 3 query filtering for address14 === 'Hospital'.
|
|
74
|
+
*/
|
|
75
|
+
export async function fetchInstitutes(): Promise<InstituteOption[]> {
|
|
76
|
+
try {
|
|
77
|
+
const res = await openmrsFetch(`${restBaseUrl}/location?v=custom:(uuid,name,display,address14)&limit=100`);
|
|
78
|
+
const results = res.data?.results || [];
|
|
79
|
+
const hospitals = results.filter((loc: any) => loc.address14 === 'Hospital');
|
|
80
|
+
const sourceList = hospitals.length > 0 ? hospitals : results;
|
|
81
|
+
|
|
82
|
+
return sourceList.map((item: any) => ({
|
|
83
|
+
uuid: item.uuid,
|
|
84
|
+
name: (item.name || item.display || item.uuid).trim(),
|
|
85
|
+
}));
|
|
86
|
+
} catch (err) {
|
|
87
|
+
console.error('Failed to load locations', err);
|
|
88
|
+
return [];
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Fetch location display name with caching.
|
|
94
|
+
*/
|
|
95
|
+
export async function fetchLocationDisplay(locationUuid: string): Promise<string> {
|
|
96
|
+
if (!locationUuid) return '';
|
|
97
|
+
if (locationCache.has(locationUuid)) {
|
|
98
|
+
return locationCache.get(locationUuid)!;
|
|
99
|
+
}
|
|
100
|
+
try {
|
|
101
|
+
const res = await openmrsFetch(`${restBaseUrl}/location/${locationUuid}`);
|
|
102
|
+
const name = res.data?.display || locationUuid;
|
|
103
|
+
locationCache.set(locationUuid, name);
|
|
104
|
+
return name;
|
|
105
|
+
} catch {
|
|
106
|
+
return locationUuid;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Fetch user / clinician display name with caching.
|
|
112
|
+
*/
|
|
113
|
+
export async function fetchUserDisplay(userUuid: string): Promise<string> {
|
|
114
|
+
if (!userUuid) return '';
|
|
115
|
+
if (userCache.has(userUuid)) {
|
|
116
|
+
return userCache.get(userUuid)!;
|
|
117
|
+
}
|
|
118
|
+
try {
|
|
119
|
+
const res = await openmrsFetch(`${restBaseUrl}/user/${userUuid}`);
|
|
120
|
+
const name = res.data?.person?.display || res.data?.display || userUuid;
|
|
121
|
+
userCache.set(userUuid, name);
|
|
122
|
+
return name;
|
|
123
|
+
} catch {
|
|
124
|
+
return userUuid;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Fetch patient basic info (name, gender, age) for table display with caching.
|
|
130
|
+
*/
|
|
131
|
+
export async function fetchPatientBasicInfo(phn: string): Promise<{ name: string; gender: string; age: string | number }> {
|
|
132
|
+
if (!phn) return { name: '', gender: '', age: '' };
|
|
133
|
+
if (patientBasicCache.has(phn)) {
|
|
134
|
+
return patientBasicCache.get(phn)!;
|
|
135
|
+
}
|
|
136
|
+
try {
|
|
137
|
+
const phnRes = await openmrsFetch(`${restBaseUrl}/phn/${encodeURIComponent(phn)}`);
|
|
138
|
+
const person = phnRes.data?.person_id?.person;
|
|
139
|
+
if (person) {
|
|
140
|
+
const info = {
|
|
141
|
+
name: person.display || '',
|
|
142
|
+
gender: person.gender || '',
|
|
143
|
+
age: person.age !== undefined && person.age !== null ? person.age : '',
|
|
144
|
+
};
|
|
145
|
+
patientBasicCache.set(phn, info);
|
|
146
|
+
return info;
|
|
147
|
+
}
|
|
148
|
+
} catch (err) {
|
|
149
|
+
console.warn('Error fetching patient basic info for PHN', phn, err);
|
|
150
|
+
}
|
|
151
|
+
return { name: '', gender: '', age: '' };
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Fetch patient demographics & address by PHN.
|
|
156
|
+
*/
|
|
157
|
+
export async function fetchPatientDetails(phn: string): Promise<PatientDemographics> {
|
|
158
|
+
const result: PatientDemographics = {
|
|
159
|
+
fullName: '',
|
|
160
|
+
gender: '',
|
|
161
|
+
nicNo: '',
|
|
162
|
+
guardianInfo: '',
|
|
163
|
+
address: '',
|
|
164
|
+
years: '',
|
|
165
|
+
months: '',
|
|
166
|
+
days: '',
|
|
167
|
+
dateOfBirth: '',
|
|
168
|
+
profileImage: '',
|
|
169
|
+
telephoneHome: '',
|
|
170
|
+
telephoneMobile: '',
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
if (!phn) return result;
|
|
174
|
+
|
|
175
|
+
try {
|
|
176
|
+
const phnRes = await openmrsFetch(`${restBaseUrl}/phn/${encodeURIComponent(phn)}`);
|
|
177
|
+
const data = phnRes.data;
|
|
178
|
+
const person = data?.person_id?.person;
|
|
179
|
+
|
|
180
|
+
if (person) {
|
|
181
|
+
result.fullName = person.display || '';
|
|
182
|
+
result.gender = person.gender || '';
|
|
183
|
+
if (person.birthdate) {
|
|
184
|
+
result.dateOfBirth = person.birthdate.split('T')[0];
|
|
185
|
+
calculateAge(person.birthdate, result);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
const attributes = person.attributes || [];
|
|
189
|
+
for (const attr of attributes) {
|
|
190
|
+
const display: string = attr.display || '';
|
|
191
|
+
if (display.includes('=')) {
|
|
192
|
+
const [key, rawVal] = display.split('=');
|
|
193
|
+
const val = rawVal ? rawVal.trim() : '';
|
|
194
|
+
const k = key.trim();
|
|
195
|
+
|
|
196
|
+
if (k === 'NIC No') result.nicNo = val;
|
|
197
|
+
else if (k === 'Guardian Name') result.guardianInfo = val;
|
|
198
|
+
else if (k === 'ProfileImage') {
|
|
199
|
+
result.profileImage = val ? `${window.location.origin}/openmrs/owa/PatientImagesUploaded/${val}` : '';
|
|
200
|
+
} else if (k === 'Telephone Home') result.telephoneHome = val;
|
|
201
|
+
else if (k === 'Telephone Number') result.telephoneMobile = val;
|
|
202
|
+
else if (!result.dateOfBirth) {
|
|
203
|
+
if (k === 'Years') result.years = val;
|
|
204
|
+
if (k === 'Months') result.months = val;
|
|
205
|
+
if (k === 'Days') result.days = val;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// Fetch Address
|
|
211
|
+
if (person.uuid) {
|
|
212
|
+
try {
|
|
213
|
+
const addrRes = await openmrsFetch(`${restBaseUrl}/person/${person.uuid}/address`);
|
|
214
|
+
const addresses = addrRes.data?.results || [];
|
|
215
|
+
if (addresses.length > 0) {
|
|
216
|
+
const addr = addresses[0];
|
|
217
|
+
const parts = [addr.address1, addr.address2, addr.cityVillage].filter(Boolean).map((s: string) => s.trim());
|
|
218
|
+
result.address = parts.join(', ');
|
|
219
|
+
}
|
|
220
|
+
} catch (e) {
|
|
221
|
+
console.warn('Could not load address for person', person.uuid, e);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
} catch (err) {
|
|
226
|
+
console.error('Error fetching patient details by PHN', phn, err);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
return result;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
function calculateAge(birthdateStr: string, out: PatientDemographics) {
|
|
233
|
+
try {
|
|
234
|
+
const now = new Date();
|
|
235
|
+
const dob = new Date(birthdateStr);
|
|
236
|
+
let yearAge = now.getFullYear() - dob.getFullYear();
|
|
237
|
+
let monthAge = now.getMonth() - dob.getMonth();
|
|
238
|
+
let dateAge = now.getDate() - dob.getDate();
|
|
239
|
+
|
|
240
|
+
if (monthAge < 0 || (monthAge === 0 && dateAge < 0)) {
|
|
241
|
+
yearAge--;
|
|
242
|
+
monthAge = (monthAge + 12) % 12;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
if (dateAge < 0) {
|
|
246
|
+
const prevMonth = new Date(now.getFullYear(), now.getMonth(), 0);
|
|
247
|
+
dateAge += prevMonth.getDate();
|
|
248
|
+
monthAge--;
|
|
249
|
+
if (monthAge < 0) {
|
|
250
|
+
monthAge = 11;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
out.years = yearAge >= 0 ? yearAge : 0;
|
|
255
|
+
out.months = monthAge >= 0 ? monthAge : 0;
|
|
256
|
+
out.days = dateAge >= 0 ? dateAge : 0;
|
|
257
|
+
} catch {
|
|
258
|
+
// Keep existing
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* Fetch pending scheduling orders for an institute.
|
|
264
|
+
*/
|
|
265
|
+
export async function fetchPendingSchedulingOrders(instituteUuid: string): Promise<SchedulingOrderDTO[]> {
|
|
266
|
+
const target = instituteUuid && instituteUuid.trim() ? instituteUuid.trim() : 'all';
|
|
267
|
+
const res = await openmrsFetch(`${restBaseUrl}/radiologytestscheduling/loadradiologytestschedulingdata/${target}`);
|
|
268
|
+
const items: any[] = Array.isArray(res.data) ? res.data : [];
|
|
269
|
+
|
|
270
|
+
return items.map((item) => ({
|
|
271
|
+
radiology: item.radiology || item,
|
|
272
|
+
type: item.type || (item.radiology ? 'OPD' : 'OPD'),
|
|
273
|
+
}));
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Fetch Exam Rooms for Modality.
|
|
278
|
+
*/
|
|
279
|
+
export async function fetchExamRooms(modality: string): Promise<ExamRoom[]> {
|
|
280
|
+
if (!modality || modality === 'all') {
|
|
281
|
+
return [];
|
|
282
|
+
}
|
|
283
|
+
try {
|
|
284
|
+
const res = await openmrsFetch(`${restBaseUrl}/patientexamination/loadexamrooms/${encodeURIComponent(modality)}`);
|
|
285
|
+
const data = res.data || [];
|
|
286
|
+
if (Array.isArray(data)) {
|
|
287
|
+
return data.map((room: any) => ({
|
|
288
|
+
id: room.id,
|
|
289
|
+
name: room.name || room.display || room,
|
|
290
|
+
}));
|
|
291
|
+
}
|
|
292
|
+
} catch (e) {
|
|
293
|
+
console.warn('Could not load exam rooms for modality', modality, e);
|
|
294
|
+
}
|
|
295
|
+
return [];
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* Fetch calendar scheduled tests.
|
|
300
|
+
*/
|
|
301
|
+
export async function fetchCalendarData(
|
|
302
|
+
modality: string,
|
|
303
|
+
examRoom: string,
|
|
304
|
+
instituteUuid: string,
|
|
305
|
+
): Promise<RadiologyOrder[]> {
|
|
306
|
+
const mod = modality || 'all';
|
|
307
|
+
const room = examRoom || 'all';
|
|
308
|
+
const ins = instituteUuid || 'all';
|
|
309
|
+
|
|
310
|
+
const res = await openmrsFetch(
|
|
311
|
+
`${restBaseUrl}/radiologytestscheduling/loadcalender/${encodeURIComponent(mod)}/${encodeURIComponent(room)}/${encodeURIComponent(ins)}`,
|
|
312
|
+
);
|
|
313
|
+
return Array.isArray(res.data) ? res.data : [];
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* Save schedule datetime and remarks for an order.
|
|
318
|
+
*/
|
|
319
|
+
export async function saveScheduling(
|
|
320
|
+
type: 'OPD' | 'Clinic' | 'Ward',
|
|
321
|
+
payload: { id: number; scheduledDateTime: string; remarks: string; cby: string },
|
|
322
|
+
): Promise<any> {
|
|
323
|
+
let endpoint = `${restBaseUrl}/radiologytestscheduling/save`;
|
|
324
|
+
if (type === 'Clinic') {
|
|
325
|
+
endpoint = `${restBaseUrl}/radiologytestscheduling/saveclinic`;
|
|
326
|
+
} else if (type === 'Ward') {
|
|
327
|
+
endpoint = `${restBaseUrl}/radiologytestscheduling/saveward`;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
const res = await openmrsFetch(endpoint, {
|
|
331
|
+
method: 'POST',
|
|
332
|
+
headers: {
|
|
333
|
+
'Content-Type': 'application/json',
|
|
334
|
+
},
|
|
335
|
+
body: JSON.stringify(payload),
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
return res.data;
|
|
339
|
+
}
|