From ca68d0279dbd727db596c14fc2e2961b794716da Mon Sep 17 00:00:00 2001 From: cp-Coder Date: Sat, 25 Feb 2023 19:44:34 +0530 Subject: [PATCH 1/6] feat(consultation): added health and medical history fields in consultation form --- src/Common/constants.tsx | 28 +- src/Components/Common/DiseaseSelect.tsx | 37 ++ .../prescription-builder/DiseaseBuilder.tsx | 122 ++++++ .../PrescriptionDropdown.tsx | 2 +- .../VaccinationBuilder.tsx | 148 ++++++++ .../prescription-builder/assets/vaccines.json | 9 + .../Facility/ConsultationDetails.tsx | 9 +- src/Components/Facility/ConsultationForm.tsx | 153 +++++++- src/Components/Facility/models.tsx | 30 ++ src/Components/Patient/PatientHome.tsx | 212 +++++++---- src/Components/Patient/PatientRegister.tsx | 359 +----------------- 11 files changed, 654 insertions(+), 455 deletions(-) create mode 100644 src/Components/Common/DiseaseSelect.tsx create mode 100644 src/Components/Common/prescription-builder/DiseaseBuilder.tsx create mode 100644 src/Components/Common/prescription-builder/VaccinationBuilder.tsx create mode 100644 src/Components/Common/prescription-builder/assets/vaccines.json diff --git a/src/Common/constants.tsx b/src/Common/constants.tsx index 5fef5799b68..60b6a845188 100644 --- a/src/Common/constants.tsx +++ b/src/Common/constants.tsx @@ -430,26 +430,16 @@ export const TEST_TYPE = [ "POCPCR", ]; -export const VACCINES = [ - "CoviShield", - "Covaxin", - "Sputnik", - "Moderna", - "Pfizer", - "Janssen", - "Sinovac", -]; - export const BLOOD_GROUPS = [ - "UNK", - "A+", - "A-", - "B+", - "B-", - "AB+", - "AB-", - "O+", - "O-", + { id: 0, text: "UNK" }, + { id: 1, text: "A+" }, + { id: 2, text: "A-" }, + { id: 3, text: "B+" }, + { id: 4, text: "B-" }, + { id: 5, text: "AB+" }, + { id: 6, text: "AB-" }, + { id: 7, text: "O+" }, + { id: 8, text: "O-" }, ]; export const SAMPLE_TYPE_CHOICES = [ diff --git a/src/Components/Common/DiseaseSelect.tsx b/src/Components/Common/DiseaseSelect.tsx new file mode 100644 index 00000000000..c2a4333f40b --- /dev/null +++ b/src/Components/Common/DiseaseSelect.tsx @@ -0,0 +1,37 @@ +import { useCallback } from "react"; +import { useDispatch } from "react-redux"; +import { listICD11Diagnosis } from "../../Redux/actions"; +import { ICD11DiagnosisModel } from "../Facility/models"; +import AutoCompleteAsync from "../Form/AutoCompleteAsync"; + +interface DiagnosisSelectProps { + name: string; + errors?: string; + selected?: string; + setSelected: (selected: string) => void; +} + +export const DiseaseSelect = (props: DiagnosisSelectProps) => { + const { name, selected, setSelected, errors } = props; + const dispatch: any = useDispatch(); + + const fetchDisease = useCallback( + async (search: string) => { + const res = await dispatch(listICD11Diagnosis({ query: search }, "")); + return res?.data; + }, + [dispatch] + ); + + return ( + setSelected(selected.label)} + placeholder="Search disease" + optionLabel={(option: ICD11DiagnosisModel) => option?.label || ""} + error={errors} + /> + ); +}; diff --git a/src/Components/Common/prescription-builder/DiseaseBuilder.tsx b/src/Components/Common/prescription-builder/DiseaseBuilder.tsx new file mode 100644 index 00000000000..abc727c1efb --- /dev/null +++ b/src/Components/Common/prescription-builder/DiseaseBuilder.tsx @@ -0,0 +1,122 @@ +import { DiseaseSelect } from "../DiseaseSelect"; + +interface DiseaseBuilderProps { + diseases: T[]; + setDiseases: React.Dispatch>; +} + +export type DiseaseDetails = { + disease?: string; + details?: string; + date?: string; + precision?: number; +}; + +export const emptyValues = { + disease: "", + details: "", + date: "", + precision: 0, +}; + +export default function DiseaseBuilder( + props: DiseaseBuilderProps +) { + const { diseases, setDiseases } = props; + + const setItem = (object: DiseaseDetails, i: number) => { + setDiseases( + diseases.map((disease, index) => (index === i ? object : disease)) + ); + }; + + return ( +
+ {diseases.map((disease, i) => { + const setDisease = (selected: string) => { + setItem( + { + ...disease, + disease: selected, + }, + i + ); + }; + + return ( +
+
+
+ Disease + +
+
+ Details + { + setItem( + { + ...disease, + details: e.target.value, + }, + i + ); + }} + required + /> +
+
+ Date + { + setItem( + { + ...disease, + date: e.target.value, + }, + i + ); + }} + required + /> +
+ +
+
+ ); + })} + +
+ ); +} diff --git a/src/Components/Common/prescription-builder/PrescriptionDropdown.tsx b/src/Components/Common/prescription-builder/PrescriptionDropdown.tsx index 1676cb6702a..339ad7805ad 100644 --- a/src/Components/Common/prescription-builder/PrescriptionDropdown.tsx +++ b/src/Components/Common/prescription-builder/PrescriptionDropdown.tsx @@ -51,7 +51,7 @@ export function PrescriptionDropdown(props: {
diff --git a/src/Components/Common/prescription-builder/VaccinationBuilder.tsx b/src/Components/Common/prescription-builder/VaccinationBuilder.tsx new file mode 100644 index 00000000000..6d883fa0613 --- /dev/null +++ b/src/Components/Common/prescription-builder/VaccinationBuilder.tsx @@ -0,0 +1,148 @@ +import { PrescriptionDropdown } from "./PrescriptionDropdown"; + +import vaccines from "./assets/vaccines.json"; +import CareIcon from "../../../CAREUI/icons/CareIcon"; +import { useState } from "react"; + +interface VaccinationBuilderProps { + vaccinations: T[]; + setVaccinations: React.Dispatch>; +} + +export type VaccinationDetails = { + vaccine?: string; + doses?: number; + date?: string; + precision?: number; +}; + +export const emptyValues = { + vaccine: "", + doses: 0, + date: "", + precision: 0, +}; + +export default function VaccinationBuilder( + props: VaccinationBuilderProps +) { + const { vaccinations, setVaccinations } = props; + + const setItem = (object: VaccinationDetails, i: number) => { + setVaccinations( + vaccinations.map((vaccination, index) => + index === i ? object : vaccination + ) + ); + }; + + const [activeIdx, setActiveIdx] = useState(null); + + return ( +
+ {vaccinations.map((vaccination, i) => { + const setVaccine = (vaccine: string) => { + setItem( + { + ...vaccination, + vaccine, + }, + i + ); + }; + + return ( +
+
+

+ Vaccine No. {i + 1} +

+ +
+
+
+ Vaccine + setActiveIdx(i)} + onBlur={() => setActiveIdx(null)} + /> +
+
+ Doses + { + let value = parseInt(e.target.value); + if (value < 0) { + value = 0; + } + setItem( + { + ...vaccination, + doses: value, + }, + i + ); + }} + required + /> +
+
+ Date + { + setItem( + { + ...vaccination, + date: e.target.value, + }, + i + ); + }} + required + /> +
+
+
+ ); + })} + +
+ ); +} diff --git a/src/Components/Common/prescription-builder/assets/vaccines.json b/src/Components/Common/prescription-builder/assets/vaccines.json new file mode 100644 index 00000000000..5d0d1fbf8e9 --- /dev/null +++ b/src/Components/Common/prescription-builder/assets/vaccines.json @@ -0,0 +1,9 @@ +[ + "CoviShield", + "Covaxin", + "Sputnik", + "Moderna", + "Pfizer", + "Janssen", + "Sinovac" +] \ No newline at end of file diff --git a/src/Components/Facility/ConsultationDetails.tsx b/src/Components/Facility/ConsultationDetails.tsx index a401412dcba..eb4418d1a5f 100644 --- a/src/Components/Facility/ConsultationDetails.tsx +++ b/src/Components/Facility/ConsultationDetails.tsx @@ -768,7 +768,14 @@ export const ConsultationDetails = (props: any) => { ]} label="Diagnosis (as per ICD-11 recommended by WHO)" /> - + {consultationData?.health_details_object?.allergies && ( +
+ + Allergies:{" "} + + {consultationData?.health_details_object?.allergies} +
+ )} {consultationData.verified_by && (
diff --git a/src/Components/Facility/ConsultationForm.tsx b/src/Components/Facility/ConsultationForm.tsx index 043f9045d5c..2c410ca7c0c 100644 --- a/src/Components/Facility/ConsultationForm.tsx +++ b/src/Components/Facility/ConsultationForm.tsx @@ -45,6 +45,8 @@ import InvestigationBuilder, { import ProcedureBuilder, { ProcedureType, } from "../Common/prescription-builder/ProcedureBuilder"; +import { VaccinationDetails } from "../Common/prescription-builder/VaccinationBuilder"; +import { DiseaseDetails } from "../Common/prescription-builder/DiseaseBuilder"; import { ICD11DiagnosisModel } from "./models"; import { Cancel, Submit } from "../Common/components/ButtonV2"; import TextAreaFormField from "../Form/FormFields/TextAreaFormField"; @@ -106,13 +108,33 @@ type FormDetails = { assigned_to_object: UserModel | null; special_instruction: string; review_interval: number; - weight: string; - height: string; bed: BedModel | null; discharge_reason: string; cause_of_death: string; death_datetime: string; death_confirmed_doctor: string; + // Health Details + family_details: string; + has_allergy: BooleanStrings; + allergies: string; + blood_group: string; + height: number; + weight: number; + vaccination_history: { + vaccine: string; + doses: number; + date: string; + precision: number; + }[]; + // Medical History + ongoing_medication: string; + present_health: string; + patient_diseases: { + disease: string; + details: string; + date: string; + precision: number; + }[]; }; type Action = @@ -155,13 +177,21 @@ const initForm: FormDetails = { assigned_to_object: null, special_instruction: "", review_interval: -1, - weight: "", - height: "", bed: null, discharge_reason: "", cause_of_death: "", death_datetime: "", death_confirmed_doctor: "", + family_details: "", + has_allergy: "false", + allergies: "", + blood_group: "", + height: 0.0, + weight: 0.0, + vaccination_history: [], + ongoing_medication: "", + present_health: "", + patient_diseases: [], }; const initError = Object.assign( @@ -221,6 +251,8 @@ export const ConsultationForm = (props: any) => { InvestigationType[] >([]); const [procedures, setProcedures] = useState([]); + const [vaccination, setVaccination] = useState([]); + const [diseases, setDiseases] = useState([]); const [selectedFacility, setSelectedFacility] = useState(null); @@ -298,6 +330,17 @@ export const ConsultationForm = (props: any) => { setSelectedFacility({ id: -1, name: res.data.referred_to_external }); else setSelectedFacility(res.data.referred_to_object); } + setVaccination( + !Array.isArray(res.data.health_details_object?.vaccination_history) + ? [] + : res.data.health_details_object?.vaccination_history + ); + setDiseases( + !Array.isArray(res.data.medical_history_object?.patient_diseases) + ? [] + : res.data.medical_history_object?.patient_diseases + ); + if (!status.aborted) { if (res && res.data) { const formData = { @@ -308,7 +351,7 @@ export const ConsultationForm = (props: any) => { admitted_to: res.data.admitted_to ? res.data.admitted_to : "", category: res.data.category ? PATIENT_CATEGORIES.find((i) => i.text === res.data.category) - ?.id || "Comfort" + ?.id || "Comfort" : "Comfort", ip_no: res.data.ip_no ? res.data.ip_no : "", op_no: res.data.op_no ? res.data.op_no : "", @@ -319,13 +362,26 @@ export const ConsultationForm = (props: any) => { assigned_to: res.data.assigned_to || "", 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 : "", - height: res.data.height ? res.data.height : "", bed: res.data?.current_bed?.bed_object || null, discharge_reason: res.data?.discharge_reason || "", cause_of_death: res.data?.discharge_notes || "", death_datetime: res.data?.death_datetime || "", death_confirmed_doctor: res.data?.death_confirmed_doctor || "", + family_details: + res.data.health_details_object?.family_details || "", + has_allergy: + `${res.data.health_details_object?.has_allergy}` || "false", + allergies: res.data.health_details_object?.allergies || "", + blood_group: res.data.health_details_object?.blood_group + ? res.data.health_details_object?.blood_group === "UNKNOWN" + ? "UNK" + : res.data.health_details_object?.blood_group + : "", + height: res.data.health_details_object?.height || 0.0, + weight: res.data.health_details_object?.weight || 0.0, + ongoing_medication: + res.data.medical_history_object?.ongoing_medication, + present_health: res.data.medical_history_object?.present_health, }; dispatch({ type: "set_form", form: formData }); setBed(formData.bed); @@ -561,6 +617,65 @@ export const ConsultationForm = (props: any) => { return; } + case "blood_group": + if (!state.form[field]) { + errors[field] = "Please select a blood group"; + invalidForm = true; + } + return; + + case "has_allergy": + if (state.form.has_allergy === "true") { + if (state.form.allergies === "") { + errors["allergies"] = "Please enter Patient's allergies"; + invalidForm = true; + } + } + return; + + case "vaccination_history": { + let invalid = false; + for (const f of vaccination) { + if ( + !f.vaccine?.replace(/\s/g, "").length || + !f.date?.replace(/\s/g, "").length + ) { + invalid = true; + break; + } + } + if (invalid) { + errors[field] = "Vaccination field can not be empty"; + invalidForm = true; + } + return; + } + case "patient_diseases": { + let invalid = false; + for (const f of diseases) { + if ( + !f.disease?.replace(/\s/g, "").length || + !f.details?.replace(/\s/g, "").length || + !f.date?.replace(/\s/g, "").length + ) { + invalid = true; + break; + } + } + if (invalid) { + errors[field] = "Disease field can not be empty"; + invalidForm = true; + } + return; + } + case "weight": + case "height": + if (!state.form[field]) { + errors[field] = "Please enter a value"; + invalidForm = true; + } + return; + default: return; } @@ -661,6 +776,23 @@ export const ConsultationForm = (props: any) => { weight: Number(state.form.weight), height: Number(state.form.height), bed: bed && bed instanceof Array ? bed[0]?.id : bed?.id, + new_health_details: { + family_details: state.form.family_details, + has_allergy: state.form.has_allergy, + allergies: + state.form.has_allergy === "true" ? state.form.allergies : "", + blood_group: state.form.blood_group + ? state.form.blood_group + : undefined, + height: state.form.height, + weight: state.form.weight, + vaccination_history: vaccination, + }, + new_medical_history: { + ongoing_medication: state.form.ongoing_medication, + present_health: state.form.present_health, + patient_diseases: diseases, + }, }; const res = await dispatchAction( @@ -845,9 +977,8 @@ export const ConsultationForm = (props: any) => { const section = sections[sectionTitle as ConsultationFormSection]; return (
- {patientData.date_of_return && ( -
-
- Date of Return -
-
- {formatDate(patientData.date_of_return)} -
+
+
+ Blood Group
- )} - {patientData.is_vaccinated && !!patientData.number_of_doses && ( -
-
- Number of vaccine doses -
-
- {patientData.number_of_doses} -
+
+ {consultationListData.at(-1)?.health_details_object + ?.blood_group || "-"}
- )} - {patientData.is_vaccinated && patientData.vaccine_name && ( -
-
- Vaccine name -
-
- {patientData.vaccine_name} -
+
+
+
+ Vaccines
- )} - {patientData.is_vaccinated && patientData.last_vaccinated_date && ( +
+ {consultationListData + .at(-1) + ?.health_details_object?.vaccination_history?.map( + (vaccines) => vaccines.vaccine + ) + .join(", ") || "-"} +
+
+ {patientData.date_of_return && (
- Last Vaccinated on + Date of Return
- {formatDate(patientData.last_vaccinated_date)} + {formatDate(patientData.date_of_return)}
)} @@ -673,6 +642,71 @@ export const PatientHome = (props: any) => {
)}
+
+ {patientData.is_vaccinated ? ( + + ) : ( + + )} + {patientData.allow_transfer ? ( + + ) : ( + + )} + {patientData.gender === 2 && + patientData.is_antenatal && + patientData.is_active && ( + + )} + {patientData.contact_with_confirmed_carrier && ( + + )} + {patientData.contact_with_suspected_carrier && ( + + )} + {patientData.past_travel && ( + + )} + {patientData.last_consultation?.is_telemedicine && ( + + )} + {consultationListData.at(-1)?.health_details_object + ?.allergies && ( + + )} +
@@ -1074,45 +1108,37 @@ export const PatientHome = (props: any) => {
Medical
- {!patientData.present_health && - !patientData.allergies && - !patientData.ongoing_medication && - !(patientData.gender === 2 && patientData.is_antenatal) && - !patientData.medical_history?.some( - (history) => history.disease !== "NO" - ) && ( -
- No Medical History Available -
- )} -
- {patientData.present_health && ( + {!consultationListData.at(-1)?.medical_history_object && ( +
+ No Medical History Available +
+ )} +
+ {consultationListData.at(-1)?.medical_history_object + ?.present_health && (
-
- Present Health +
+ Present Health Condition
-
- {patientData.present_health} +
+ { + consultationListData.at(-1)?.medical_history_object + ?.present_health + }
)} - {patientData.ongoing_medication && ( + {consultationListData.at(-1)?.medical_history_object + ?.ongoing_medication && (
Ongoing Medications
-
- {patientData.ongoing_medication} -
-
- )} - {patientData.allergies && ( -
-
- Allergies -
-
- {patientData.allergies} +
+ { + consultationListData.at(-1)?.medical_history_object + ?.ongoing_medication + }
)} @@ -1126,7 +1152,25 @@ export const PatientHome = (props: any) => {
)} - {patientMedHis} +
+
+
+
+
+
+ Family Details +
+ {!consultationListData.at(-1)?.health_details_object + ?.family_details && ( +
+ No Family Details Available +
+ )} +
+ { + consultationListData.at(-1)?.health_details_object + ?.family_details + }
diff --git a/src/Components/Patient/PatientRegister.tsx b/src/Components/Patient/PatientRegister.tsx index 919a27ef2d6..ae6534409df 100644 --- a/src/Components/Patient/PatientRegister.tsx +++ b/src/Components/Patient/PatientRegister.tsx @@ -15,12 +15,9 @@ import loadable from "@loadable/component"; import { useCallback, useReducer, useState, useEffect } from "react"; import { useDispatch } from "react-redux"; import { - BLOOD_GROUPS, DISEASE_STATUS, GENDER_TYPES, - MEDICAL_HISTORY_CHOICES, TEST_TYPE, - VACCINES, } from "../../Common/constants"; import countryList from "../../Common/static/countries.json"; import { statusType, useAbortableEffect } from "../../Common/utils"; @@ -42,7 +39,6 @@ import AlertDialog from "../Common/AlertDialog"; import { LegacyCheckboxField, LegacyDateInputField, - LegacyErrorHelperText, LegacySelectField, LegacyTextInputField, } from "../Common/HelperInputFields"; @@ -82,24 +78,15 @@ interface PatientRegisterProps extends PatientModel { facilityId: number; } -interface medicalHistoryModel { - id?: number; - disease: string | number; - details: string; -} - -const medicalHistoryChoices = MEDICAL_HISTORY_CHOICES.reduce( - (acc: Array<{ [x: string]: string }>, cur) => [ - ...acc, - { [`medical_history_${cur.id}`]: "" }, - ], - [] -); -const genderTypes = GENDER_TYPES; +const genderTypes = [ + { + id: 0, + text: "Select", + }, + ...GENDER_TYPES, +]; const diseaseStatus = [...DISEASE_STATUS]; -const bloodGroups = [...BLOOD_GROUPS]; const testType = [...TEST_TYPE]; -const vaccines = ["Select", ...VACCINES]; const initForm: any = { name: "", @@ -122,15 +109,12 @@ const initForm: any = { address: "", permanent_address: "", village: "", - allergies: "", pincode: "", present_health: "", contact_with_confirmed_carrier: "false", contact_with_suspected_carrier: "false", - estimated_contact_date: null, date_of_return: null, - number_of_primary_contacts: "", number_of_secondary_contacts: "", is_antenatal: "false", @@ -146,10 +130,6 @@ const initForm: any = { cluster_name: "", covin_id: "", is_vaccinated: "false", - number_of_doses: "0", - vaccine_name: null, - last_vaccinated_date: null, - ...medicalHistoryChoices, }; const initError = Object.assign( @@ -327,7 +307,6 @@ export const PatientRegister = (props: PatientRegisterProps) => { ? res.data.test_id : state.form.test_id; form["srf_id"] = res.data.srf_id ? res.data.srf_id : state.form.srf_id; - form["state"] = res.data.district_object ? res.data.district_object.state : state.form.state; @@ -385,22 +364,15 @@ export const PatientRegister = (props: PatientRegisterProps) => { cluster_name: res.data.cluster_name ? res.data.cluster_name : "", state: res.data.state ? res.data.state : "", district: res.data.district ? res.data.district : "", - blood_group: res.data.blood_group - ? res.data.blood_group === "UNKNOWN" - ? "UNK" - : res.data.blood_group - : "", local_body: res.data.local_body ? res.data.local_body : "", ward: res.data.ward_object ? res.data.ward_object.id : undefined, village: res.data.village ? res.data.village : "", - medical_history: [], is_antenatal: String(!!res.data.is_antenatal), allergies: res.data.allergies ? res.data.allergies : "", pincode: res.data.pincode ? res.data.pincode : "", ongoing_medication: res.data.ongoing_medication ? res.data.ongoing_medication : "", - is_declared_positive: res.data.is_declared_positive ? String(res.data.is_declared_positive) : "false", @@ -412,7 +384,6 @@ export const PatientRegister = (props: PatientRegisterProps) => { .instituion_of_health_care_worker ? res.data.instituion_of_health_care_worker : "", - number_of_primary_contacts: res.data.number_of_primary_contacts ? res.data.number_of_primary_contacts : "", @@ -428,27 +399,10 @@ export const PatientRegister = (props: PatientRegisterProps) => { ? String(res.data.contact_with_suspected_carrier) : "false", is_vaccinated: String(res.data.is_vaccinated), - number_of_doses: res.data.number_of_doses - ? String(res.data.number_of_doses) - : "0", - vaccine_name: res.data.vaccine_name ? res.data.vaccine_name : null, - last_vaccinated_date: res.data.last_vaccinated_date - ? res.data.last_vaccinated_date - : null, }; if (res.data.address !== res.data.permanent_address) { setSameAddress(false); } - res.data.medical_history.forEach((i: any) => { - const medicalHistory = MEDICAL_HISTORY_CHOICES.find( - (j: any) => - String(j.text).toLowerCase() === String(i.disease).toLowerCase() - ); - if (medicalHistory) { - formData.medical_history.push(medicalHistory.id); - formData[`medical_history_${medicalHistory.id}`] = i.details; - } - }); dispatch({ type: "set_form", form: formData, @@ -650,39 +604,6 @@ export const PatientRegister = (props: PatientRegisterProps) => { } } return; - case "blood_group": - if (!state.form[field]) { - errors[field] = "Please select a blood group"; - if (!error_div) error_div = field; - invalidForm = true; - } - return; - - case "is_vaccinated": - if (state.form.is_vaccinated === "true") { - if (state.form.number_of_doses === "0") { - errors["number_of_doses"] = - "Please fill the number of doses taken"; - if (!error_div) error_div = field; - invalidForm = true; - } - if ( - state.form.vaccine_name === null || - state.form.vaccine_name === "Select" - ) { - errors["vaccine_name"] = "Please select vaccine name"; - if (!error_div) error_div = field; - invalidForm = true; - } - - if (!state.form.last_vaccinated_date) { - errors["last_vaccinated_date"] = - "Please enter last vaccinated date"; - if (!error_div) error_div = field; - invalidForm = true; - } - } - return; case "date_of_result": if (state.form[field] < state.form.date_of_test) { @@ -771,17 +692,6 @@ export const PatientRegister = (props: PatientRegisterProps) => { scrollTo(error_div); } else { setIsLoading(true); - const medical_history: Array = []; - state.form.medical_history.forEach((id: number) => { - const medData = MEDICAL_HISTORY_CHOICES.find((i) => i.id === id); - if (medData) { - const details = state.form[`medical_history_${medData.id}`]; - medical_history.push({ - disease: medData.text, - details: details ? details : "", - }); - } - }); const data = { phone_number: parsePhoneNumberFromString( state.form.phone_number @@ -799,7 +709,7 @@ export const PatientRegister = (props: PatientRegisterProps) => { : undefined, date_declared_positive: JSON.parse(state.form.is_declared_positive) && - state.form.date_declared_positive + state.form.date_declared_positive ? state.form.date_declared_positive : null, test_id: state.form.test_id, @@ -807,22 +717,6 @@ export const PatientRegister = (props: PatientRegisterProps) => { covin_id: state.form.is_vaccinated === "true" ? state.form.covin_id : undefined, is_vaccinated: state.form.is_vaccinated, - number_of_doses: - state.form.is_vaccinated === "true" - ? Number(state.form.number_of_doses) - : Number("0"), - vaccine_name: - state.form.vaccine_name && - state.form.vaccine_name !== "Select" && - state.form.is_vaccinated === "true" - ? state.form.vaccine_name - : null, - last_vaccinated_date: - state.form.is_vaccinated === "true" - ? state.form.last_vaccinated_date - ? state.form.last_vaccinated_date - : null - : null, test_type: state.form.test_type, name: state.form.name, pincode: state.form.pincode ? state.form.pincode : undefined, @@ -847,8 +741,8 @@ export const PatientRegister = (props: PatientRegisterProps) => { permanent_address: sameAddress ? state.form.address : state.form.permanent_address - ? state.form.permanent_address - : undefined, + ? state.form.permanent_address + : undefined, present_health: state.form.present_health ? state.form.present_health : undefined, @@ -861,13 +755,13 @@ export const PatientRegister = (props: PatientRegisterProps) => { estimated_contact_date: (JSON.parse(state.form.contact_with_confirmed_carrier) || JSON.parse(state.form.contact_with_suspected_carrier)) && - state.form.estimated_contact_date + state.form.estimated_contact_date ? state.form.estimated_contact_date : null, cluster_name: (JSON.parse(state.form.contact_with_confirmed_carrier) || JSON.parse(state.form.contact_with_suspected_carrier)) && - state.form.cluster_name + state.form.cluster_name ? state.form.cluster_name : null, allergies: state.form.allergies, @@ -887,10 +781,6 @@ export const PatientRegister = (props: PatientRegisterProps) => { state.form.designation_of_health_care_worker, instituion_of_health_care_worker: state.form.instituion_of_health_care_worker, - blood_group: state.form.blood_group - ? state.form.blood_group - : undefined, - medical_history, is_active: true, }; const res = await dispatchAction( @@ -909,14 +799,14 @@ export const PatientRegister = (props: PatientRegisterProps) => { }; const policyRes = await (policy.id ? dispatchAction( - HCXActions.policies.update( - policy.id, - policy as HCXPolicyModel - ) + HCXActions.policies.update( + policy.id, + policy as HCXPolicyModel ) + ) : dispatchAction( - HCXActions.policies.create(policy as HCXPolicyModel) - )); + HCXActions.policies.create(policy as HCXPolicyModel) + )); if (enable_hcx) { const eligibilityCheckRes = await dispatchAction( @@ -1000,18 +890,6 @@ export const PatientRegister = (props: PatientRegisterProps) => { } }; - const handleMedicalCheckboxChange = (e: any, id: number) => { - const form = { ...state.form }; - const values = state.form.medical_history; - if (e.target.checked) { - values.push(id); - } else { - values.splice(values.indexOf(id), 1); - } - form["medical_history"] = values; - dispatch({ type: "set_form", form }); - }; - const duplicateCheck = useCallback( debounce(async (phoneNo: string) => { if (phoneNo && parsePhoneNumberFromString(phoneNo)?.isPossible()) { @@ -1023,8 +901,8 @@ export const PatientRegister = (props: PatientRegisterProps) => { const duplicateList = !id ? res.data.results : res.data.results.filter( - (item: DupPatientModel) => item.patient_id !== id - ); + (item: DupPatientModel) => item.patient_id !== id + ); if (duplicateList.length) { setStatusDialog({ show: true, @@ -1047,35 +925,6 @@ export const PatientRegister = (props: PatientRegisterProps) => { } }; - const renderMedicalHistory = (id: number, title: string) => { - const checkboxField = `medical_history_check_${id}`; - const textField = `medical_history_${id}`; - return ( -
-
- handleMedicalCheckboxChange(e, id)} - name={checkboxField} - label={id !== 1 ? title : "NONE"} - /> -
- {id !== 1 && state.form.medical_history.includes(id) && ( -
- -
- )} -
- ); - }; - if (isLoading) { return ; } @@ -1606,88 +1455,6 @@ export const PatientRegister = (props: PatientRegisterProps) => { errors={state.errors.covin_id} />
-
- - Number of doses - - -
- } - label="1" - /> - } - label="2" - /> - } - label="3 (Booster/Precautionary Dose)" - /> -
-
- -
-
- - Vaccine Name - - -
-
- - Last Date of Vaccination - - - handleDateChange( - date, - "last_vaccinated_date" - ) - } - errors={state.errors.last_vaccinated_date} - inputVariant="outlined" - margin="dense" - openTo="year" - disableFuture={true} - /> -
} @@ -2012,92 +1779,6 @@ export const PatientRegister = (props: PatientRegisterProps) => { - - -

- Medical History -

-
-
- - Present Health Condition - - -
- -
- - Ongoing Medication - - -
-
- - Any medical history? (Comorbidities) - -
- {MEDICAL_HISTORY_CHOICES.map((i) => { - return renderMedicalHistory(i.id, i.text); - })} -
- -
- -
- - Allergies - - -
- -
- o} - onChange={handleFormFieldChange} - error={state.errors.blood_group} - /> -
-
-
-

From 7879491776dc9ac4dbd0581180aebad7cba08377 Mon Sep 17 00:00:00 2001 From: cp-Coder Date: Sat, 25 Feb 2023 22:53:14 +0530 Subject: [PATCH 2/6] fix(consultation): updated vaccine and disease builder --- src/Components/Common/DiseaseSelect.tsx | 37 ------ .../prescription-builder/DiseaseBuilder.tsx | 123 +++++++++++------- .../PrescriptionDropdown.tsx | 2 +- .../VaccinationBuilder.tsx | 117 +++++++++-------- 4 files changed, 143 insertions(+), 136 deletions(-) delete mode 100644 src/Components/Common/DiseaseSelect.tsx diff --git a/src/Components/Common/DiseaseSelect.tsx b/src/Components/Common/DiseaseSelect.tsx deleted file mode 100644 index c2a4333f40b..00000000000 --- a/src/Components/Common/DiseaseSelect.tsx +++ /dev/null @@ -1,37 +0,0 @@ -import { useCallback } from "react"; -import { useDispatch } from "react-redux"; -import { listICD11Diagnosis } from "../../Redux/actions"; -import { ICD11DiagnosisModel } from "../Facility/models"; -import AutoCompleteAsync from "../Form/AutoCompleteAsync"; - -interface DiagnosisSelectProps { - name: string; - errors?: string; - selected?: string; - setSelected: (selected: string) => void; -} - -export const DiseaseSelect = (props: DiagnosisSelectProps) => { - const { name, selected, setSelected, errors } = props; - const dispatch: any = useDispatch(); - - const fetchDisease = useCallback( - async (search: string) => { - const res = await dispatch(listICD11Diagnosis({ query: search }, "")); - return res?.data; - }, - [dispatch] - ); - - return ( - setSelected(selected.label)} - placeholder="Search disease" - optionLabel={(option: ICD11DiagnosisModel) => option?.label || ""} - error={errors} - /> - ); -}; diff --git a/src/Components/Common/prescription-builder/DiseaseBuilder.tsx b/src/Components/Common/prescription-builder/DiseaseBuilder.tsx index abc727c1efb..7f1b5e8d702 100644 --- a/src/Components/Common/prescription-builder/DiseaseBuilder.tsx +++ b/src/Components/Common/prescription-builder/DiseaseBuilder.tsx @@ -1,4 +1,8 @@ -import { DiseaseSelect } from "../DiseaseSelect"; +import { useCallback, useState } from "react"; +import { useDispatch } from "react-redux"; +import CareIcon from "../../../CAREUI/icons/CareIcon"; +import { listICD11Diagnosis } from "../../../Redux/actions"; +import AutoCompleteAsync from "../../Form/AutoCompleteAsync"; interface DiseaseBuilderProps { diseases: T[]; @@ -23,6 +27,17 @@ export default function DiseaseBuilder( props: DiseaseBuilderProps ) { const { diseases, setDiseases } = props; + const dispatch: any = useDispatch(); + const fetchDisease = useCallback( + async (search: string) => { + const res = await dispatch(listICD11Diagnosis({ query: search }, "")); + return (res?.data as Array).reduce( + (disease, cur) => disease.concat(cur.label), + [] + ); + }, + [dispatch] + ); const setItem = (object: DiseaseDetails, i: number) => { setDiseases( @@ -30,44 +45,69 @@ export default function DiseaseBuilder( ); }; + const [activeIdx, setActiveIdx] = useState(null); + return (
- {diseases.map((disease, i) => { - const setDisease = (selected: string) => { - setItem( - { - ...disease, - disease: selected, - }, - i - ); - }; - - return ( -
-
-
+ {diseases.map((cur, i) => ( +
+
+

+ Disease No. {i + 1} +

+ +
+
+
+
Disease - + {" *"}
-
- Details + option} + onChange={(selected) => { + setItem( + { + ...cur, + disease: selected, + }, + i + ); + }} + className="-mt-1 z-10" + onFocus={() => setActiveIdx(i)} + onBlur={() => setActiveIdx(null)} + /> +
+
+
+
Details
{ setItem( { - ...disease, + ...cur, details: e.target.value, }, i @@ -76,17 +116,17 @@ export default function DiseaseBuilder( required />
-
- Date +
+
Date
{ setItem( { - ...disease, + ...cur, date: e.target.value, }, i @@ -95,19 +135,10 @@ export default function DiseaseBuilder( required />
-
- ); - })} +
+ ))}

-
-
- Vaccine - +
+
+ Vaccine + {" *"} +
+ setActiveIdx(i)} - onBlur={() => setActiveIdx(null)} - /> -
-
- Doses - { - let value = parseInt(e.target.value); - if (value < 0) { - value = 0; - } - setItem( - { - ...vaccination, - doses: value, - }, - i + selected={vaccination.vaccine} + fetchData={(search) => { + return Promise.resolve( + vaccines.filter((vaccine: string) => + vaccine.toLowerCase().includes(search.toLowerCase()) + ) ); }} - required + optionLabel={(option) => option} + onChange={setVaccine} + className="-mt-1" + showNOptions={vaccines.length} + onFocus={() => setActiveIdx(i)} + onBlur={() => setActiveIdx(null)} />
-
- Date - { - setItem( - { - ...vaccination, - date: e.target.value, - }, - i - ); - }} - required - /> +
+
+
Doses
+ { + let value = parseInt(e.target.value); + if (value < 0) { + value = 0; + } + setItem( + { + ...vaccination, + doses: value, + }, + i + ); + }} + required + /> +
+
+
Date
+ { + setItem( + { + ...vaccination, + date: e.target.value, + }, + i + ); + }} + required + /> +
From 0ea0a900fde9c38499dacacfbc78faf816479108 Mon Sep 17 00:00:00 2001 From: cp-Coder Date: Sun, 12 Mar 2023 13:53:22 +0530 Subject: [PATCH 3/6] fix(patient): fixed patient registration and removed fields from patient model --- .../Facility/ConsultationDetails.tsx | 3 +- src/Components/Facility/TreatmentSummary.tsx | 8 +- src/Components/Patient/ManagePatients.tsx | 130 ++++++++++-------- src/Components/Patient/PatientHome.tsx | 4 +- src/Components/Patient/PatientInfoCard.tsx | 8 +- src/Components/Patient/PatientRegister.tsx | 35 +---- src/Components/Patient/models.tsx | 8 -- 7 files changed, 92 insertions(+), 104 deletions(-) diff --git a/src/Components/Facility/ConsultationDetails.tsx b/src/Components/Facility/ConsultationDetails.tsx index eb4418d1a5f..77a8c8737ce 100644 --- a/src/Components/Facility/ConsultationDetails.tsx +++ b/src/Components/Facility/ConsultationDetails.tsx @@ -1331,7 +1331,8 @@ export const ConsultationDetails = (props: any) => {
Blood Group {" - "} - {patientData.blood_group || "-"} + {patientData?.last_consultation?.health_details_object + ?.blood_group || "-"}
diff --git a/src/Components/Facility/TreatmentSummary.tsx b/src/Components/Facility/TreatmentSummary.tsx index 2696b0d7031..d15709b471f 100644 --- a/src/Components/Facility/TreatmentSummary.tsx +++ b/src/Components/Facility/TreatmentSummary.tsx @@ -189,9 +189,11 @@ const TreatmentSummary = (props: any) => { - {patientData.medical_history && - patientData.medical_history.length > 0 ? ( - patientData.medical_history.map( + {patientData?.last_consultation?.medical_history_object + ?.patient_diseases && + patientData?.last_consultation?.medical_history_object + ?.patient_diseases?.length > 0 ? ( + patientData?.last_consultation?.medical_history_object?.patient_diseases?.map( (obj: any, index: number) => { return ( diff --git a/src/Components/Patient/ManagePatients.tsx b/src/Components/Patient/ManagePatients.tsx index a1e9b77c847..3836d4101c1 100644 --- a/src/Components/Patient/ManagePatients.tsx +++ b/src/Components/Patient/ManagePatients.tsx @@ -156,8 +156,8 @@ export const PatientManager = () => { : undefined, emergency_phone_number: qParams.emergency_phone_number ? parsePhoneNumberFromString(qParams.emergency_phone_number)?.format( - "E.164" - ) + "E.164" + ) : undefined, local_body: qParams.lsgBody || undefined, facility: qParams.facility, @@ -437,8 +437,8 @@ export const PatientManager = () => {
{patient?.last_consultation && - patient?.last_consultation?.current_bed && - patient?.last_consultation?.discharge_date === null ? ( + patient?.last_consultation?.current_bed && + patient?.last_consultation?.discharge_date === null ? (
{ patient.last_consultation?.facility !== patient.facility || (patient.last_consultation?.discharge_date && patient.is_active)) && ( - - - - - + + + + + + - - )} + )} {!( patient.last_consultation?.facility !== patient.facility ) && @@ -590,6 +590,14 @@ export const PatientManager = () => { )} + {patient.last_consultation?.health_details_object + ?.allergies && ( + + )}
@@ -808,51 +816,51 @@ export const PatientManager = () => { range, ordering, }) => [ - phoneNumber("Primary number", "phone_number"), - phoneNumber("Emergency number", "emergency_phone_number"), - badge("Patient name", "name"), - badge("IP number", "ip_no"), - ...dateRange("Modified", "modified_date"), - ...dateRange("Created", "created_date"), - ...dateRange("Admitted", "last_consultation_admission_date"), - ...dateRange("Discharged", "last_consultation_discharge_date"), - // Admitted to type badges - badge("No. of vaccination doses", "number_of_doses"), - kasp(), - badge("COWIN ID", "covin_id"), - badge("Is Antenatal", "is_antenatal"), - value("Facility", "facility", facilityBadgeName), - badge("Facility Type", "facility_type"), - value("District", "district", districtName), - ordering(), - badge("Category", "category"), - badge("Disease Status", "disease_status"), - value( - "Gender", - "gender", - parseOptionId(GENDER_TYPES, qParams.gender) || "" - ), - { - name: "Admitted to", - value: ADMITTED_TO[qParams.last_consultation_admitted_to], - paramKey: "last_consultation_admitted_to", - }, - ...range("Age", "age"), - badge("SRF ID", "srf_id"), - { name: "LSG Body", value: localbodyName, paramKey: "lsgBody" }, - badge("Declared Status", "is_declared_positive"), - ...dateRange("Result", "date_of_result"), - ...dateRange("Declared positive", "date_declared_positive"), - ...dateRange( - "Symptoms onset", - "last_consultation_symptoms_onset_date" - ), - ...dateRange("Last vaccinated", "last_vaccinated_date"), - { - name: "Telemedicine", - paramKey: "last_consultation_is_telemedicine", - }, - ]} + phoneNumber("Primary number", "phone_number"), + phoneNumber("Emergency number", "emergency_phone_number"), + badge("Patient name", "name"), + badge("IP number", "ip_no"), + ...dateRange("Modified", "modified_date"), + ...dateRange("Created", "created_date"), + ...dateRange("Admitted", "last_consultation_admission_date"), + ...dateRange("Discharged", "last_consultation_discharge_date"), + // Admitted to type badges + badge("No. of vaccination doses", "number_of_doses"), + kasp(), + badge("COWIN ID", "covin_id"), + badge("Is Antenatal", "is_antenatal"), + value("Facility", "facility", facilityBadgeName), + badge("Facility Type", "facility_type"), + value("District", "district", districtName), + ordering(), + badge("Category", "category"), + badge("Disease Status", "disease_status"), + value( + "Gender", + "gender", + parseOptionId(GENDER_TYPES, qParams.gender) || "" + ), + { + name: "Admitted to", + value: ADMITTED_TO[qParams.last_consultation_admitted_to], + paramKey: "last_consultation_admitted_to", + }, + ...range("Age", "age"), + badge("SRF ID", "srf_id"), + { name: "LSG Body", value: localbodyName, paramKey: "lsgBody" }, + badge("Declared Status", "is_declared_positive"), + ...dateRange("Result", "date_of_result"), + ...dateRange("Declared positive", "date_declared_positive"), + ...dateRange( + "Symptoms onset", + "last_consultation_symptoms_onset_date" + ), + ...dateRange("Last vaccinated", "last_vaccinated_date"), + { + name: "Telemedicine", + paramKey: "last_consultation_is_telemedicine", + }, + ]} children={ qParams.last_consultation_admitted_bed_type_list && LastAdmittedToTypeBadges() diff --git a/src/Components/Patient/PatientHome.tsx b/src/Components/Patient/PatientHome.tsx index 867f6d27107..66e72d1c7e5 100644 --- a/src/Components/Patient/PatientHome.tsx +++ b/src/Components/Patient/PatientHome.tsx @@ -536,7 +536,9 @@ export const PatientHome = (props: any) => { {patientData.facility_object?.name || "-"}

- {patientGender} | {patientData.blood_group || "-"} + {patientGender} |{" "} + {patientData?.last_consultation?.health_details_object + ?.blood_group || "-"}

diff --git a/src/Components/Patient/PatientInfoCard.tsx b/src/Components/Patient/PatientInfoCard.tsx index edeb5321e61..8f2318ab0e5 100644 --- a/src/Components/Patient/PatientInfoCard.tsx +++ b/src/Components/Patient/PatientInfoCard.tsx @@ -166,7 +166,13 @@ export default function PatientInfoCard(props: {

{[ - ["Blood Group", patient.blood_group, patient.blood_group], + [ + "Blood Group", + patient?.last_consultation?.health_details_object + ?.blood_group, + patient?.last_consultation?.health_details_object + ?.blood_group, + ], [ "Weight", getDimensionOrDash(patient.last_consultation?.weight, " kg"), diff --git a/src/Components/Patient/PatientRegister.tsx b/src/Components/Patient/PatientRegister.tsx index ae6534409df..42e06a73340 100644 --- a/src/Components/Patient/PatientRegister.tsx +++ b/src/Components/Patient/PatientRegister.tsx @@ -94,12 +94,10 @@ const initForm: any = { gender: "", phone_number: "", emergency_phone_number: "", - blood_group: "", disease_status: diseaseStatus[2], is_declared_positive: "false", date_declared_positive: new Date(), date_of_birth: null, - medical_history: [], nationality: "India", passport_no: "", state: "", @@ -110,7 +108,6 @@ const initForm: any = { permanent_address: "", village: "", pincode: "", - present_health: "", contact_with_confirmed_carrier: "false", contact_with_suspected_carrier: "false", estimated_contact_date: null, @@ -124,7 +121,6 @@ const initForm: any = { srf_id: "", test_type: testType[0], prescribed_medication: false, - ongoing_medication: "", designation_of_health_care_worker: "", instituion_of_health_care_worker: "", cluster_name: "", @@ -370,9 +366,6 @@ export const PatientRegister = (props: PatientRegisterProps) => { is_antenatal: String(!!res.data.is_antenatal), allergies: res.data.allergies ? res.data.allergies : "", pincode: res.data.pincode ? res.data.pincode : "", - ongoing_medication: res.data.ongoing_medication - ? res.data.ongoing_medication - : "", is_declared_positive: res.data.is_declared_positive ? String(res.data.is_declared_positive) : "false", @@ -627,17 +620,6 @@ export const PatientRegister = (props: PatientRegisterProps) => { } } return; - case "medical_history": - if (!state.form[field].length) { - errors[field] = ( - - Please fill the medical history - - ); - if (!error_div) error_div = field; - invalidForm = true; - } - return; default: return; } @@ -709,7 +691,7 @@ export const PatientRegister = (props: PatientRegisterProps) => { : undefined, date_declared_positive: JSON.parse(state.form.is_declared_positive) && - state.form.date_declared_positive + state.form.date_declared_positive ? state.form.date_declared_positive : null, test_id: state.form.test_id, @@ -741,10 +723,7 @@ export const PatientRegister = (props: PatientRegisterProps) => { permanent_address: sameAddress ? state.form.address : state.form.permanent_address - ? state.form.permanent_address - : undefined, - present_health: state.form.present_health - ? state.form.present_health + ? state.form.permanent_address : undefined, contact_with_confirmed_carrier: JSON.parse( state.form.contact_with_confirmed_carrier @@ -755,16 +734,15 @@ export const PatientRegister = (props: PatientRegisterProps) => { estimated_contact_date: (JSON.parse(state.form.contact_with_confirmed_carrier) || JSON.parse(state.form.contact_with_suspected_carrier)) && - state.form.estimated_contact_date + state.form.estimated_contact_date ? state.form.estimated_contact_date : null, cluster_name: (JSON.parse(state.form.contact_with_confirmed_carrier) || JSON.parse(state.form.contact_with_suspected_carrier)) && - state.form.cluster_name + state.form.cluster_name ? state.form.cluster_name : null, - allergies: state.form.allergies, number_of_primary_contacts: Number( state.form.number_of_primary_contacts ) @@ -775,7 +753,6 @@ export const PatientRegister = (props: PatientRegisterProps) => { ) ? Number(state.form.number_of_secondary_contacts) : undefined, - ongoing_medication: state.form.ongoing_medication, is_declared_positive: JSON.parse(state.form.is_declared_positive), designation_of_health_care_worker: state.form.designation_of_health_care_worker, @@ -901,8 +878,8 @@ export const PatientRegister = (props: PatientRegisterProps) => { const duplicateList = !id ? res.data.results : res.data.results.filter( - (item: DupPatientModel) => item.patient_id !== id - ); + (item: DupPatientModel) => item.patient_id !== id + ); if (duplicateList.length) { setStatusDialog({ show: true, diff --git a/src/Components/Patient/models.tsx b/src/Components/Patient/models.tsx index 3da59b9ba4a..0f93d9d14d2 100644 --- a/src/Components/Patient/models.tsx +++ b/src/Components/Patient/models.tsx @@ -37,14 +37,12 @@ export interface PatientModel { phone_number?: string; emergency_phone_number?: string; allergies?: string; - medical_history?: Array<{ disease: string | number; details: string }>; facility_object?: { id: number; name: string; facility_type?: { id: number; name: string }; }; contact_with_carrier?: boolean; - medical_history_details?: string; is_active?: boolean; is_antenatal?: boolean; is_migrant_worker?: boolean; @@ -66,12 +64,10 @@ export interface PatientModel { frontline_worker?: string; estimated_contact_date?: string; past_travel?: boolean; - ongoing_medication?: string; countries_travelled?: Array; transit_details?: string; number_of_primary_contacts?: number; number_of_secondary_contacts?: number; - present_health?: string; has_SARI?: boolean; local_body?: number; district?: number; @@ -85,11 +81,7 @@ export interface PatientModel { srf_id?: string; covin_id?: string; is_vaccinated?: boolean; - vaccine_name?: string; - number_of_doses?: number; - last_vaccinated_date?: string; date_of_birth?: string; - blood_group?: string; review_interval?: number; review_time?: string; date_of_return?: string; From 56afab19ae40107385cd0f17bbcaca7840c74597 Mon Sep 17 00:00:00 2001 From: cp-Coder Date: Sun, 12 Mar 2023 14:58:20 +0530 Subject: [PATCH 4/6] style(consultation): revamped UI --- src/Components/Facility/ConsultationForm.tsx | 27 ++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/Components/Facility/ConsultationForm.tsx b/src/Components/Facility/ConsultationForm.tsx index 2c410ca7c0c..864fa1bf91d 100644 --- a/src/Components/Facility/ConsultationForm.tsx +++ b/src/Components/Facility/ConsultationForm.tsx @@ -234,7 +234,11 @@ const consultationFormReducer = (state = initialState, action: Action) => { } }; -type ConsultationFormSection = "Consultation Details" | "Treatment Plan"; +type ConsultationFormSection = + | "Consultation Details" + | "Treatment Plan" + | "Health Details" + | "Medical History"; export const ConsultationForm = (props: any) => { const { goBack } = useAppHistory(); @@ -266,6 +270,8 @@ export const ConsultationForm = (props: any) => { ); const [consultationDetailsVisible, consultationDetailsRef] = useVisibility(); const [treatmentPlanVisible, treatmentPlanRef] = useVisibility(-300); + const [healthDetailsVisible, healthDetailsRef] = useVisibility(-300); + const [medicalHistoryVisible, medicalHistoryRef] = useVisibility(-300); const sections = { "Consultation Details": { @@ -278,6 +284,16 @@ export const ConsultationForm = (props: any) => { visible: treatmentPlanVisible, ref: treatmentPlanRef, }, + "Health Details": { + iconClass: "fa-solid fa-syringe", + visible: healthDetailsVisible, + ref: healthDetailsRef, + }, + "Medical History": { + iconClass: "fa-solid fa-book-medical", + visible: medicalHistoryVisible, + ref: medicalHistoryRef, + }, }; useEffect(() => { @@ -285,9 +301,16 @@ export const ConsultationForm = (props: any) => { let sectionNow = currentSection; if (consultationDetailsVisible) sectionNow = "Consultation Details"; if (treatmentPlanVisible) sectionNow = "Treatment Plan"; + if (healthDetailsVisible) sectionNow = "Health Details"; + if (medicalHistoryVisible) sectionNow = "Medical History"; return sectionNow; }); - }, [consultationDetailsVisible, treatmentPlanVisible]); + }, [ + consultationDetailsVisible, + treatmentPlanVisible, + healthDetailsVisible, + medicalHistoryVisible, + ]); useEffect(() => { async function fetchPatientName() { From 344a350495bf1393971d69392e2c853f8ac3fc2d Mon Sep 17 00:00:00 2001 From: cp-Coder Date: Sat, 8 Apr 2023 00:29:42 +0530 Subject: [PATCH 5/6] fix(consultation): reordered the fields in the form --- .../prescription-builder/DiseaseBuilder.tsx | 10 +- .../VaccinationBuilder.tsx | 7 +- src/Components/Facility/ConsultationForm.tsx | 252 ++++++++++++++---- .../Form/FormFields/CheckBoxFormField.tsx | 2 +- 4 files changed, 217 insertions(+), 54 deletions(-) diff --git a/src/Components/Common/prescription-builder/DiseaseBuilder.tsx b/src/Components/Common/prescription-builder/DiseaseBuilder.tsx index 7f1b5e8d702..13254d00c89 100644 --- a/src/Components/Common/prescription-builder/DiseaseBuilder.tsx +++ b/src/Components/Common/prescription-builder/DiseaseBuilder.tsx @@ -3,7 +3,6 @@ import { useDispatch } from "react-redux"; import CareIcon from "../../../CAREUI/icons/CareIcon"; import { listICD11Diagnosis } from "../../../Redux/actions"; import AutoCompleteAsync from "../../Form/AutoCompleteAsync"; - interface DiseaseBuilderProps { diseases: T[]; setDiseases: React.Dispatch>; @@ -19,7 +18,7 @@ export type DiseaseDetails = { export const emptyValues = { disease: "", details: "", - date: "", + date: new Date().toJSON().slice(0, 10), precision: 0, }; @@ -117,7 +116,10 @@ export default function DiseaseBuilder( />
-
Date
+
+ Date + {" *"} +
- + Add Disease History + + Add Medical History
); diff --git a/src/Components/Common/prescription-builder/VaccinationBuilder.tsx b/src/Components/Common/prescription-builder/VaccinationBuilder.tsx index 6b98ac529c3..ca935ddb773 100644 --- a/src/Components/Common/prescription-builder/VaccinationBuilder.tsx +++ b/src/Components/Common/prescription-builder/VaccinationBuilder.tsx @@ -18,7 +18,7 @@ export type VaccinationDetails = { export const emptyValues = { vaccine: "", doses: 0, - date: "", + date: new Date().toJSON().slice(0, 10), precision: 0, }; @@ -124,7 +124,10 @@ export default function VaccinationBuilder( />
-
Date
+
+ Date + {" *"} +
{ }; type ConsultationFormSection = - | "Consultation Details" - | "Treatment Plan" + | "Medical History" | "Health Details" - | "Medical History"; + | "Consultation Details" + | "Treatment Plan"; export const ConsultationForm = (props: any) => { const { goBack } = useAppHistory(); @@ -265,15 +270,25 @@ export const ConsultationForm = (props: any) => { const [facilityName, setFacilityName] = useState(""); const isUpdate = !!id; - const [currentSection, setCurrentSection] = useState( - "Consultation Details" - ); - const [consultationDetailsVisible, consultationDetailsRef] = useVisibility(); + const [currentSection, setCurrentSection] = + useState("Medical History"); + const [consultationDetailsVisible, consultationDetailsRef] = + useVisibility(-300); const [treatmentPlanVisible, treatmentPlanRef] = useVisibility(-300); const [healthDetailsVisible, healthDetailsRef] = useVisibility(-300); - const [medicalHistoryVisible, medicalHistoryRef] = useVisibility(-300); + const [medicalHistoryVisible, medicalHistoryRef] = useVisibility(); const sections = { + "Medical History": { + iconClass: "care-l-book-medical", + visible: medicalHistoryVisible, + ref: medicalHistoryRef, + }, + "Health Details": { + iconClass: "care-l-syringe", + visible: healthDetailsVisible, + ref: healthDetailsRef, + }, "Consultation Details": { iconClass: "care-l-medkit", visible: consultationDetailsVisible, @@ -284,25 +299,15 @@ export const ConsultationForm = (props: any) => { visible: treatmentPlanVisible, ref: treatmentPlanRef, }, - "Health Details": { - iconClass: "fa-solid fa-syringe", - visible: healthDetailsVisible, - ref: healthDetailsRef, - }, - "Medical History": { - iconClass: "fa-solid fa-book-medical", - visible: medicalHistoryVisible, - ref: medicalHistoryRef, - }, }; useEffect(() => { setCurrentSection((currentSection) => { let sectionNow = currentSection; + if (medicalHistoryVisible) sectionNow = "Medical History"; + if (healthDetailsVisible) sectionNow = "Health Details"; if (consultationDetailsVisible) sectionNow = "Consultation Details"; if (treatmentPlanVisible) sectionNow = "Treatment Plan"; - if (healthDetailsVisible) sectionNow = "Health Details"; - if (medicalHistoryVisible) sectionNow = "Medical History"; return sectionNow; }); }, [ @@ -374,7 +379,7 @@ export const ConsultationForm = (props: any) => { admitted_to: res.data.admitted_to ? res.data.admitted_to : "", category: res.data.category ? PATIENT_CATEGORIES.find((i) => i.text === res.data.category) - ?.id || "Comfort" + ?.id || "Comfort" : "Comfort", ip_no: res.data.ip_no ? res.data.ip_no : "", op_no: res.data.op_no ? res.data.op_no : "", @@ -390,11 +395,9 @@ export const ConsultationForm = (props: any) => { cause_of_death: res.data?.discharge_notes || "", death_datetime: res.data?.death_datetime || "", death_confirmed_doctor: res.data?.death_confirmed_doctor || "", - family_details: - res.data.health_details_object?.family_details || "", - has_allergy: - `${res.data.health_details_object?.has_allergy}` || "false", - allergies: res.data.health_details_object?.allergies || "", + family_details: res.data?.health_details_object?.family_detail, + has_allergy: res?.data.health_details_object?.has_allergy, + allergies: res?.data.health_details_object?.allergies, blood_group: res.data.health_details_object?.blood_group ? res.data.health_details_object?.blood_group === "UNKNOWN" ? "UNK" @@ -407,6 +410,7 @@ export const ConsultationForm = (props: any) => { present_health: res.data.medical_history_object?.present_health, }; dispatch({ type: "set_form", form: formData }); + console.log(formData); setBed(formData.bed); } else { goBack(); @@ -648,7 +652,7 @@ export const ConsultationForm = (props: any) => { return; case "has_allergy": - if (state.form.has_allergy === "true") { + if (state.form.has_allergy) { if (state.form.allergies === "") { errors["allergies"] = "Please enter Patient's allergies"; invalidForm = true; @@ -658,35 +662,47 @@ export const ConsultationForm = (props: any) => { case "vaccination_history": { let invalid = false; + let errorMsg = ""; for (const f of vaccination) { - if ( - !f.vaccine?.replace(/\s/g, "").length || - !f.date?.replace(/\s/g, "").length - ) { + if (!f.vaccine?.replace(/\s/g, "").length) { + errorMsg = "Vaccine field can not be empty"; + invalid = true; + break; + } + if (!f.date?.replace(/\s/g, "").length) { + errorMsg = "Date field can not be empty"; invalid = true; break; } } if (invalid) { - errors[field] = "Vaccination field can not be empty"; + errors[field] = errorMsg; invalidForm = true; } return; } case "patient_diseases": { let invalid = false; + let errorMsg = ""; for (const f of diseases) { - if ( - !f.disease?.replace(/\s/g, "").length || - !f.details?.replace(/\s/g, "").length || - !f.date?.replace(/\s/g, "").length - ) { + if (!f.disease?.replace(/\s/g, "").length) { + errorMsg = "Disease field can not be empty"; + invalid = true; + break; + } + if (!f.details?.replace(/\s/g, "").length) { + errorMsg = "Details field can not be empty"; + invalid = true; + break; + } + if (!f.date?.replace(/\s/g, "").length) { + errorMsg = "Date field can not be empty"; invalid = true; break; } } if (invalid) { - errors[field] = "Disease field can not be empty"; + errors[field] = errorMsg; invalidForm = true; } return; @@ -747,6 +763,7 @@ export const ConsultationForm = (props: any) => { ) => { e.preventDefault(); const validated = validateForm(); + console.log(validated, state, vaccination); if (validated) { setIsLoading(true); const data = { @@ -802,8 +819,7 @@ export const ConsultationForm = (props: any) => { new_health_details: { family_details: state.form.family_details, has_allergy: state.form.has_allergy, - allergies: - state.form.has_allergy === "true" ? state.form.allergies : "", + allergies: state.form.has_allergy ? state.form.allergies : "", blood_group: state.form.blood_group ? state.form.blood_group : undefined, @@ -897,6 +913,16 @@ export const ConsultationForm = (props: any) => { }); }; + const handleAllergyChange = ({ name, value }: FieldChangeEvent) => { + dispatch({ + type: "set_form", + form: { + ...state.form, + [name]: value, + }, + }); + }; + const handleDoctorSelect = (doctor: UserModel | null) => { if (doctor?.id) { dispatch({ @@ -1000,8 +1026,9 @@ export const ConsultationForm = (props: any) => { const section = sections[sectionTitle as ConsultationFormSection]; return (