Skip to content

Commit

Permalink
update(OH2-247): Update triage default values
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveGT96 committed Nov 2, 2023
1 parent 333019c commit e214ce4
Show file tree
Hide file tree
Showing 10 changed files with 107 additions and 27 deletions.
31 changes: 16 additions & 15 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,
getDefaultPatientExamination,
getLastByPatientId,
updateExamination,
updateExaminationReset,
Expand Down Expand Up @@ -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
);
Expand Down Expand Up @@ -108,6 +114,7 @@ const PatientTriage: FC = () => {
useEffect(() => {
if (patientDataCode) {
dispatch(getLastByPatientId(patientDataCode));
dispatch(getDefaultPatientExamination(patientDataCode));
}
}, [patientDataCode]);

Expand Down Expand Up @@ -153,21 +160,15 @@ const PatientTriage: FC = () => {
<PatientTriageForm
fields={
creationMode
? {
...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, {
...(defaultPatientExamination ?? {}),
pex_height:
lastExamination?.pex_height ??
defaultPatientExamination?.pex_height,
pex_weight:
lastExamination?.pex_weight ??
defaultPatientExamination?.pex_weight,
} as any)
: updateTriageFields(initialFields, {
...triageToEdit,
pex_height:
Expand Down
20 changes: 10 additions & 10 deletions src/components/accessories/patientTriage/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,43 +27,43 @@ export const initialFields: TFields<TPatientTriageFormFieldName> = {
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: {
Expand Down
8 changes: 7 additions & 1 deletion src/libraries/formDataHandling/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ export const formatAllFieldValues = (
(acc: Record<string, TFieldFormattedValue>, 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);
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/mockServer/fixtures/patientExaminationDTO.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
};
Expand Down
10 changes: 10 additions & 0 deletions src/mockServer/routes/examinations.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
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_DEFAULT_EXAMINATION_FAIL,
GET_DEFAULT_EXAMINATION_LOADING,
GET_DEFAULT_EXAMINATION_SUCCESS,
GET_LAST_EXAMINATION_FAIL,
GET_LAST_EXAMINATION_LOADING,
GET_LAST_EXAMINATION_SUCCESS,
Expand Down Expand Up @@ -96,6 +99,34 @@ export const deleteExaminationReset =
});
};

export const getDefaultPatientExamination =
(patId: number) =>
(dispatch: Dispatch<IAction<PatientExaminationDTO, {}>>): 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<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 @@ -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 =
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" },
getDefaultPatientExamination: { status: "IDLE" },
getLastByPatientId: { status: "IDLE" },
examinationsByPatientId: { status: "IDLE", data: [] },
deleteExamination: { status: "IDLE" },
Expand Down
23 changes: 23 additions & 0 deletions src/state/examinations/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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
*/
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>;
getDefaultPatientExamination: IApiResponse<PatientExaminationDTO>;
getLastByPatientId: IApiResponse<PatientExaminationDTO>;
examinationsByPatientId: IApiResponse<Array<PatientExaminationDTO>>;
deleteExamination: IApiResponse<null>;
Expand Down

0 comments on commit e214ce4

Please sign in to comment.