diff --git a/cypress/pageobject/Patient/PatientConsultation.ts b/cypress/pageobject/Patient/PatientConsultation.ts index 2eb6550cb8b..fb396e9f8a9 100644 --- a/cypress/pageobject/Patient/PatientConsultation.ts +++ b/cypress/pageobject/Patient/PatientConsultation.ts @@ -1,6 +1,6 @@ export class PatientConsultationPage { selectConsultationStatus(status: string) { - cy.get("#consultation_status") + cy.get("#route_to_facility") .click() .then(() => { cy.get("[role='option']").contains(status).click(); @@ -61,7 +61,7 @@ export class PatientConsultationPage { .click(); cy.get("#consultation_notes").click().type(consulationNotes); - cy.get("#verified_by") + cy.get("#treating_physician") .click() .type(verificationBy) .then(() => { diff --git a/src/Common/constants.tsx b/src/Common/constants.tsx index e51494f6bac..61a9cb5c8ba 100644 --- a/src/Common/constants.tsx +++ b/src/Common/constants.tsx @@ -332,14 +332,6 @@ export const CONSULTATION_SUGGESTION = [ { id: "DD", text: "Declare Death" }, ]; -export const CONSULTATION_STATUS = [ - { id: "1", text: "Brought Dead" }, - { id: "2", text: "Transferred from ward" }, - { id: "3", text: "Transferred from ICU" }, - { id: "4", text: "Referred from other hospital" }, - { id: "5", text: "Out-patient (walk in)" }, -]; - export const ADMITTED_TO = [ { id: "1", text: "Isolation" }, { id: "2", text: "ICU" }, diff --git a/src/Components/Common/RouteToFacilitySelect.tsx b/src/Components/Common/RouteToFacilitySelect.tsx new file mode 100644 index 00000000000..0f36d632e42 --- /dev/null +++ b/src/Components/Common/RouteToFacilitySelect.tsx @@ -0,0 +1,31 @@ +import { SelectFormField } from "../Form/FormFields/SelectFormField"; +import { + FormFieldBaseProps, + useFormFieldPropsResolver, +} from "../Form/FormFields/Utils"; + +export const ROUTE_TO_FACILITY_OPTIONS = { + 10: "Outpatient/Emergency Room", + 20: "Referred from another facility", + 30: "Internal Transfer within the facility", +}; + +export type RouteToFacility = keyof typeof ROUTE_TO_FACILITY_OPTIONS; + +export const keys = Object.keys(ROUTE_TO_FACILITY_OPTIONS).map((key) => + parseInt(key) +) as RouteToFacility[]; + +type Props = FormFieldBaseProps; + +export default function RouteToFacilitySelect(props: Props) { + const field = useFormFieldPropsResolver(props as any); + + return ( + ROUTE_TO_FACILITY_OPTIONS[key]} + /> + ); +} diff --git a/src/Components/Facility/ConsultationDetails/index.tsx b/src/Components/Facility/ConsultationDetails/index.tsx index 3d3271b16d5..f9f30b6df3b 100644 --- a/src/Components/Facility/ConsultationDetails/index.tsx +++ b/src/Components/Facility/ConsultationDetails/index.tsx @@ -430,14 +430,14 @@ export const ConsultationDetails = (props: any) => { label="Diagnosis (as per ICD-11 recommended by WHO)" /> - {(consultationData.verified_by_object || + {(consultationData.treating_physician_object || consultationData.deprecated_verified_by) && (
Treating Physician:{" "} - {consultationData.verified_by_object - ? `${consultationData.verified_by_object.first_name} ${consultationData.verified_by_object.last_name}` + {consultationData.treating_physician_object + ? `${consultationData.treating_physician_object.first_name} ${consultationData.treating_physician_object.last_name}` : consultationData.deprecated_verified_by}
diff --git a/src/Components/Facility/ConsultationForm.tsx b/src/Components/Facility/ConsultationForm.tsx index 01a5f02b7b1..8dae90d56de 100644 --- a/src/Components/Facility/ConsultationForm.tsx +++ b/src/Components/Facility/ConsultationForm.tsx @@ -2,7 +2,6 @@ import * as Notification from "../../Utils/Notifications.js"; import { BedModel, FacilityModel, ICD11DiagnosisModel } from "./models"; import { - CONSULTATION_STATUS, CONSULTATION_SUGGESTION, PATIENT_CATEGORIES, REVIEW_AT_CHOICES, @@ -61,6 +60,11 @@ import { useDispatch } from "react-redux"; import useVisibility from "../../Utils/useVisibility"; import dayjs from "../../Utils/dayjs"; import AutocompleteFormField from "../Form/FormFields/Autocomplete.js"; +import RouteToFacilitySelect, { + RouteToFacility, +} from "../Common/RouteToFacilitySelect.js"; +import { LocationSelect } from "../Common/LocationSelect.js"; +import { classNames } from "../../Utils/utils.js"; const Loading = lazy(() => import("../Common/Loading")); const PageTitle = lazy(() => import("../Common/PageTitle")); @@ -72,21 +76,26 @@ type FormDetails = { other_symptoms: string; symptoms_onset_date?: Date; suggestion: string; - consultation_status: number; + route_to_facility?: RouteToFacility; patient: string; facility: string; admitted: BooleanStrings; admitted_to: string; category: string; admission_date?: Date; + icu_admission_date?: Date; discharge_date: null; referred_to?: string; referred_to_external?: string; + referred_from_facility?: string; + referred_from_facility_external?: string; + referred_by_external?: string; + transferred_from_location?: string; icd11_diagnoses_object: ICD11DiagnosisModel[]; icd11_provisional_diagnoses_object: ICD11DiagnosisModel[]; icd11_principal_diagnosis?: ICD11DiagnosisModel["id"]; - verified_by: string; - verified_by_object: UserModel | null; + treating_physician: string; + treating_physician_object: UserModel | null; is_kasp: BooleanStrings; kasp_enabled_date: null; examination_details: string; @@ -118,21 +127,26 @@ const initForm: FormDetails = { other_symptoms: "", symptoms_onset_date: undefined, suggestion: "A", - consultation_status: 0, + route_to_facility: undefined, patient: "", facility: "", admitted: "false", admitted_to: "", category: "", admission_date: new Date(), + icu_admission_date: undefined, discharge_date: null, referred_to: "", referred_to_external: "", + referred_from_facility: "", + referred_from_facility_external: "", + referred_by_external: "", + transferred_from_location: "", icd11_diagnoses_object: [], icd11_provisional_diagnoses_object: [], icd11_principal_diagnosis: undefined, - verified_by: "", - verified_by_object: null, + treating_physician: "", + treating_physician_object: null, is_kasp: "false", kasp_enabled_date: null, examination_details: "", @@ -219,7 +233,9 @@ export const ConsultationForm = (props: any) => { initialState ); const [bed, setBed] = useState(null); - const [selectedFacility, setSelectedFacility] = + const [referredToFacility, setReferredToFacility] = + useState(null); + const [referredFromFacility, setReferredFromFacility] = useState(null); const [isLoading, setIsLoading] = useState(false); const [patientName, setPatientName] = useState(""); @@ -302,26 +318,13 @@ export const ConsultationForm = (props: any) => { const isOtherSymptomsSelected = state.form.symptoms.includes(9); const handleFormFieldChange: FieldChangeEventHandler = (event) => { - if (event.name === "consultation_status" && event.value === "1") { - dispatch({ - type: "set_form", - form: { - ...state.form, - consultation_status: 1, - symptoms: [1], - symptoms_onset_date: new Date(), - category: "Critical", - suggestion: "DD", - }, - }); - } else if (event.name === "suggestion" && event.value === "DD") { + if (event.name === "suggestion" && event.value === "DD") { dispatch({ type: "set_form", form: { ...state.form, suggestion: "DD", consultation_notes: "Patient declared dead", - verified_by: "Declared Dead", }, }); } else if ( @@ -360,8 +363,19 @@ export const ConsultationForm = (props: any) => { }); if (res.data.suggestion === "R") { if (res.data.referred_to_external) - setSelectedFacility({ id: -1, name: res.data.referred_to_external }); - else setSelectedFacility(res.data.referred_to_object); + setReferredToFacility({ + id: -1, + name: res.data.referred_to_external, + }); + else setReferredToFacility(res.data.referred_to_object); + } + if (res.data.route_to_facility === 20) { + if (res.data.referred_from_facility_external) + setReferredFromFacility({ + id: -1, + name: res.data.referred_from_facility_external, + }); + else setReferredFromFacility(res.data.referred_from_facility_object); } if (!status.aborted) { if (res?.data) { @@ -369,6 +383,7 @@ export const ConsultationForm = (props: any) => { ...res.data, symptoms_onset_date: isoStringToDate(res.data.symptoms_onset_date), admission_date: isoStringToDate(res.data.admission_date), + icu_admission_date: isoStringToDate(res.data.icu_admission_date), admitted: res.data.admitted ? String(res.data.admitted) : "false", admitted_to: res.data.admitted_to ? res.data.admitted_to : "", category: res.data.category @@ -381,8 +396,8 @@ export const ConsultationForm = (props: any) => { is_kasp: `${res.data.is_kasp}`, assigned_to: res.data.assigned_to || "", assigned_to_object: res.data.assigned_to_object, - verified_by: res.data.verified_by || "", - verified_by_object: res.data.verified_by_object, + treating_physician: res.data.treating_physician || "", + treating_physician_object: res.data.treating_physician_object, ett_tt: res.data.ett_tt ? Number(res.data.ett_tt) : 3, special_instruction: res.data.special_instruction || "", weight: res.data.weight ? res.data.weight : "", @@ -442,9 +457,9 @@ export const ConsultationForm = (props: any) => { invalidForm = true; } return; - case "consultation_status": + case "route_to_facility": if (!state.form[field]) { - errors[field] = "Please select the consultation status"; + errors[field] = "Field is required"; invalidForm = true; } return; @@ -508,15 +523,30 @@ export const ConsultationForm = (props: any) => { invalidForm = true; } return; + case "referred_from_facility": + if ( + state.form.route_to_facility === 20 && + !state.form[field] && + !state.form["referred_from_facility_external"] + ) { + errors[field] = "Please select the referred from facility"; + invalidForm = true; + } + return; + case "transferred_from_location": + if (state.form.route_to_facility === 30 && !state.form[field]) { + errors[field] = + "Name of Ward/ICU the patient is being transferred from is required"; + invalidForm = true; + } + return; case "consultation_notes": - if (state.form.consultation_status != 1) { - if (!state.form[field]) { - errors[field] = "Required *"; - invalidForm = true; - } else if (!state.form[field].replace(/\s/g, "").length) { - errors[field] = "Consultation notes can not be empty"; - invalidForm = true; - } + if (!state.form[field]) { + errors[field] = "Field is required"; + invalidForm = true; + } else if (!state.form[field].replace(/\s/g, "").length) { + errors[field] = "Consultation notes can not be empty"; + invalidForm = true; } return; case "is_telemedicine": @@ -579,7 +609,7 @@ export const ConsultationForm = (props: any) => { return; } - case "verified_by": { + case "treating_physician": { if (state.form.suggestion !== "DD" && !state.form[field]) { errors[field] = "Please fill treating physician"; invalidForm = true; @@ -701,7 +731,7 @@ export const ConsultationForm = (props: any) => { ? state.form.symptoms_onset_date : undefined, suggestion: state.form.suggestion, - consultation_status: Number(state.form.consultation_status), + route_to_facility: state.form.route_to_facility, admitted: state.form.suggestion === "A", admission_date: ["A", "DC"].includes(state.form.suggestion) ? state.form.admission_date @@ -722,7 +752,7 @@ export const ConsultationForm = (props: any) => { (o: ICD11DiagnosisModel) => o.id ), icd11_principal_diagnosis: state.form.icd11_principal_diagnosis, - verified_by: state.form.verified_by, + treating_physician: state.form.treating_physician, investigation: state.form.InvestigationAdvice, procedure: state.form.procedures, patient: patientId, @@ -735,6 +765,24 @@ export const ConsultationForm = (props: any) => { state.form.suggestion === "R" && !state.form.referred_to ? state.form.referred_to_external : undefined, + referred_from_facility: + state.form.route_to_facility === 20 && + !state.form.referred_from_facility_external + ? state.form.referred_from_facility + : undefined, + referred_from_facility_external: + state.form.route_to_facility === 20 && + !state.form.referred_from_facility + ? state.form.referred_from_facility_external + : undefined, + referred_by_external: + state.form.route_to_facility === 20 + ? state.form.referred_by_external + : undefined, + transferred_from_location: + state.form.route_to_facility === 30 + ? state.form.transferred_from_location + : undefined, consultation_notes: state.form.consultation_notes, is_telemedicine: state.form.is_telemedicine, action: state.form.action, @@ -833,9 +881,11 @@ export const ConsultationForm = (props: any) => { ); }; - const setFacility = (selected: FacilityModel | FacilityModel[] | null) => { + const handleReferredToFacilityChange = ( + selected: FacilityModel | FacilityModel[] | null + ) => { const selectedFacility = selected as FacilityModel; - setSelectedFacility(selectedFacility); + setReferredToFacility(selectedFacility); const form: FormDetails = { ...state.form }; if (selectedFacility?.id) { if (selectedFacility.id === -1) { @@ -849,6 +899,24 @@ export const ConsultationForm = (props: any) => { dispatch({ type: "set_form", form }); }; + const handleReferredFromFacilityChange = ( + selected: FacilityModel | FacilityModel[] | null + ) => { + const selectedFacility = selected as FacilityModel; + setReferredFromFacility(selectedFacility); + const form: FormDetails = { ...state.form }; + if (selectedFacility?.id) { + if (selectedFacility.id === -1) { + form.referred_from_facility_external = selectedFacility.name ?? ""; + delete form.referred_from_facility; + } else { + form.referred_from_facility = selectedFacility.id.toString() || ""; + delete form.referred_from_facility_external; + } + } + dispatch({ type: "set_form", form }); + }; + const field = (name: string) => { return { id: name, @@ -888,9 +956,6 @@ export const ConsultationForm = (props: any) => {
{Object.keys(sections).map((sectionTitle) => { - if (state.form.consultation_status === 1) { - return null; - } if (!isUpdate && sectionTitle === "Bed Status") { return null; } @@ -932,66 +997,119 @@ export const ConsultationForm = (props: any) => { {sectionTitle("Consultation Details")}
-
- {String(state.form.consultation_status) !== "1" && ( + {state.form.route_to_facility === 20 && ( <> -
- + + Name of the referring Facility + +
- {isOtherSymptomsSelected && ( -
- -
- )} - - {hasSymptoms && ( -
- -
- )}
-
)} + {state.form.route_to_facility === 30 && ( +
+ + Name of Ward/ICU the patient is shifted from + + + field("transferred_from_location").onChange({ + name: "transferred_from_location", + value: location, + }) + } + selected={field("transferred_from_location").value} + showAll={false} + multiple={false} + facilityId={facilityId} + errors={state.errors.transferred_from_location ?? ""} + /> +
+ )} + +
+ +
+ {isOtherSymptomsSelected && ( +
+ +
+ )} + + {hasSymptoms && ( +
+ +
+ )} +
+ +
+
{
- {String(state.form.consultation_status) !== "1" && ( -
- - A daily round already exists. -

- ) - } - required - label="Category" - {...field("category")} - /> -
- )} +
+ + A daily round already exists. +

+ ) + } + required + label="Category" + {...field("category")} + /> +
-
+
!deprecated )} @@ -1088,8 +1200,8 @@ export const ConsultationForm = (props: any) => { @@ -1140,40 +1252,74 @@ export const ConsultationForm = (props: any) => { )} {["A", "DC"].includes(state.form.suggestion) && ( - <> +
+ +
+ )} + + {state.form.route_to_facility && + [20, 30].includes(state.form.route_to_facility) && (
-
- - {!isUpdate && ( -
- Bed - -
- )} - + )} + + {["A", "DC"].includes(state.form.suggestion) && !isUpdate && ( +
+ Bed + +
)} +
{
- {String(state.form.consultation_status) !== "1" && ( + {sectionTitle("Treatment Plan")} + {state.form.suggestion !== "DD" && ( <> - {sectionTitle("Treatment Plan")} - {state.form.suggestion !== "DD" && ( - <> -
- Investigations Suggestions - { - handleFormFieldChange({ - name: "InvestigationAdvice", - value: investigations, - }); - }} - /> - -
-
- Procedures - { - handleFormFieldChange({ - name: "procedures", - value: procedures, - }); - }} - /> - -
-
- -
-
- -
- - {kasp_enabled && ( - - )} -
- -
-
- -
- -
-
- -
-
- option.desc} - optionDescription={() => ""} - /> -
-
- - + Investigations Suggestions + { + handleFormFieldChange({ + name: "InvestigationAdvice", + value: investigations, + }); + }} + /> + +
+
+ Procedures + { + handleFormFieldChange({ + name: "procedures", + value: procedures, + }); + }} + /> + +
+
+ +
+
+ +
+ + {kasp_enabled && ( + + )} +
+ +
+
+ +
+ +
+
+ +
+
+ option.desc} + optionDescription={() => ""} + /> +
+
- {JSON.parse(state.form.is_telemedicine) && ( -
- -
- )} - + + + {JSON.parse(state.form.is_telemedicine) && ( +
+ +
)} )} diff --git a/src/Components/Facility/models.tsx b/src/Components/Facility/models.tsx index de2c6af698a..d0c730bab39 100644 --- a/src/Components/Facility/models.tsx +++ b/src/Components/Facility/models.tsx @@ -3,6 +3,7 @@ import { ProcedureType } from "../Common/prescription-builder/ProcedureBuilder"; import { NormalPrescription, PRNPrescription } from "../Medicine/models"; import { AssetData } from "../Assets/AssetTypes"; import { UserBareMinimum } from "../Users/models"; +import { RouteToFacility } from "../Common/RouteToFacilitySelect"; export interface LocalBodyModel { name: string; @@ -83,6 +84,7 @@ export type PatientCategory = export interface ConsultationModel { admission_date?: string; + icu_admission_date?: string; admitted?: boolean; test_id?: string; admitted_to?: string; @@ -102,12 +104,18 @@ export interface ConsultationModel { other_symptoms?: string; patient?: string; treatment_plan?: string; - referred_to?: number | null; + referred_to?: FacilityModel["id"]; referred_to_object?: FacilityModel; referred_to_external?: string; + referred_from_facility?: FacilityModel["id"]; + referred_from_facility_object?: FacilityModel; + referred_from_facility_external?: string; + referred_by_external?: string; + transferred_from_location?: LocationModel["id"]; + transferred_from_location_object?: LocationModel; suggestion?: string; patient_no?: string; - consultation_status?: number; + route_to_facility?: RouteToFacility; is_kasp?: boolean; kasp_enabled_date?: string; diagnosis?: string; @@ -115,8 +123,8 @@ export interface ConsultationModel { icd11_provisional_diagnoses_object?: ICD11DiagnosisModel[]; icd11_principal_diagnosis?: ICD11DiagnosisModel["id"]; deprecated_verified_by?: string; - verified_by?: string; - verified_by_object?: UserBareMinimum; + treating_physician?: UserBareMinimum["id"]; + treating_physician_object?: UserBareMinimum; suggestion_text?: string; symptoms?: Array; symptoms_text?: string;