Skip to content

Commit

Permalink
Fetch Patients starting from the Latest registered, Spilt Patient nam…
Browse files Browse the repository at this point in the history
…es and Only get the first letter of the gender (M or F) .

Fetch Patients starting from the Latest registered, Spilt Patient names and Only get the first letter of the gender (M or F) .
  • Loading branch information
Michaelndula authored Apr 30, 2024
2 parents fb0f509 + 10dd416 commit d3c8b98
Showing 1 changed file with 41 additions and 22 deletions.
63 changes: 41 additions & 22 deletions packages/esm-patient-list-app/src/hooks/usePatientList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,52 @@ export function usePatientList() {

const filterData = ({ start = null, end = null }) => {
let filteredArray = data.entry;
if (start && end)
filteredArray = data.entry.filter(

if (start && end) {
filteredArray = filteredArray.filter(
(item) =>
new Date(item.resource.meta.lastUpdated) >= new Date(start) &&
new Date(item.resource.meta.lastUpdated) <= new Date(end)
);
}

filteredArray = filteredArray.map((item: any) => {
const givenName =
item?.resource?.name[0]?.given[0] +
(item?.resource?.name[0]?.given[1]
? " " + item.resource?.name[0]?.given[1]
: "");

const gender = item.resource.gender
? item.resource.gender.charAt(0).toUpperCase()
: "";

return {
fullName: givenName + " " + item.resource?.name[0]?.family,
age:
new Date().getFullYear() -
new Date(item.resource.birthDate).getFullYear(),
gender: gender,
openmrsID: item.resource?.identifier?.find(
(id) => id.type?.text === "OpenMRS ID"
)?.value,
opdNumber: item.resource?.identifier?.find(
(id) => id.type.text === "Unique OPD number"
)?.value,
dateRegistered: new Date(
item.resource?.meta?.lastUpdated
).toLocaleDateString(),
timeRegistered: new Date(
item.resource?.meta?.lastUpdated
).toLocaleTimeString(),
};
});

filteredArray = filteredArray.map((item: any) => ({
fullName:
item?.resource?.name[0]?.given[0] + item.resource?.name[0]?.family,
age:
new Date().getFullYear() -
new Date(item.resource.birthDate).getFullYear(),
gender: item.resource.gender?.toUpperCase(),
openmrsID: item.resource?.identifier?.find(
(id) => id.type?.text === "OpenMRS ID"
)?.value,
opdNumber: item.resource?.identifier?.find(
(id) => id.type.text === "Unique OPD number"
)?.value,
dateRegistered: new Date(
item.resource?.meta?.lastUpdated
).toLocaleDateString(),
timeRegistered: new Date(
item.resource?.meta?.lastUpdated
).toLocaleTimeString(),
}));
filteredArray.sort((a, b) => {
const dateA = new Date(a.dateRegistered + " " + a.timeRegistered);
const dateB = new Date(b.dateRegistered + " " + b.timeRegistered);
return (dateB as unknown as number) - (dateA as unknown as number);
});

setFilteredData(filteredArray);
};
Expand Down

0 comments on commit d3c8b98

Please sign in to comment.