Skip to content

Commit

Permalink
PMTCT - update metadata to use config instead of constants
Browse files Browse the repository at this point in the history
  • Loading branch information
lucyjemutai committed Jan 9, 2024
1 parent ebc4940 commit 5e2fd14
Show file tree
Hide file tree
Showing 11 changed files with 202 additions and 238 deletions.
10 changes: 5 additions & 5 deletions packages/esm-ohri-pmtct-app/src/api/api.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { openmrsFetch } from '@openmrs/esm-framework';
import { openmrsFetch, getConfig } from '@openmrs/esm-framework';
import { AncVisitsReport, Patient, PatientIdentifier, Relationship } from './types';
import { ancVisitsReport, eddReport, motherHivStatusReport } from '../constants';
import useSWR from 'swr';
import { fetchPatientRelationships } from '@ohri/openmrs-esm-ohri-commons-lib';

const BASE_WS_API_URL = '/ws/rest/v1/';
const config = await getConfig('@ohri/openmrs-esm-ohri-pmtct');

export function generateIdentifier(source: string) {
return openmrsFetch(`/ws/rest/v1/idgen/identifiersource/${source}/identifier`, {
Expand Down Expand Up @@ -43,7 +43,7 @@ export function saveRelationship(relationship: Relationship) {
// Get ANC visits report count with pTrackerID and patientUuid
export function getAncVisitCount(pTrackerID: string, patientUuid: string) {
return openmrsFetch(
`${BASE_WS_API_URL}reportingrest/dataSet/${ancVisitsReport}?ptracker_id=${pTrackerID}&patient_uuid=${patientUuid}`,
`${BASE_WS_API_URL}reportingrest/dataSet/${config.reports.ancVisitsReport}?ptracker_id=${pTrackerID}&patient_uuid=${patientUuid}`,
).then(({ data }) => {
if (data) {
return data;
Expand Down Expand Up @@ -73,7 +73,7 @@ export function saveIdentifier(identifier: PatientIdentifier, patientUuid: strin

export function getEstimatedDeliveryDate(patientUuid: string, pTrackerId: string) {
return openmrsFetch(
`${BASE_WS_API_URL}reportingrest/dataSet/${eddReport}?ptracker_id=${pTrackerId}&patient_uuid=${patientUuid}`,
`${BASE_WS_API_URL}reportingrest/dataSet/${config.reports.eddReport}?ptracker_id=${pTrackerId}&patient_uuid=${patientUuid}`,
).then(({ data }) => {
if (data) {
return data;
Expand All @@ -95,7 +95,7 @@ export function getIdentifierInfo(identifier: string) {

export function fetchMotherHIVStatus(patientUuid: string, pTrackerId: string) {
return openmrsFetch(
`${BASE_WS_API_URL}reportingrest/dataSet/${motherHivStatusReport}?person_uuid=${patientUuid}&ptracker_id=${pTrackerId}`,
`${BASE_WS_API_URL}reportingrest/dataSet/${config.reports.motherHivStatusReport}?person_uuid=${patientUuid}&ptracker_id=${pTrackerId}`,
).then(({ data }) => {
if (data) {
return data;
Expand Down
97 changes: 97 additions & 0 deletions packages/esm-ohri-pmtct-app/src/config-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,103 @@ export const configSchema = {
laborAndDelivery: '6dc5308d-27c9-4d49-b16f-2c5e3c759757',
infantPostnatal: 'af1f1b24-d2e8-4282-b308-0bf79b365584',
motherPostnatal: '269bcc7f-04f8-4ddc-883d-7a3a0d569aad',
mnchEncounterType_UUID: '3eb24129-9f7d-4372-a14e-c2cf577e5db1',
clientsEnrolledToCar: '51bec6f7-df43-426e-a83e-c1ae5501372f',
vLResultsConcept: '1305AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
PTrackerIdentifierType: '4da0a3fe-e546-463f-81fa-084f098ff06c',
artUniqueNumberType: '9d6d1eec-2cd6-4637-a981-4a46b4b8b41f',
pTrackerIdConcept: '6c45421e-2566-47cb-bbb3-07586fffbfe2',
},
},
labour: {
_type: Type.Object,
_description: 'Labour & Delivery Concept and uuid.',
_default: {
clientsEnrolledForTb: '98fd11ba-cb4d-46f7-9b82-40d49949c7ef',
labourAndDeliveryEncounterType: '2678423c-0523-4d76-b0da-18177b439eed',
infantStatusAtBirthConcept: '159917AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
dateOfDeliveryConcept: '5599AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
bookedForAncConcept: '1719AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
ancHivResultConcept: 'c5f74c86-62cd-4d22-9260-4238f1e45fe0',
hivStatusAtDeliveryConcept: 'c5f74c86-62cd-4d22-9260-4238f1e45fe0',
artInitiationConcept: '6e62bf7e-2107-4d09-b485-6e60cbbb2d08',
birthCountConcept: '1568AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
visitDate: '163260AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
hivTestStatus: '164401AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
artLinkage: '6e62bf7e-2107-4d09-b485-6e60cbbb2d08',
recenctViralLoad: '163310AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
motherStatusConcept: '1856AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
ancVisitConcept: '160446AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
infantDeliveryGroupingConcept: '1c70c490-cafa-4c95-9fdd-a30b62bb78b8',
infantPTrackerIdConcept: '164803AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
infantDateOfBirth: '164802AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
},
},
infantpnc: {
_type: Type.Object,
_description: 'Infant Postnatal encounterTypes and concepts uuid.',
_default: {
infantPostnatalEncounterType: 'af1f1b24-d2e8-4282-b308-0bf79b365584',
nextVisitDate: '5096AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
ChildPTrackerId: '6c45421e-2566-47cb-bbb3-07586fffbfe2',
childDateOfBirth: '163260AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
artProphylaxisStatus: '1148AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
linkedToArt: 'a40d8bc4-56b8-4f28-a1dd-412da5cf20ed',
breastfeedingStatus: '1151AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
outcomeStatus: '160433AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
infantVisitDate: '159599AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
finalTestResults: '164460AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
},
},
antenatal: {
_type: Type.Object,
_description: 'Antenatal encounterType and concepts uuid.',
_default: {
antenatalEncounterType: '2549af50-75c8-4aeb-87ca-4bb2cef6c69a',
visitDateConcept: '163260AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
hivTestResultConcept: '159427AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
artNoConcept: '164402AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
followUpDateConcept: '5096AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
eDDConcept: '5596AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
nextVisitDateConcept: '5096AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
artStartDate: '159599AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
ancVisitsConcept: '1425AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
testTypeConcept: 'ee8c0292-47f8-4c01-8b60-8ba13a560e1a',
infantExposureStatus: '6027869c-5d7e-4a82-b22f-6d9c57d61a4d',
},
},
motherpnc: {
_type: Type.Object,
_description: 'Mother Postnatal uuid.',
_default: {
clientsEnrolledForTb: '98fd11ba-cb4d-46f7-9b82-40d49949c7ef',
motherPostnatalEncounterType: '269bcc7f-04f8-4ddc-883d-7a3a0d569aad',
MothervisitDate: '163260AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
MotherHivStatus: '159427AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
MotherViralLoadDate: '163281AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
MotherViralLoadResult: '1305AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
MotherNextVisitDate: '5096AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
artUniqueNoConcept: '164402AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
},
},
reports: {
_type: Type.Object,
_description: 'reports uuid.',
_default: {
clientsEnrolledForTb: '98fd11ba-cb4d-46f7-9b82-40d49949c7ef',
ancVisitsReport: '5299521a-7fad-47bb-8280-14c99d04c790',
eddReport: 'aac635c9-0a77-4489-8b0d-866b3ad22f73',
motherHivStatusReport: 'ed50a889-dd5b-4759-861c-b54e3c686fe7',
},
},
mnch: {
_type: Type.Object,
_description: 'mnch summary uuid.',
_default: {
mchEncounterType: '12de5bc5-352e-4faf-9961-a2125085a75c',
antenatalVisitType: '164181AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
mchVisitType: '140084BBBBBBBBBBBBBBBBBBBBBBBBBBBBBB',
mchVisitsTypes: ['Antenatal', 'Labor and Delivery', 'Mother Postnatal'],
},
},
};
Expand Down
72 changes: 0 additions & 72 deletions packages/esm-ohri-pmtct-app/src/constants.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
import { PostSubmissionAction } from '@openmrs/openmrs-form-engine-lib';
import { artNoConcept, artUniqueNumberType } from '../constants';
import { getConfig } from '@openmrs/esm-framework';
import { fetchPatientIdentifiers, saveIdentifier } from '../api/api';
import { PatientIdentifier } from '../api/types';

const ArtSubmissionAction: PostSubmissionAction = {
applyAction: async function ({ patient, encounters, sessionMode }) {
const config = await getConfig('@ohri/openmrs-esm-ohri-pmtct');
const encounter = encounters[0];
const encounterLocation = encounter.location['uuid'];

if (sessionMode !== 'enter') {
return;
}

let artNumber = encounter.obs.find((observation) => observation.concept.uuid === artNoConcept)?.value;
let artNumber = encounter.obs.find(
(observation) => observation.concept.uuid === config.antenatal.artNoConcept,
)?.value;
if (!artNumber) {
return;
}
Expand All @@ -22,15 +25,17 @@ const ArtSubmissionAction: PostSubmissionAction = {

//Patient can only have one ART No.
const patientIdentifiers = await fetchPatientIdentifiers(patient.id);
const existingArtNumbers = patientIdentifiers.filter((id) => id.identifierType.uuid === artUniqueNumberType);
const existingArtNumbers = patientIdentifiers.filter(
(id) => id.identifierType.uuid === config.encounterTypes.artUniqueNumberType,
);
if (existingArtNumbers.length > 0) {
return;
}

//add current art number to identities
const currentArtNumberObject: PatientIdentifier = {
identifier: artNumber,
identifierType: artUniqueNumberType,
identifierType: config.encounterTypes.artUniqueNumberType,
location: encounterLocation,
preferred: false,
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { PostSubmissionAction } from '@openmrs/openmrs-form-engine-lib';
import { fetchPatientIdentifiers, saveIdentifier } from '../api/api';
import { Patient, PatientIdentifier } from '../api/types';
import { pTrackerIdConcept, PTrackerIdentifierType } from '../constants';
import { getConfig } from '@openmrs/esm-framework';

export const PTrackerSubmissionAction: PostSubmissionAction = {
applyAction: async function ({ patient, encounters, sessionMode }) {
Expand All @@ -17,20 +17,21 @@ export const PTrackerSubmissionAction: PostSubmissionAction = {
};

export async function updatePatientPtracker(encounter, encounterLocation, patientUuid) {
const inComingPTrackerID = encounter.obs.find((observation) => observation.concept.uuid === pTrackerIdConcept)?.value;
const config = await getConfig('@ohri/openmrs-esm-ohri-pmtct');
const inComingPTrackerID = encounter.obs.find((observation) => observation.concept.uuid === config.encounterTypes.pTrackerIdConcept)?.value;
if (!inComingPTrackerID) {
return;
}
const patientIdentifiers = await fetchPatientIdentifiers(patientUuid);
const existingPTrackers = patientIdentifiers.filter((id) => id.identifierType.uuid === PTrackerIdentifierType);
const existingPTrackers = patientIdentifiers.filter((id) => id.identifierType.uuid === config.encounterTypes.PTrackerIdentifierType);
if (existingPTrackers.some((ptracker) => ptracker.identifier === inComingPTrackerID)) {
return;
}

//add current ptracker to identities
const currentPTrackerObject: PatientIdentifier = {
identifier: inComingPTrackerID,
identifierType: PTrackerIdentifierType,
identifierType: config.PTrackerIdentifierType.PTrackerIdentifierType,
location: encounterLocation,
preferred: false,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,6 @@ import {
fetchPatientRelationships,
getObsFromEncounter,
} from '@ohri/openmrs-esm-ohri-commons-lib';
import {
pTrackerIdConcept,
nextVisitDate,
artProphylaxisStatus,
linkedToArt,
breastfeedingStatus,
outcomeStatus,
} from '../../../constants';
import { moduleName } from '../../..';
import { useConfig } from '@openmrs/esm-framework';

Expand All @@ -23,6 +15,7 @@ interface InfantPostnatalListProps {

const InfantPostnatalList: React.FC<InfantPostnatalListProps> = ({ patientUuid }) => {
const { t } = useTranslation();
const config = useConfig();
const headerTitle = t('hivExposedInfant', 'HIV Exposed Infant');
const InfantPNCEncounterTypeUUID = useConfig().encounterTypes.infantPostnatal;

Expand All @@ -41,7 +34,7 @@ const InfantPostnatalList: React.FC<InfantPostnatalListProps> = ({ patientUuid }
key: 'pTrackerId',
header: t('pTrackerId', 'Child PTracker ID'),
getValue: (encounter) => {
return getObsFromEncounter(encounter, pTrackerIdConcept);
return getObsFromEncounter(encounter, config.encounterTypes.pTrackerIdConcept);
},
},
{
Expand All @@ -55,35 +48,35 @@ const InfantPostnatalList: React.FC<InfantPostnatalListProps> = ({ patientUuid }
key: 'artProphylaxisStatus',
header: t('artProphylaxisStatus', 'ART Prophylaxis Status'),
getValue: (encounter) => {
return getObsFromEncounter(encounter, artProphylaxisStatus);
return getObsFromEncounter(encounter, config.artProphylaxisStatus.artProphylaxisStatus);
},
},
{
key: 'linkedToArt',
header: t('linkedToArt', 'Linked to ART'),
getValue: (encounter) => {
return getObsFromEncounter(encounter, linkedToArt);
return getObsFromEncounter(encounter, config.infantpnc.linkedToArt);
},
},
{
key: 'breastfeedingStatus',
header: t('breastfeedingStatus', 'Breastfeeding status'),
getValue: (encounter) => {
return getObsFromEncounter(encounter, breastfeedingStatus);
return getObsFromEncounter(encounter, config.infantpnc.breastfeedingStatus);
},
},
{
key: 'outcomeStatus',
header: t('outcomeStatus', 'Outcome Status'),
getValue: (encounter) => {
return getObsFromEncounter(encounter, outcomeStatus);
return getObsFromEncounter(encounter, config.infantpnc.outcomeStatus);
},
},
{
key: 'nextVisitDate',
header: t('nextVisitDate', 'Next visit date'),
getValue: (encounter) => {
return getObsFromEncounter(encounter, nextVisitDate, true);
return getObsFromEncounter(encounter, config.infantpnc.nextVisitDate, true);
},
},
{
Expand Down
Loading

0 comments on commit 5e2fd14

Please sign in to comment.