Skip to content

Commit

Permalink
fix admission request notes
Browse files Browse the repository at this point in the history
  • Loading branch information
chibongho committed Oct 10, 2024
1 parent c9244f7 commit 5139689
Show file tree
Hide file tree
Showing 16 changed files with 213 additions and 95 deletions.
59 changes: 37 additions & 22 deletions packages/esm-ward-app/src/config-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,30 +74,45 @@ export const configSchema: ConfigSchema = {
},
},
pendingItems: {
orders: {
orderTypes: {
_type: Type.Array,
_description: 'Configures pending orders and transfers to display.',
_default: [{ label: 'Labs', uuid: '52a447d3-a64a-11e3-9aeb-50e549534c5e' }],
_elements: {
uuid: {
_type: Type.UUID,
_description: 'Identifies the order type.',
},
label: {
_type: Type.String,
_description:
"The label or i18n key to the translated label to display. If not provided, defaults to 'Orders'",
_default: null,
_type: Type.Array,
_description: 'Configures pending orders and transfers to display.',
_default: [
{
id: 'pending-items',
orders: {
orderTypes: [{ label: 'Labs', uuid: '52a447d3-a64a-11e3-9aeb-50e549534c5e' }],
},
showPendingItems: true,
},
],
_elements: {
id: {
_type: Type.String,
_description: 'The unique identifier for this patient card element',
},
orders: {
orderTypes: {
_type: Type.Array,
_description: 'Configures pending orders and transfers to display.',
_elements: {
uuid: {
_type: Type.UUID,
_description: 'Identifies the order type.',
},
label: {
_type: Type.String,
_description:
"The label or i18n key to the translated label to display. If not provided, defaults to 'Orders'",
_default: null,
},
},
},
},
},
showPendingItems: {
_type: Type.Boolean,
_description:
'Optional. If true, pending items (e.g., number of pending orders) will be displayed on the patient card.',
_default: true,
showPendingItems: {
_type: Type.Boolean,
_description:
'Optional. If true, pending items (e.g., number of pending orders) will be displayed on the patient card.',
},
},
},
patientIdentifier: {
Expand Down Expand Up @@ -158,7 +173,7 @@ export const configSchema: ConfigSchema = {
_description: 'Configures admission request notes to display.',
_default: [
{
id: 'admission-note',
id: 'admission-request-note',
conceptUuid: '161011AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
},
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { useConfig } from '@openmrs/esm-framework';
import React from 'react';
import { type ObsElementConfig } from '../../config-schema';
import { type WardPatient } from '../../types';
import { useElementConfig } from '../../ward-view/ward-view.resource';
import WardPatientObs from '../row-elements/ward-patient-obs';
import styles from '../ward-patient-card.scss';
import { useElementConfig } from '../../ward-view/ward-view.resource';

interface AdmissionRequestNoteRowProps {
wardPatient: WardPatient;
Expand All @@ -13,7 +12,7 @@ interface AdmissionRequestNoteRowProps {

const AdmissionRequestNoteRow: React.FC<AdmissionRequestNoteRowProps> = ({ id, wardPatient }) => {
const { patient, visit, inpatientAdmission } = wardPatient;
const { conceptUuid } = useElementConfig('admissionRequestNote', id);
const { conceptUuid } = useElementConfig('admissionRequestNote', id) ?? {};
const config: ObsElementConfig = {
conceptUuid,
limit: 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const WardPatientObs: React.FC<WardPatientObsProps> = ({ id, configOverride, pat
<span className={styles.wardPatientObsLabel}>
{labelToDisplay ? t('labelColon', '{{label}}:', { label: labelToDisplay }) : ''}
</span>
{obsNodes}
<div className={styles.dotSeparatedChildren}>{obsNodes}</div>
</div>
);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
width: 100%;
padding: layout.$spacing-04;
border-top: 1px colors.$gray-20 solid;
background-color: colors.$white;

&:empty {
border-top: 0px;
Expand Down Expand Up @@ -174,7 +175,7 @@
display: flex;
flex-wrap: wrap;

> div:not(div:first-of-type):not(:empty) {
> *:not(*:first-of-type):not(:empty) {
display: flex;
align-items: center;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import WardPatientName from '../../ward-patient-card/row-elements/ward-patient-n
import WardPatientTimeOnWard from '../../ward-patient-card/row-elements/ward-patient-time-on-ward';
import WardPatientTimeSinceAdmission from '../../ward-patient-card/row-elements/ward-patient-time-since-admission';
import styles from '../../ward-patient-card/ward-patient-card.scss';
import { WardPatientCardType } from '../../types';
import { type WardPatientCardType } from '../../types';
import WardPatientGender from '../../ward-patient-card/row-elements/ward-patient-gender.component';

const DefaultWardPatientCardHeader : WardPatientCardType = (wardPatient) => {
const DefaultWardPatientCardHeader: WardPatientCardType = (wardPatient) => {
const { patient, bed, inpatientAdmission } = wardPatient;
const { encounterAssigningToCurrentInpatientLocation, firstAdmissionOrTransferEncounter } = inpatientAdmission ?? {};

Expand All @@ -18,13 +19,14 @@ const DefaultWardPatientCardHeader : WardPatientCardType = (wardPatient) => {
{bed ? <WardPatientBedNumber bed={bed} /> : null}
<WardPatientName patient={patient} />
<WardPatientIdentifier patient={patient} />
<WardPatientGender patient={patient} />
<WardPatientAge patient={patient} />
<WardPatientTimeSinceAdmission firstAdmissionOrTransferEncounter={firstAdmissionOrTransferEncounter} />
<WardPatientTimeOnWard
encounterAssigningToCurrentInpatientLocation={encounterAssigningToCurrentInpatientLocation}
/>
</div>
);
}
};

export default DefaultWardPatientCardHeader;
export default DefaultWardPatientCardHeader;
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useTranslation } from 'react-i18next';
import { type WardViewContext, type InpatientRequest } from '../../types';
import AdmissionRequestCard from '../../ward-workspace/admission-request-card/admission-request-card.component';
import WardPatientSkeletonText from '../../ward-patient-card/row-elements/ward-patient-skeleton-text';
import AdmissionRequestNoteRow from '../../ward-patient-card/card-rows/admission-request-note-row.component';

function DefaultWardPendingPatients() {
const { wardPatientGroupDetails } = useAppContext<WardViewContext>('ward-view-context') ?? {};
Expand All @@ -21,16 +22,29 @@ function DefaultWardPendingPatients() {
<ErrorState headerTitle={t('admissionRequests', 'Admission requests')} error={errorFetchingInpatientRequests} />
) : (
<>
{inpatientRequests?.map((request: InpatientRequest, i) => (
<AdmissionRequestCard
key={`admission-request-card-${i}`}
patient={request.patient}
visit={request.visit}
bed={null}
inpatientRequest={request}
inpatientAdmission={null}
/>
))}
{inpatientRequests?.map((request: InpatientRequest, i) => {
const wardPatient = {
patient: request.patient,
visit: request.visit,
bed: null,
inpatientRequest: request,
inpatientAdmission: null,
};

return (
<AdmissionRequestCard
key={`admission-request-card-${i}`}
wardPatient={{
patient: request.patient,
visit: request.visit,
bed: null,
inpatientRequest: request,
inpatientAdmission: null,
}}>
<AdmissionRequestNoteRow id={'admission-request-note'} wardPatient={wardPatient} />
</AdmissionRequestCard>
);
})}
</>
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,60 +1,60 @@
import { useAppContext } from '@openmrs/esm-framework';
import React from 'react';
import WardBed from '../../beds/ward-bed.component';
import { MotherAndChild, type WardPatient, type WardViewContext } from '../../types';
import { type MotherAndChild, type WardPatient, type WardViewContext } from '../../types';
import { bedLayoutToBed } from '../ward-view.resource';
import MaternalWardPatientCard from './maternal-ward-patient-card.component';

interface MaternalWardBedsProps {
motherChildrenRelationshipsByPatient: Map<string, MotherAndChild[]>;
}

const MaternalWardBeds : React.FC<MaternalWardBedsProps> = ({motherChildrenRelationshipsByPatient}) => {
const {wardPatientGroupDetails} = useAppContext<WardViewContext>('ward-view-context') ?? {};
const MaternalWardBeds: React.FC<MaternalWardBedsProps> = ({ motherChildrenRelationshipsByPatient }) => {
const { wardPatientGroupDetails } = useAppContext<WardViewContext>('ward-view-context') ?? {};
const { bedLayouts, wardAdmittedPatientsWithBed } = wardPatientGroupDetails ?? {};

const wardBeds = bedLayouts?.map((bedLayout) => {
const { patients: patientsInCurrentBed } = bedLayout;
const bed = bedLayoutToBed(bedLayout);
const wardPatients: WardPatient[] = patientsInCurrentBed.map((patient): WardPatient => {
const inpatientAdmission = wardAdmittedPatientsWithBed?.get(patient.uuid);
if (inpatientAdmission) {
const { patient, visit, currentInpatientRequest } = inpatientAdmission;
return { patient, visit, bed, inpatientAdmission, inpatientRequest: currentInpatientRequest || null };
} else {
// for some reason this patient is in a bed but not in the list of admitted patients,
// so we need to use the patient data from the bed endpoint
return {
patient: patient,
visit: null,
bed,
inpatientAdmission: null,
inpatientRequest: null,
};
}
}).filter((wardPatient) => {
// filter out any child patient whose mother is also assigned to the same bed
// (the child patient will instead have a sub-card rendered in the mother's patient card)
const patientUuid = wardPatient.patient.uuid;
for(const relationship of motherChildrenRelationshipsByPatient?.get(patientUuid) ?? []) {
if(relationship.child.uuid == patientUuid) {
if(patientsInCurrentBed.some((patient) => patient.uuid == relationship.mother.uuid)) {
return false;
const wardPatients: WardPatient[] = patientsInCurrentBed
.map((patient): WardPatient => {
const inpatientAdmission = wardAdmittedPatientsWithBed?.get(patient.uuid);
if (inpatientAdmission) {
const { patient, visit, currentInpatientRequest } = inpatientAdmission;
return { patient, visit, bed, inpatientAdmission, inpatientRequest: currentInpatientRequest || null };
} else {
// for some reason this patient is in a bed but not in the list of admitted patients,
// so we need to use the patient data from the bed endpoint
return {
patient: patient,
visit: null,
bed,
inpatientAdmission: null,
inpatientRequest: null,
};
}
})
.filter((wardPatient) => {
// filter out any child patient whose mother is also assigned to the same bed
// (the child patient will instead have a sub-card rendered in the mother's patient card)
const patientUuid = wardPatient.patient.uuid;
for (const relationship of motherChildrenRelationshipsByPatient?.get(patientUuid) ?? []) {
if (relationship.child.uuid == patientUuid) {
if (patientsInCurrentBed.some((patient) => patient.uuid == relationship.mother.uuid)) {
return false;
}
}
}
}
return true;
});
const patientCards = wardPatients.map(wardPatient => (
<MaternalWardPatientCard
key={wardPatient.patient.uuid}
{...wardPatient} />
return true;
});
const patientCards = wardPatients.map((wardPatient) => (
<MaternalWardPatientCard key={wardPatient.patient.uuid} {...wardPatient} />
));

return <WardBed key={bed.uuid} bed={bed} patientCards={patientCards} />;
});

return <>{wardBeds}</>;
}
};

export default MaternalWardBeds;
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import classNames from 'classnames';
import React from 'react';
import { WardPatientCardType } from '../../types';
import { type WardPatientCardType } from '../../types';
import WardPatientAge from '../../ward-patient-card/row-elements/ward-patient-age';
import WardPatientBedNumber from '../../ward-patient-card/row-elements/ward-patient-bed-number';
import WardPatientAddress from '../../ward-patient-card/row-elements/ward-patient-header-address';
Expand All @@ -10,7 +10,7 @@ import WardPatientObs from '../../ward-patient-card/row-elements/ward-patient-ob
import WardPatientTimeSinceAdmission from '../../ward-patient-card/row-elements/ward-patient-time-since-admission';
import styles from '../../ward-patient-card/ward-patient-card.scss';

const MaternalWardPatientCardHeader : WardPatientCardType = (wardPatient) => {
const MaternalWardPatientCardHeader: WardPatientCardType = (wardPatient) => {
const { patient, bed, visit, inpatientAdmission } = wardPatient;
const { firstAdmissionOrTransferEncounter } = inpatientAdmission ?? {};

Expand All @@ -20,11 +20,11 @@ const MaternalWardPatientCardHeader : WardPatientCardType = (wardPatient) => {
<WardPatientName patient={patient} />
<WardPatientIdentifier patient={patient} />
<WardPatientAge patient={patient} />
<WardPatientAddress id={"patient-address"} patient={patient} />
<WardPatientObs id={"admission-reason"} patient={patient} visit={visit} />
<WardPatientAddress id={'patient-address'} patient={patient} />
<WardPatientObs id={'admission-reason'} patient={patient} visit={visit} />
<WardPatientTimeSinceAdmission firstAdmissionOrTransferEncounter={firstAdmissionOrTransferEncounter} />
</div>
);
}
};

export default MaternalWardPatientCardHeader;
export default MaternalWardPatientCardHeader;
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ const MaternalWardPatientCard: WardPatientCardType = (wardPatient) => {
<PendingItemsRow id={'pending-items'} wardPatient={wardPatient} />
<CodedObsTagsRow id="pregnancy-complications" {...wardPatient} />
<MotherChildRowExtension {...wardPatient} />
<AdmissionRequestNoteRow id={'admission-request-note'} wardPatient={wardPatient} />
</WardPatientCard>
);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { ErrorState, useAppContext } from '@openmrs/esm-framework';
import React from 'react';
import { useTranslation } from 'react-i18next';
import { type InpatientRequest, type WardViewContext } from '../../types';
import AdmissionRequestNoteRow from '../../ward-patient-card/card-rows/admission-request-note-row.component';
import CodedObsTagsRow from '../../ward-patient-card/card-rows/coded-obs-tags-row.component';
import MotherChildRowExtension from '../../ward-patient-card/card-rows/mother-child-row.component';
import WardPatientSkeletonText from '../../ward-patient-card/row-elements/ward-patient-skeleton-text';
import AdmissionRequestCard from '../../ward-workspace/admission-request-card/admission-request-card.component';

function MaternalWardPendingPatients() {
const { wardPatientGroupDetails } = useAppContext<WardViewContext>('ward-view-context') ?? {};
const { t } = useTranslation();
const { inpatientRequestResponse } = wardPatientGroupDetails ?? {};
const {
inpatientRequests,
isLoading: isLoadingInpatientRequests,
error: errorFetchingInpatientRequests,
} = inpatientRequestResponse ?? {};

return isLoadingInpatientRequests ? (
<WardPatientSkeletonText />
) : errorFetchingInpatientRequests ? (
<ErrorState headerTitle={t('admissionRequests', 'Admission requests')} error={errorFetchingInpatientRequests} />
) : (
<>
{inpatientRequests?.map((request: InpatientRequest, i) => {
const wardPatient = {
patient: request.patient,
visit: request.visit,
bed: null,
inpatientRequest: request,
inpatientAdmission: null,
};

return (
<AdmissionRequestCard key={`admission-request-card-${i}`} wardPatient={wardPatient}>
<CodedObsTagsRow id="pregnancy-complications" {...wardPatient} />
<MotherChildRowExtension {...wardPatient} />
<AdmissionRequestNoteRow id={'admission-request-note'} wardPatient={wardPatient} />
</AdmissionRequestCard>
);
})}
</>
);
}

export default MaternalWardPendingPatients;
Loading

0 comments on commit 5139689

Please sign in to comment.