diff --git a/src/components/accessories/patientTriage/PatientTriage.tsx b/src/components/accessories/patientTriage/PatientTriage.tsx index 3283a68b7..cf6c7275c 100644 --- a/src/components/accessories/patientTriage/PatientTriage.tsx +++ b/src/components/accessories/patientTriage/PatientTriage.tsx @@ -12,6 +12,7 @@ import { deleteExamination, deleteExaminationReset, examinationsByPatientId, + getDefaultPatientExamination, getLastByPatientId, updateExamination, updateExaminationReset, @@ -46,6 +47,11 @@ const PatientTriage: FC = () => { PatientExaminationDTO | undefined >((state) => state.examinations.getLastByPatientId.data); + const defaultPatientExamination = useSelector< + IState, + PatientExaminationDTO | undefined + >((state) => state.examinations.getDefaultPatientExamination.data); + const patientDataCode = useSelector( (state: IState) => state.patients.selectedPatient.data?.code ); @@ -108,6 +114,7 @@ const PatientTriage: FC = () => { useEffect(() => { if (patientDataCode) { dispatch(getLastByPatientId(patientDataCode)); + dispatch(getDefaultPatientExamination(patientDataCode)); } }, [patientDataCode]); @@ -153,21 +160,15 @@ const PatientTriage: FC = () => { = { type: "date", }, pex_height: { - value: "175", + value: "0", type: "number", }, pex_weight: { - value: "83", + value: "0", type: "number", }, pex_temp: { - value: "36", + value: "0", type: "number", }, pex_sat: { - value: "98", + value: "0", type: "number", }, pex_ap_min: { - value: "80", + value: "0", type: "number", }, pex_ap_max: { - value: "120", + value: "0", type: "number", }, pex_rr: { - value: "20", + value: "0", type: "number", }, pex_diuresis: { - value: "100", + value: "0", type: "number", }, pex_hr: { - value: "60", + value: "0", type: "number", }, pex_hgt: { - value: "80", + value: "0", type: "number", }, pex_diuresis_desc: { diff --git a/src/libraries/formDataHandling/functions.ts b/src/libraries/formDataHandling/functions.ts index 40407549b..e5fb85287 100644 --- a/src/libraries/formDataHandling/functions.ts +++ b/src/libraries/formDataHandling/functions.ts @@ -102,7 +102,9 @@ export const formatAllFieldValues = ( (acc: Record, key) => { switch (fields[key].type) { case "number": - acc[key] = parseInt(values[key]); + const int = parseInt(values[key]); + const float = parseFloat(values[key]); + acc[key] = int < float ? float : int; break; case "date": acc[key] = parseDate(values[key], withTimezone); @@ -198,6 +200,10 @@ export const updateTriageFields = ( (value ?? "") as string ).toLowerCase()); } + if (draft[key as string] && typeof value === "number") { + return (draft[key as string].value = draft[key as string].value = + value); + } if (draft[key as string]) { return (draft[key as string].value = parseFloat(value as string) ? value diff --git a/src/mockServer/fixtures/patientExaminationDTO.js b/src/mockServer/fixtures/patientExaminationDTO.js index 201af21a7..78098c32c 100644 --- a/src/mockServer/fixtures/patientExaminationDTO.js +++ b/src/mockServer/fixtures/patientExaminationDTO.js @@ -8,7 +8,7 @@ const patientExaminationDTO = { pex_pa_max: 120, pex_fc: 75, pex_temp: 37.5, - pex_sat: 140, + pex_sat: 92, 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.", }; diff --git a/src/mockServer/routes/examinations.js b/src/mockServer/routes/examinations.js index 531ea584f..c0607c51d 100644 --- a/src/mockServer/routes/examinations.js +++ b/src/mockServer/routes/examinations.js @@ -24,6 +24,16 @@ export const examinationsRoutes = (server) => { break; } }); + server.get("/defaultPatientExamination").intercept((req, res) => { + const code = req.params.code; + switch (code) { + case "1": + res.status(400); + break; + default: + res.status(200).json(patientExaminationDTO); + } + }); server.get("/lastByPatientId/:patId").intercept((req, res) => { const code = req.params.code; switch (code) { diff --git a/src/state/examinations/actions.ts b/src/state/examinations/actions.ts index b6de1a049..88bb428a4 100644 --- a/src/state/examinations/actions.ts +++ b/src/state/examinations/actions.ts @@ -10,6 +10,9 @@ import { CREATE_EXAMINATION_SUCCESS, DELETE_EXAMINATION_FAIL, DELETE_EXAMINATION_RESET, + GET_DEFAULT_EXAMINATION_FAIL, + GET_DEFAULT_EXAMINATION_LOADING, + GET_DEFAULT_EXAMINATION_SUCCESS, GET_LAST_EXAMINATION_FAIL, GET_LAST_EXAMINATION_LOADING, GET_LAST_EXAMINATION_SUCCESS, @@ -96,6 +99,34 @@ export const deleteExaminationReset = }); }; +export const getDefaultPatientExamination = + (patId: number) => + (dispatch: Dispatch>): void => { + dispatch({ + type: GET_DEFAULT_EXAMINATION_LOADING, + }); + if (patId) { + examinationsApi.getDefaultPatientExamination({ patId: patId }).subscribe( + (payload) => { + dispatch({ + type: GET_DEFAULT_EXAMINATION_SUCCESS, + payload: payload, + }); + }, + (error) => { + dispatch({ + type: GET_DEFAULT_EXAMINATION_FAIL, + error, + }); + } + ); + } else + dispatch({ + type: GET_DEFAULT_EXAMINATION_FAIL, + error: "patient object should not be empty", + }); + }; + export const getLastByPatientId = (patId: number) => (dispatch: Dispatch>): void => { diff --git a/src/state/examinations/consts.ts b/src/state/examinations/consts.ts index d85873ef6..6bf03062d 100644 --- a/src/state/examinations/consts.ts +++ b/src/state/examinations/consts.ts @@ -19,6 +19,13 @@ export const GET_LAST_EXAMINATION_SUCCESS = export const GET_LAST_EXAMINATION_FAIL = "examinations/GET_LAST_EXAMINATION_FAIL"; +export const GET_DEFAULT_EXAMINATION_LOADING = + "examinations/GET_DEFAULT_EXAMINATION_LOADING"; +export const GET_DEFAULT_EXAMINATION_SUCCESS = + "examinations/GET_DEFAULT_EXAMINATION_SUCCESS"; +export const GET_DEFAULT_EXAMINATION_FAIL = + "examinations/GET_DEFAULT_EXAMINATION_FAIL"; + export const SEARCH_EXAMINATION_LOADING = "examinations/SEARCH_EXAMINATION_LOADING"; export const SEARCH_EXAMINATION_SUCCESS = diff --git a/src/state/examinations/initial.ts b/src/state/examinations/initial.ts index eb1f1f73b..82501f10b 100644 --- a/src/state/examinations/initial.ts +++ b/src/state/examinations/initial.ts @@ -3,6 +3,7 @@ import { IExaminationsState } from "./types"; export const initial: IExaminationsState = { createExamination: { status: "IDLE" }, updateExamination: { status: "IDLE" }, + getDefaultPatientExamination: { status: "IDLE" }, getLastByPatientId: { status: "IDLE" }, examinationsByPatientId: { status: "IDLE", data: [] }, deleteExamination: { status: "IDLE" }, diff --git a/src/state/examinations/reducer.ts b/src/state/examinations/reducer.ts index e2ce2e9a1..ca42f8005 100644 --- a/src/state/examinations/reducer.ts +++ b/src/state/examinations/reducer.ts @@ -21,6 +21,9 @@ import { GET_LAST_EXAMINATION_FAIL, GET_LAST_EXAMINATION_LOADING, GET_LAST_EXAMINATION_SUCCESS, + GET_DEFAULT_EXAMINATION_FAIL, + GET_DEFAULT_EXAMINATION_LOADING, + GET_DEFAULT_EXAMINATION_SUCCESS, } from "./consts"; import { initial } from "./initial"; import { IExaminationsState } from "./types"; @@ -92,6 +95,26 @@ export default produce( break; } + /** + * GET_DEFAULT_EXAMINATION + */ + case GET_DEFAULT_EXAMINATION_LOADING: { + draft.getDefaultPatientExamination.status = "LOADING"; + break; + } + + case GET_DEFAULT_EXAMINATION_SUCCESS: { + draft.getDefaultPatientExamination.status = "SUCCESS"; + draft.getDefaultPatientExamination.data = action.payload; + delete draft.getDefaultPatientExamination.error; + break; + } + case GET_DEFAULT_EXAMINATION_FAIL: { + draft.getDefaultPatientExamination.status = "FAIL"; + draft.getDefaultPatientExamination.error = action.error; + break; + } + /** * GET_LAST_EXAMINATION */ diff --git a/src/state/examinations/types.ts b/src/state/examinations/types.ts index 9853d61b3..5de3d9b4f 100644 --- a/src/state/examinations/types.ts +++ b/src/state/examinations/types.ts @@ -4,6 +4,7 @@ import { IApiResponse } from "../types"; export type IExaminationsState = { createExamination: IApiResponse; updateExamination: IApiResponse; + getDefaultPatientExamination: IApiResponse; getLastByPatientId: IApiResponse; examinationsByPatientId: IApiResponse>; deleteExamination: IApiResponse;