diff --git a/src/constants.ts b/src/constants.ts index 19dbc7f..bb75008 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -241,6 +241,24 @@ export const reportIndicators: Array = [ 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", @@ -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: [], + }, +]; diff --git a/src/data-visualizer/data-visualizer.component.tsx b/src/data-visualizer/data-visualizer.component.tsx index 6400d34..b7ce4ed 100644 --- a/src/data-visualizer/data-visualizer.component.tsx +++ b/src/data-visualizer/data-visualizer.component.tsx @@ -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"; @@ -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) => { @@ -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); @@ -875,9 +908,13 @@ const DataVisualizer: React.FC = () => { /> {parameter.label} - {parameter?.type !== - "PatientIdentifier" && - parameter?.type !== "PersonAttribute" ? ( + {![ + "PatientIdentifier", + "PersonAttribute", + "PersonName", + "Demographics", + "Address", + ].includes(parameter?.type) ? (