Skip to content
This repository has been archived by the owner on Dec 18, 2024. It is now read-only.

Mat 7914 patient characteristic expired #766

Merged
merged 2 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import {
PatientCharacteristicEthnicity,
PatientCharacteristicExpired,
DataElementCode,
PatientCharacteristicRace,
PatientCharacteristicSex,
} from "cqm-models";

const emptyPatient = new QDMPatient();
Expand Down Expand Up @@ -198,4 +200,72 @@ describe("DemographicsSection", () => {
});
});
});

it("should handle Race change", () => {
const qdmPatient = new QDMPatient();
const raceElement = new PatientCharacteristicRace();
const newCode: DataElementCode = {
code: "1002-5",
display: "American Indian or Alaska Native",
version: undefined,
system: "2.16.840.1.113883.6.238",
};
raceElement.dataElementCodes = [newCode];
qdmPatient.dataElements.push(raceElement);
(useQdmPatient as jest.Mock).mockImplementation(() => ({
state: { patient: qdmPatient },
dispatch: mockUseQdmPatientDispatch,
}));
render(
<FormikProvider value={mockFormik}>
<DemographicsSection canEdit={true} />
</FormikProvider>
);

expect(screen.getByText("Race")).toBeInTheDocument();
const raceInput = screen.getByTestId(
"demographics-race-input"
) as HTMLInputElement;
expect(raceInput).toBeInTheDocument();
expect(raceInput.value).toBe("American Indian or Alaska Native");

fireEvent.change(raceInput, {
target: { value: "Asian" },
});
expect(raceInput.value).toBe("Asian");
});

it("should handle Gender change", () => {
const qdmPatient = new QDMPatient();
const genderElement = new PatientCharacteristicSex();
const newCode: DataElementCode = {
system: "2.16.840.1.113883.5.1",
version: "2023-02-01",
code: "F",
display: "Female",
};
genderElement.dataElementCodes = [newCode];
qdmPatient.dataElements.push(genderElement);
(useQdmPatient as jest.Mock).mockImplementation(() => ({
state: { patient: qdmPatient },
dispatch: mockUseQdmPatientDispatch,
}));
render(
<FormikProvider value={mockFormik}>
<DemographicsSection canEdit={true} />
</FormikProvider>
);

expect(screen.getByText("Gender")).toBeInTheDocument();
const genderInput = screen.getByTestId(
"demographics-gender-input"
) as HTMLInputElement;
expect(genderInput).toBeInTheDocument();
expect(genderInput.value).toBe("Female");

fireEvent.change(genderInput, {
target: { value: "Male" },
});
expect(genderInput.value).toBe("Male");
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import {
getRaceDataElement,
LIVING_STATUS_CODE_OPTIONS,
RACE_CODE_OPTIONS,
PATIENT_CHARACTERISTIC_EXPIRED,
getPatientCharacteristicExpiredDateElement,
} from "./DemographicsSectionConst";
import { MenuItem as MuiMenuItem } from "@mui/material";
import {
Expand Down Expand Up @@ -110,6 +112,7 @@ const DemographicsSection = ({ canEdit }) => {

const expiredElement = getDataElementByStatus("expired", patient);
if (expiredElement) {
expiredElement.dataElementCodes = PATIENT_CHARACTERISTIC_EXPIRED;
setLivingStatusDataElement(expiredElement);
} else {
setLivingStatusDataElement("Living");
Expand Down Expand Up @@ -209,10 +212,8 @@ const DemographicsSection = ({ canEdit }) => {

const handleExpiredDateTimeChange = (val) => {
const expiredElement = getDataElementByStatus("expired", patient);
const newExpiredElement: DataElement = new PatientCharacteristicExpired(
expiredElement
);
newExpiredElement.expiredDatetime = val;
const newExpiredElement: DataElement =
getPatientCharacteristicExpiredDateElement(val, expiredElement);
setLivingStatusDataElement(newExpiredElement);
dispatch({
type: PatientActionType.MODIFY_DATA_ELEMENT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,23 @@ export const ETHNICITY_CODE_OPTIONS: DataElementCode[] = [
];

export const LIVING_STATUS_CODE_OPTIONS = ["Living", "Expired"];
export const PATIENT_CHARACTERISTIC_EXPIRED: DataElementCode = {
code: "419099009",
system: "2.16.840.1.113883.6.96",
version: "2022-09",
display: "Dead (finding)",
};
export const getPatientCharacteristicExpiredDateElement = (
value,
existingElement: DataElement
): DataElement => {
const expired: DataElement = existingElement
? new PatientCharacteristicExpired(existingElement)
: new PatientCharacteristicExpired();
expired.expiredDatetime = value;
expired.dataElementCodes = [PATIENT_CHARACTERISTIC_EXPIRED];
return expired;
};

export const getBirthDateElement = (
value,
Expand Down Expand Up @@ -169,7 +186,7 @@ export const getEthnicityDataElement = (

export const getLivingStatusDataElement = (): DataElement => {
const pce: DataElement = new PatientCharacteristicExpired();
pce.dataElementCodes = [];
pce.dataElementCodes = [PATIENT_CHARACTERISTIC_EXPIRED];
return pce;
};

Expand Down
Loading