Skip to content

Commit

Permalink
OH2-245 | Update examination state and triage form (#528)
Browse files Browse the repository at this point in the history
* update(OHCS-102): Update examination state and triage form

* update: Update patient triage logic
  • Loading branch information
SteveGT96 authored Oct 31, 2023
1 parent 9a28afc commit 8d85466
Show file tree
Hide file tree
Showing 8 changed files with 165 additions and 45 deletions.
45 changes: 43 additions & 2 deletions src/components/accessories/patientTriage/PatientTriage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
deleteExamination,
deleteExaminationReset,
examinationsByPatientId,
getLastByPatientId,
updateExamination,
updateExaminationReset,
} from "../../../state/examinations/actions";
Expand Down Expand Up @@ -40,6 +41,11 @@ const PatientTriage: FC = () => {

const [creationMode, setCreationMode] = useState(true);

const lastExamination = useSelector<
IState,
PatientExaminationDTO | undefined
>((state) => state.examinations.getLastByPatientId.data);

const patientDataCode = useSelector(
(state: IState) => state.patients.selectedPatient.data?.code
);
Expand Down Expand Up @@ -71,8 +77,17 @@ const PatientTriage: FC = () => {
setActivityTransitionState("FAIL");
scrollToElement(infoBoxRef.current);
}
if (status === "SUCCESS" && patientDataCode) {
dispatch(getLastByPatientId(patientDataCode));
}
}, [status]);

useEffect(() => {
if (deleteStatus === "SUCCESS" && patientDataCode) {
dispatch(getLastByPatientId(patientDataCode));
}
}, [deleteStatus]);

useEffect(() => {
dispatch(createExaminationReset());
dispatch(updateExaminationReset());
Expand All @@ -90,6 +105,12 @@ const PatientTriage: FC = () => {
}
}, [dispatch, activityTransitionState]);

useEffect(() => {
if (patientDataCode) {
dispatch(getLastByPatientId(patientDataCode));
}
}, [patientDataCode]);

const onSubmit = (triage: PatientExaminationDTO) => {
setShouldResetForm(false);
triage.patientCode = patientDataCode ?? -1;
Expand Down Expand Up @@ -132,8 +153,28 @@ const PatientTriage: FC = () => {
<PatientTriageForm
fields={
creationMode
? initialFields
: updateTriageFields(initialFields, triageToEdit)
? {
...initialFields,
pex_height: {
...initialFields.pex_height,
value:
lastExamination?.pex_height?.toString() ??
initialFields.pex_height.value,
},
pex_weight: {
...initialFields.pex_weight,
value:
lastExamination?.pex_weight?.toString() ??
initialFields.pex_weight.value,
},
}
: updateTriageFields(initialFields, {
...triageToEdit,
pex_height:
triageToEdit.pex_height ?? lastExamination?.pex_height,
pex_weight:
triageToEdit.pex_weight ?? lastExamination?.pex_weight,
})
}
creationMode={creationMode}
onSubmit={onSubmit}
Expand Down
9 changes: 5 additions & 4 deletions src/mockServer/fixtures/patientExaminationDTO.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ const patientExaminationDTO = {
pex_ID: Math.floor(Math.random() * 100 + 1),
pex_date: "2021-03-19T14:58:00.000Z",
patientCode: 1,
pex_height: 175,
pex_weight: 70,
pex_height: 178,
pex_weight: 84,
pex_pa_min: 50,
pex_pa_max: 120,
pex_fc: 75,
pex_temp: 37.5,
pex_sat: 140,
pex_note: "Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem."
pex_note:
"Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem.",
};

export default patientExaminationDTO;
export default patientExaminationDTO;
93 changes: 54 additions & 39 deletions src/mockServer/routes/examinations.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,59 @@
import patientExaminationDTO from "../fixtures/patientExaminationDTO";

export const examinationsRoutes = (server) => {
server.namespace("/examinations", () => {
server.post("/").intercept((req, res) => {
const body = req.jsonBody();
switch (body.patientCode) {
case "fail":
res.status(400);
break;
default:
res.status(201).json(body);
break;
}
});
server.put("/:code").intercept((req, res) => {
const body = req.jsonBody();
switch (body.patientCode) {
case "fail":
res.status(400);
break;
default:
res.status(200).json(body);
break;
}
});
server.get("/byPatientId/:patId").intercept((req, res) => {
const code = req.params.code;
switch (code) {
case "1":
res.status(400);
break;
case "2":
res.status(204);
res.body = null;
break;
default:
res.status(200).json([patientExaminationDTO,
patientExaminationDTO, patientExaminationDTO, patientExaminationDTO
]);
}
});
server.namespace("/examinations", () => {
server.post("/").intercept((req, res) => {
const body = req.jsonBody();
switch (body.patientCode) {
case "fail":
res.status(400);
break;
default:
res.status(201).json(body);
break;
}
});
server.put("/:code").intercept((req, res) => {
const body = req.jsonBody();
switch (body.patientCode) {
case "fail":
res.status(400);
break;
default:
res.status(200).json(body);
break;
}
});
server.get("/lastByPatientId/:patId").intercept((req, res) => {
const code = req.params.code;
switch (code) {
case "1":
res.status(400);
break;
default:
res.status(200).json(patientExaminationDTO);
}
});
server.get("/byPatientId/:patId").intercept((req, res) => {
const code = req.params.code;
switch (code) {
case "1":
res.status(400);
break;
case "2":
res.status(204);
res.body = null;
break;
default:
res
.status(200)
.json([
patientExaminationDTO,
patientExaminationDTO,
patientExaminationDTO,
patientExaminationDTO,
]);
}
});
});
};
31 changes: 31 additions & 0 deletions src/state/examinations/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import {
CREATE_EXAMINATION_SUCCESS,
DELETE_EXAMINATION_FAIL,
DELETE_EXAMINATION_RESET,
GET_LAST_EXAMINATION_FAIL,
GET_LAST_EXAMINATION_LOADING,
GET_LAST_EXAMINATION_SUCCESS,
SEARCH_EXAMINATION_FAIL,
SEARCH_EXAMINATION_LOADING,
SEARCH_EXAMINATION_SUCCESS,
Expand Down Expand Up @@ -93,6 +96,34 @@ export const deleteExaminationReset =
});
};

export const getLastByPatientId =
(patId: number) =>
(dispatch: Dispatch<IAction<PatientExaminationDTO, {}>>): void => {
dispatch({
type: GET_LAST_EXAMINATION_LOADING,
});
if (patId) {
examinationsApi.getLastByPatientId({ patId: patId }).subscribe(
(payload) => {
dispatch({
type: GET_LAST_EXAMINATION_SUCCESS,
payload: payload,
});
},
(error) => {
dispatch({
type: GET_LAST_EXAMINATION_FAIL,
error,
});
}
);
} else
dispatch({
type: GET_LAST_EXAMINATION_FAIL,
error: "patient object should not be empty",
});
};

export const examinationsByPatientId =
(patId: number | undefined) =>
(dispatch: Dispatch<IAction<PatientExaminationDTO[], {}>>): void => {
Expand Down
7 changes: 7 additions & 0 deletions src/state/examinations/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ export const UPDATE_EXAMINATION_SUCCESS =
export const UPDATE_EXAMINATION_FAIL = "examinations/UPDATE_EXAMINATION_FAIL";
export const UPDATE_EXAMINATION_RESET = "examinations/UPDATE_EXAMINATION_RESET";

export const GET_LAST_EXAMINATION_LOADING =
"examinations/GET_LAST_EXAMINATION_LOADING";
export const GET_LAST_EXAMINATION_SUCCESS =
"examinations/GET_LAST_EXAMINATION_SUCCESS";
export const GET_LAST_EXAMINATION_FAIL =
"examinations/GET_LAST_EXAMINATION_FAIL";

export const SEARCH_EXAMINATION_LOADING =
"examinations/SEARCH_EXAMINATION_LOADING";
export const SEARCH_EXAMINATION_SUCCESS =
Expand Down
1 change: 1 addition & 0 deletions src/state/examinations/initial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { IExaminationsState } from "./types";
export const initial: IExaminationsState = {
createExamination: { status: "IDLE" },
updateExamination: { status: "IDLE" },
getLastByPatientId: { status: "IDLE" },
examinationsByPatientId: { status: "IDLE", data: [] },
deleteExamination: { status: "IDLE" },
};
23 changes: 23 additions & 0 deletions src/state/examinations/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ import {
SEARCH_EXAMINATION_LOADING,
SEARCH_EXAMINATION_SUCCESS,
SEARCH_EXAMINATION_SUCCESS_EMPTY,
GET_LAST_EXAMINATION_FAIL,
GET_LAST_EXAMINATION_LOADING,
GET_LAST_EXAMINATION_SUCCESS,
} from "./consts";
import { initial } from "./initial";
import { IExaminationsState } from "./types";
Expand Down Expand Up @@ -89,6 +92,26 @@ export default produce(
break;
}

/**
* GET_LAST_EXAMINATION
*/
case GET_LAST_EXAMINATION_LOADING: {
draft.getLastByPatientId.status = "LOADING";
break;
}

case GET_LAST_EXAMINATION_SUCCESS: {
draft.getLastByPatientId.status = "SUCCESS";
draft.getLastByPatientId.data = action.payload;
delete draft.getLastByPatientId.error;
break;
}
case GET_LAST_EXAMINATION_FAIL: {
draft.getLastByPatientId.status = "FAIL";
draft.getLastByPatientId.error = action.error;
break;
}

/**
* SEARCH_EXAMINATION
*/
Expand Down
1 change: 1 addition & 0 deletions src/state/examinations/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { IApiResponse } from "../types";
export type IExaminationsState = {
createExamination: IApiResponse<PatientExaminationDTO>;
updateExamination: IApiResponse<PatientExaminationDTO>;
getLastByPatientId: IApiResponse<PatientExaminationDTO>;
examinationsByPatientId: IApiResponse<Array<PatientExaminationDTO>>;
deleteExamination: IApiResponse<null>;
};

0 comments on commit 8d85466

Please sign in to comment.