Skip to content

Commit

Permalink
Add Patient Names, Demographics & Address to dynamic reports (#35)
Browse files Browse the repository at this point in the history
* Handle other error codes while sending to DHIS2

* Add patient names & demographics to indicators

* Fix linting

* Add date of death
  • Loading branch information
akileng56 authored Aug 14, 2024
1 parent 44fb529 commit 374b5b8
Show file tree
Hide file tree
Showing 2 changed files with 234 additions and 26 deletions.
171 changes: 171 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,24 @@ export const reportIndicators: Array<Indicator> = [
type: "PatientIdentifier",
attributes: [],
},
{
id: "PEN",
label: "Person Names",
type: "PersonName",
attributes: [],
},
{
id: "DEM",
label: "Demographics",
type: "Demographics",
attributes: [],
},
{
id: "ADD",
label: "Address",
type: "Address",
attributes: [],
},
{
id: "PAT",
label: "Person Attributes",
Expand Down Expand Up @@ -483,3 +501,156 @@ export const modifiers = [
label: "Provider",
},
];

export const personNames = [
{
id: "givenName",
label: "Given Name",
type: "PersonName",
modifier: 1,
showModifierPanel: false,
extras: [],
attributes: [],
},
{
id: "middleName",
label: "Middle Name",
type: "PersonName",
modifier: 1,
showModifierPanel: false,
extras: [],
attributes: [],
},
{
id: "familyName",
label: "Family Name",
type: "PersonName",
modifier: 1,
showModifierPanel: false,
extras: [],
attributes: [],
},
{
id: "familyName2",
label: "Family Name 2",
type: "PersonName",
modifier: 1,
showModifierPanel: false,
extras: [],
attributes: [],
},
];

export const Demographics = [
{
id: "gender",
label: "Gender",
type: "Demographics",
modifier: 1,
showModifierPanel: false,
extras: [],
attributes: [],
},
{
id: "birthdate",
label: "Birthdate",
type: "Demographics",
modifier: 1,
showModifierPanel: false,
extras: [],
attributes: [],
},
{
id: "Age",
label: "Age",
type: "Demographics",
modifier: 1,
showModifierPanel: false,
extras: [],
attributes: [],
},
{
id: "birthdateEstimated",
label: "Birth Date estimated",
type: "Demographics",
modifier: 1,
showModifierPanel: false,
extras: [],
attributes: [],
},
{
id: "dead",
label: "Deceased",
type: "Demographics",
modifier: 1,
showModifierPanel: false,
extras: [],
attributes: [],
},
{
id: "deathDate",
label: "Date of death",
type: "Demographics",
modifier: 1,
showModifierPanel: false,
extras: [],
attributes: [],
},
];

export const Address = [
{
id: "country",
label: "Country",
type: "Address",
modifier: 1,
showModifierPanel: false,
extras: [],
attributes: [],
},
{
id: "countyDistrict",
label: "District",
type: "Address",
modifier: 1,
showModifierPanel: false,
extras: [],
attributes: [],
},
{
id: "stateProvince",
label: "County",
type: "Address",
modifier: 1,
showModifierPanel: false,
extras: [],
attributes: [],
},
{
id: "address3",
label: "Sub County",
type: "Address",
modifier: 1,
showModifierPanel: false,
extras: [],
attributes: [],
},
{
id: "address4",
label: "Parish",
type: "Address",
modifier: 1,
showModifierPanel: false,
extras: [],
attributes: [],
},
{
id: "address5",
label: "Village",
type: "Address",
modifier: 1,
showModifierPanel: false,
extras: [],
attributes: [],
},
];
89 changes: 63 additions & 26 deletions src/data-visualizer/data-visualizer.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ import {
reportTypes,
reportPeriod,
dynamicReportOptions,
personNames,
Address,
Demographics,
} from "../constants";
import DataList from "../components/data-table/data-table.component";
import CQIDataList from "../components/cqi-components/cqi-data-table.component";
Expand Down Expand Up @@ -217,6 +220,14 @@ const DataVisualizer: React.FC = () => {
description: `Report ${selectedReport.label} sent Successfully`,
});
}
{
showNotification({
title: "Error sending report to DHIS2",
kind: "error",
critical: true,
description: `Failed with error code ${response.status}, Contact System Administrator`,
});
}
setIsSendingReport(false);
},
(error) => {
Expand Down Expand Up @@ -352,30 +363,52 @@ const DataVisualizer: React.FC = () => {
setAvailableParameters([]);
};

const handleIndicatorChange = useCallback(({ selectedItem }) => {
const indicator = selectedItem;
getCategoryIndicator(selectedItem.id).then(
(response) => {
let results;
if (selectedItem.type === "") {
results = mapDataElements(response, null, "concepts");
} else {
results = mapDataElements(response?.results, selectedItem.type);
const handleIndicatorChange = useCallback(
({ selectedItem }) => {
const indicator = selectedItem;
getCategoryIndicator(selectedItem.id).then(
(response) => {
let results;
switch (selectedItem.type) {
case "PersonName":
results = personNames;
break;
case "Demographics":
results = Demographics;
break;
case "Address":
results = Address;
break;
case "":
results = mapDataElements(response, null, "concepts");
break;
default:
results = mapDataElements(response?.results, selectedItem.type);
break;
}

setSelectedIndicators(indicator);
const filteredArray = results?.filter(
(resultParameter) =>
!selectedParameters?.some(
(parameter) => parameter.id === resultParameter.id
)
);
indicator.attributes = filteredArray;
setAvailableParameters(indicator.attributes ?? []);
},
(error) => {
showNotification({
title: "Error fetching Indicators",
kind: "error",
critical: true,
description: error?.message,
});
}
indicator.attributes = results;
setSelectedIndicators(indicator);
setAvailableParameters(indicator.attributes ?? []);
},
(error) => {
showNotification({
title: "Error fetching Indicators",
kind: "error",
critical: true,
description: error?.message,
});
}
);
}, []);
);
},
[selectedParameters]
);

const handleSelectedReportDefinition = ({ selectedItem }) => {
setSelectedReport(selectedItem);
Expand Down Expand Up @@ -875,9 +908,13 @@ const DataVisualizer: React.FC = () => {
/>
</div>
{parameter.label}
{parameter?.type !==
"PatientIdentifier" &&
parameter?.type !== "PersonAttribute" ? (
{![
"PatientIdentifier",
"PersonAttribute",
"PersonName",
"Demographics",
"Address",
].includes(parameter?.type) ? (
<div
className={styles.modifierContainer}
>
Expand Down

0 comments on commit 374b5b8

Please sign in to comment.