From f3c3c4ae41db1a4c422d99ae6e66460a4db2efa6 Mon Sep 17 00:00:00 2001 From: Ashraf Mohammed Date: Sun, 31 Mar 2024 12:11:15 +0530 Subject: [PATCH 01/11] add auth checks --- src/Components/Common/FacilitySelect.tsx | 3 + .../FacilitiesSelectDialogue.tsx | 12 + src/Components/Patient/ManagePatients.tsx | 10 +- src/Components/Patient/PatientRegister.tsx | 1725 +++++++++-------- 4 files changed, 908 insertions(+), 842 deletions(-) diff --git a/src/Components/Common/FacilitySelect.tsx b/src/Components/Common/FacilitySelect.tsx index b207189d27..14db2ff09b 100644 --- a/src/Components/Common/FacilitySelect.tsx +++ b/src/Components/Common/FacilitySelect.tsx @@ -13,6 +13,7 @@ interface FacilitySelectProps { multiple?: boolean; facilityType?: number; district?: string; + state?: string; showAll?: boolean; showNOptions?: number; freeText?: boolean; @@ -33,6 +34,7 @@ export const FacilitySelect = (props: FacilitySelectProps) => { className = "", facilityType, district, + state, freeText = false, errors = "", } = props; @@ -47,6 +49,7 @@ export const FacilitySelect = (props: FacilitySelectProps) => { facility_type: facilityType, exclude_user: exclude_user, district, + state, }; const { data } = await request( diff --git a/src/Components/ExternalResult/FacilitiesSelectDialogue.tsx b/src/Components/ExternalResult/FacilitiesSelectDialogue.tsx index 7239e0b912..03f6e92d72 100644 --- a/src/Components/ExternalResult/FacilitiesSelectDialogue.tsx +++ b/src/Components/ExternalResult/FacilitiesSelectDialogue.tsx @@ -3,6 +3,7 @@ import DialogModal from "../Common/Dialog"; import { FacilitySelect } from "../Common/FacilitySelect"; import { FacilityModel } from "../Facility/models"; import { useTranslation } from "react-i18next"; +import useAuthUser from "../../Common/hooks/useAuthUser"; interface Props { show: boolean; @@ -15,6 +16,7 @@ interface Props { const FacilitiesSelectDialog = (props: Props) => { const { show, handleOk, handleCancel, selectedFacility, setSelected } = props; const { t } = useTranslation(); + const authUser = useAuthUser(); return ( { errors="" showAll={false} multiple={false} + district={ + authUser?.user_type === "DistrictAdmin" + ? authUser?.district?.toString() + : "" + } + state={ + authUser?.user_type === "StateAdmin" + ? authUser?.state?.toString() + : "" + } />
diff --git a/src/Components/Patient/ManagePatients.tsx b/src/Components/Patient/ManagePatients.tsx index ff3dede407..0d2c9a8cb2 100644 --- a/src/Components/Patient/ManagePatients.tsx +++ b/src/Components/Patient/ManagePatients.tsx @@ -742,11 +742,19 @@ export const PatientManager = () => { { + const showAllFacilityUsers = ["DistrictAdmin", "StateAdmin"]; if (qParams.facility) navigate(`/facility/${qParams.facility}/patient`); else if (onlyAccessibleFacility) navigate(`/facility/${onlyAccessibleFacility.id}/patient`); - else setShowDialog("create"); + else if ( + !showAllFacilityUsers.includes(authUser.user_type) && + authUser.home_facility_object?.id + ) { + navigate( + `/facility/${authUser.home_facility_object.id}/patient` + ); + } else setShowDialog("create"); }} className="w-full lg:w-fit" > diff --git a/src/Components/Patient/PatientRegister.tsx b/src/Components/Patient/PatientRegister.tsx index 85a5002f8d..ebe612c752 100644 --- a/src/Components/Patient/PatientRegister.tsx +++ b/src/Components/Patient/PatientRegister.tsx @@ -61,6 +61,7 @@ import useAuthUser from "../../Common/hooks/useAuthUser.js"; import useQuery from "../../Utils/request/useQuery.js"; import routes from "../../Redux/api.js"; import request from "../../Utils/request/request.js"; +import Error404 from "../ErrorPages/404"; const Loading = lazy(() => import("../Common/Loading")); const PageTitle = lazy(() => import("../Common/PageTitle")); @@ -1021,905 +1022,947 @@ export const PatientRegister = (props: PatientRegisterProps) => { ); }; + const PatientRegisterAuth = () => { + let check = false; + const showAllFacilityUsers = ["DistrictAdmin", "StateAdmin"]; + if ( + !showAllFacilityUsers.includes(authUser.user_type) && + authUser.home_facility_object?.id === facilityId + ) { + check = true; + } else if ( + authUser.user_type === "DistrictAdmin" && + authUser.district === facilityObject?.district + ) { + check = true; + } else if ( + authUser.user_type === "StateAdmin" && + authUser.state === facilityObject?.state + ) { + check = true; + } + return check; + }; + if (isLoading) { return ; } - return ( -
- {statusDialog.show && ( - - )} - {statusDialog.transfer && ( - handleDialogClose("back")} - title="Patient Transfer Form" - className="max-w-md md:min-w-[600px]" - > - ; + } + + if (!isLoading) + return ( +
+ {statusDialog.show && ( + handleDialogClose("close")} - handleCancel={() => handleDialogClose("back")} - facilityId={facilityId} + handleOk={handleDialogClose} + handleCancel={goBack} + isNew={!id} /> - - )} - { - if (showImport.show) { - setShowImport({ - show: false, - field: null, - }); - return false; - } else { - id - ? navigate(`/facility/${facilityId}/patient/${id}`) - : navigate(`/facility/${facilityId}`); - } - }} - crumbsReplacements={{ - [facilityId]: { name: facilityObject?.name }, - [id ?? "????"]: { name: patientName }, - }} - /> -
-
-
- {" "} - Please enter the correct date of birth for the patient -
-

- Each patient in the system is uniquely identifiable by the number - and date of birth. Adding incorrect date of birth can result in - duplication of patient records. -

-
- <> - {showAlertMessage.show && ( - goBack()} - onClose={() => goBack()} - variant="primary" - action="Ok" - show + )} + {statusDialog.transfer && ( + handleDialogClose("back")} + title="Patient Transfer Form" + className="max-w-md md:min-w-[600px]" + > + handleDialogClose("close")} + handleCancel={() => handleDialogClose("back")} + facilityId={facilityId} /> - )} - {showImport.show && ( -
-
-
- - Enter Care External Results Id - - setCareExtId(e.value)} - error={state.errors.name} - /> + + )} + { + if (showImport.show) { + setShowImport({ + show: false, + field: null, + }); + return false; + } else { + id + ? navigate(`/facility/${facilityId}/patient/${id}`) + : navigate(`/facility/${facilityId}`); + } + }} + crumbsReplacements={{ + [facilityId]: { name: facilityObject?.name }, + [id ?? "????"]: { name: patientName }, + }} + /> +
+
+
+ {" "} + Please enter the correct date of birth for the patient +
+

+ Each patient in the system is uniquely identifiable by the number + and date of birth. Adding incorrect date of birth can result in + duplication of patient records. +

+
+ <> + {showAlertMessage.show && ( + goBack()} + onClose={() => goBack()} + variant="primary" + action="Ok" + show + /> + )} + {showImport.show && ( +
+
+
+ + Enter Care External Results Id + + setCareExtId(e.value)} + error={state.errors.name} + /> +
+ {" "} +
-
+ )} + <> +
+ + defaults={id ? state.form : initForm} + validate={validateForm} + onSubmit={handleSubmit} + submitLabel={buttonText} + onCancel={() => navigate("/facility")} + className="bg-transparent px-1 py-2 md:px-2" + onDraftRestore={(newState) => { + dispatch({ type: "set_state", state: newState }); + Promise.all([ + fetchDistricts(newState.form.state ?? 0), + fetchLocalBody(newState.form.district?.toString() ?? ""), + fetchWards(newState.form.local_body?.toString() ?? ""), + duplicateCheck(newState.form.phone_number ?? ""), + ]); }} - disabled={!careExtId} + noPadding > - Import Patient Data from External Results - {" "} - -
-
- )} - <> -
- - defaults={id ? state.form : initForm} - validate={validateForm} - onSubmit={handleSubmit} - submitLabel={buttonText} - onCancel={() => navigate("/facility")} - className="bg-transparent px-1 py-2 md:px-2" - onDraftRestore={(newState) => { - dispatch({ type: "set_state", state: newState }); - Promise.all([ - fetchDistricts(newState.form.state ?? 0), - fetchLocalBody(newState.form.district?.toString() ?? ""), - fetchWards(newState.form.local_body?.toString() ?? ""), - duplicateCheck(newState.form.phone_number ?? ""), - ]); - }} - noPadding - > - {(field) => { - if (!formField) setFormField(field); - return ( - <> -
- { - setShowImport({ - show: true, - field, - }); - setQuery({ extId: "" }, { replace: true }); - }} - > - - Import From External Results - -
- {enable_abdm && ( -
-

- ABHA Details -

- {showLinkAbhaNumberModal && ( - setShowLinkAbhaNumberModal(false)} - onSuccess={(data: any) => { - if (id) { - navigate( - `/facility/${facilityId}/patient/${id}` - ); - return; + {(field) => { + if (!formField) setFormField(field); + return ( + <> +
+ { + setShowImport({ + show: true, + field, + }); + setQuery({ extId: "" }, { replace: true }); + }} + > + + Import From External Results + +
+ {enable_abdm && ( +
+

+ ABHA Details +

+ {showLinkAbhaNumberModal && ( + + setShowLinkAbhaNumberModal(false) } + onSuccess={(data: any) => { + if (id) { + navigate( + `/facility/${facilityId}/patient/${id}` + ); + return; + } - handleAbhaLinking(data, field); - }} - /> - )} - {!state.form.abha_number ? ( - - ) : ( -
-
- null} - disabled={true} - error="" - /> -
-
- {state.form.health_id ? ( + handleAbhaLinking(data, field); + }} + /> + )} + {!state.form.abha_number ? ( + + ) : ( +
+
null} disabled={true} error="" /> - ) : ( -
- No Abha Address Associated with this ABHA - Number -
- )} -
-
- )} -
- )} -
-

- Personal Details -

-
-
- { - if (!id) duplicateCheck(event.value); - field("phone_number").onChange(event); - }} - types={["mobile", "landline"]} - /> -
-
- -
-
- -
-
- -
-
- o.text} - optionValue={(o: any) => o.id} - /> -
- - { -
- option.label} - optionValue={(option) => option.value} - /> -
- } -
-
- -
-
- - -
- -
- { - field("pincode").onChange(e); - handlePincodeChange( - e, - field("pincode").onChange - ); - }} - /> - {showAutoFilledPincode && ( -
- - - State and District auto-filled from Pincode - +
+
+ {state.form.health_id ? ( + null} + disabled={true} + error="" + /> + ) : ( +
+ No Abha Address Associated with this ABHA + Number +
+ )} +
)}
-
- -
-
- o} - optionValue={(o) => o} - /> -
- {field("nationality").value === "India" ? ( - <> -
- {isStateLoading ? ( - - ) : ( - o.name} - optionValue={(o: any) => o.id} - onChange={(e: any) => { - field("state").onChange(e); - field("district").onChange({ - name: "district", - value: undefined, - }); - field("local_body").onChange({ - name: "local_body", - value: undefined, - }); - field("ward").onChange({ - name: "ward", - value: undefined, - }); - fetchDistricts(e.value); - fetchLocalBody("0"); - fetchWards("0"); - }} - /> - )} -
- -
- {isDistrictLoading ? ( -
- -
- ) : ( - o.name} - optionValue={(o: any) => o.id} - onChange={(e: any) => { - field("district").onChange(e); - field("local_body").onChange({ - name: "local_body", - value: undefined, - }); - field("ward").onChange({ - name: "ward", - value: undefined, - }); - fetchLocalBody(String(e.value)); - fetchWards("0"); - }} + )} +
+

+ Personal Details +

+
+
+ { + if (!id) duplicateCheck(event.value); + field("phone_number").onChange(event); + }} + types={["mobile", "landline"]} + /> +
+
+ +
+
+ +
+
+ +
+
+ o.text} + optionValue={(o: any) => o.id} + /> +
+ + { +
+ option.label} + optionValue={(option) => option.value} /> - )} -
+
+ } + +
+ +
+
+ + +
-
- {isLocalbodyLoading ? ( -
- -
- ) : ( - o.name} - optionValue={(o: any) => o.id} - onChange={(e: any) => { - field("local_body").onChange(e); - field("ward").onChange({ - name: "ward", - value: undefined, - }); - fetchWards(String(e.value)); - }} - /> - )} -
-
- {isWardLoading ? ( -
- -
- ) : ( - { - return { - id: e.id, - name: e.number + ": " + e.name, - }; - })} - placeholder={ - field("local_body").value - ? "Choose Ward" - : "Select Localbody First" - } - disabled={!field("local_body").value} - optionLabel={(o: any) => o.name} - optionValue={(o: any) => o.id} - onChange={(e: any) => { - field("ward").onChange(e); - }} - /> - )} -
- o.text} - optionValue={(o) => o.id} +
+ { + field("pincode").onChange(e); + handlePincodeChange( + e, + field("pincode").onChange + ); + }} /> - - ) : ( -
+ {showAutoFilledPincode && ( +
+ + + State and District auto-filled from Pincode + +
+ )} +
+
- )} -
-
-
- - } - title={ -

- COVID Details -

- } - > -
-
-
- option.label} - optionValue={(option) => option.value} - /> -
-
- option.label} - optionValue={(option) => option.value} - /> -
-
- option.label} - optionValue={(option) => option.value} - /> -
+
+ o} + optionValue={(o) => o} + />
-
- - { -
-
- -
-
- option.label} - optionValue={(option) => option.value} - /> -
-
- o} - optionValue={(o) => o} - /> -
-
- + {field("nationality").value === "India" ? ( + <> +
+ {isStateLoading ? ( + + ) : ( + o.name} + optionValue={(o: any) => o.id} + onChange={(e: any) => { + field("state").onChange(e); + field("district").onChange({ + name: "district", + value: undefined, + }); + field("local_body").onChange({ + name: "local_body", + value: undefined, + }); + field("ward").onChange({ + name: "ward", + value: undefined, + }); + fetchDistricts(e.value); + fetchLocalBody("0"); + fetchWards("0"); + }} + /> + )} +
+ +
+ {isDistrictLoading ? ( +
+
-
- } - - -
-
- o.name} + optionValue={(o: any) => o.id} + onChange={(e: any) => { + field("district").onChange(e); + field("local_body").onChange({ + name: "local_body", + value: undefined, + }); + field("ward").onChange({ + name: "ward", + value: undefined, + }); + fetchLocalBody(String(e.value)); + fetchWards("0"); + }} /> -
+ )} +
-
- + {isLocalbodyLoading ? ( +
+ +
+ ) : ( + o.name} + optionValue={(o: any) => o.id} + onChange={(e: any) => { + field("local_body").onChange(e); + field("ward").onChange({ + name: "ward", + value: undefined, + }); + fetchWards(String(e.value)); + }} /> -
+ )} +
+
+ {isWardLoading ? ( +
+ +
+ ) : ( + { + return { + id: e.id, + name: e.number + ": " + e.name, + }; + })} + placeholder={ + field("local_body").value + ? "Choose Ward" + : "Select Localbody First" + } + disabled={!field("local_body").value} + optionLabel={(o: any) => o.name} + optionValue={(o: any) => o.id} + onChange={(e: any) => { + field("ward").onChange(e); + }} + /> + )}
- -
- o} - optionValue={(o) => o} - required - /> -
-
o} - optionValue={(o) => o} - required + {...field("occupation")} + label="Occupation" + placeholder="Select Occupation" + options={occupationTypes} + optionLabel={(o) => o.text} + optionValue={(o) => o.id} /> -
-
+ + ) : ( +
-
- option.label} - optionValue={(option) => option.value} - /> + )} +
+
+
+ + } + title={ +

+ COVID Details +

+ } + > +
+
+
+ option.label} + optionValue={(option) => option.value} + /> +
+
+ option.label} + optionValue={(option) => option.value} + /> +
+
+ option.label} + optionValue={(option) => option.value} + /> +
+
+
-
- + { +
+
+ +
+
+ + option.label + } + optionValue={(option) => option.value} + /> +
+
+ o} + optionValue={(o) => o} + /> +
+
+ +
+
+ } + + +
+
+ +
+ +
+ +
-
-
- -
+
+ o} + optionValue={(o) => o} + required + /> +
+
+ o} + optionValue={(o) => o} + required + /> +
+
+ +
+
+ option.label} + optionValue={(option) => option.value} + /> + +
+ +
+
+
+
+ +
-
- -
-
- -
+
+ +
+
+ +
-
- -
-
- +
+ +
+
+ +
-
-
-
-
-

- Medical History -

-
-
- -
+ +
+
+

+ Medical History +

+
+
+ +
-
- -
-
- - Any medical history? (Comorbidities) - -
- {MEDICAL_HISTORY_CHOICES.map((i) => { - return renderMedicalHistory( - i.id as number, - i.text, - field - ); - })} +
+ +
+
+ + Any medical history? (Comorbidities) + +
+ {MEDICAL_HISTORY_CHOICES.map((i) => { + return renderMedicalHistory( + i.id as number, + i.text, + field + ); + })} +
+
- -
-
- -
+
+ +
-
- o} - optionValue={(o: any) => o} - /> +
+ o} + optionValue={(o: any) => o} + /> +
-
-
-
-

- Insurance Details -

- - setInsuranceDetails([ - ...insuranceDetails, - { - id: "", - subscriber_id: "", - policy_id: "", - insurer_id: "", - insurer_name: "", - }, - ]) - } - data-testid="add-insurance-button" - > - - Add Insurance Details - +
+
+

+ Insurance Details +

+ + setInsuranceDetails([ + ...insuranceDetails, + { + id: "", + subscriber_id: "", + policy_id: "", + insurer_id: "", + insurer_name: "", + }, + ]) + } + data-testid="add-insurance-button" + > + + Add Insurance Details + +
+ setInsuranceDetails(value)} + error={insuranceDetailsError} + gridView + />
- setInsuranceDetails(value)} - error={insuranceDetailsError} - gridView - /> -
- - ); - }} - -
+ + ); + }} + +
+ - +
-
- ); + ); }; From 0129bca5c1d2797808d8ca5427d9a61ace7eb1c5 Mon Sep 17 00:00:00 2001 From: Ashraf Mohammed Date: Tue, 2 Apr 2024 20:30:03 +0530 Subject: [PATCH 02/11] remove merge conflict --- src/Components/Patient/PatientRegister.tsx | 1682 ++++++++++---------- 1 file changed, 840 insertions(+), 842 deletions(-) diff --git a/src/Components/Patient/PatientRegister.tsx b/src/Components/Patient/PatientRegister.tsx index 6bc67ba625..56bbc07258 100644 --- a/src/Components/Patient/PatientRegister.tsx +++ b/src/Components/Patient/PatientRegister.tsx @@ -1018,6 +1018,10 @@ export const PatientRegister = (props: PatientRegisterProps) => { ); }; + if (isLoading) { + return ; + } + const PatientRegisterAuth = () => { let check = false; const showAllFacilityUsers = ["DistrictAdmin", "StateAdmin"]; @@ -1040,126 +1044,99 @@ export const PatientRegister = (props: PatientRegisterProps) => { return check; }; - if (isLoading) { - return ; - } - if (!isLoading && facilityId && facilityObject && !PatientRegisterAuth()) { return ; } - if (!isLoading) - return ( -
- {statusDialog.show && ( - + {statusDialog.show && ( + + )} + {statusDialog.transfer && ( + handleDialogClose("back")} + title="Patient Transfer Form" + className="max-w-md md:min-w-[600px]" + > + handleDialogClose("close")} + handleCancel={() => handleDialogClose("back")} + facilityId={facilityId} /> - )} - {statusDialog.transfer && ( - handleDialogClose("back")} - title="Patient Transfer Form" - className="max-w-md md:min-w-[600px]" - > - handleDialogClose("close")} - handleCancel={() => handleDialogClose("back")} - facilityId={facilityId} - /> - - )} - { - if (showImport.show) { - setShowImport({ - show: false, - field: null, - }); - return false; - } else { - id - ? navigate(`/facility/${facilityId}/patient/${id}`) - : navigate(`/facility/${facilityId}`); - } - }} - crumbsReplacements={{ - [facilityId]: { name: facilityObject?.name }, - [id ?? "????"]: { name: patientName }, - }} - /> -
-
-
- {" "} - Please enter the correct date of birth for the patient -
-

- Each patient in the system is uniquely identifiable by the number - and date of birth. Adding incorrect date of birth can result in - duplication of patient records. -

+ + )} + { + if (showImport.show) { + setShowImport({ + show: false, + field: null, + }); + return false; + } else { + id + ? navigate(`/facility/${facilityId}/patient/${id}`) + : navigate(`/facility/${facilityId}`); + } + }} + crumbsReplacements={{ + [facilityId]: { name: facilityObject?.name }, + [id ?? "????"]: { name: patientName }, + }} + /> +
+
+
+ {" "} + Please enter the correct date of birth for the patient
- <> - {showAlertMessage.show && ( - goBack()} - onClose={() => goBack()} - variant="primary" - action="Ok" - show - /> - )} - {showImport.show && ( -
-
-
- - Enter Care External Results Id - - setCareExtId(e.value)} - error={state.errors.name} - /> -
- {" "} - +

+ Each patient in the system is uniquely identifiable by the number + and date of birth. Adding incorrect date of birth can result in + duplication of patient records. +

+
+ <> + {showAlertMessage.show && ( + goBack()} + onClose={() => goBack()} + variant="primary" + action="Ok" + show + /> + )} + {showImport.show && ( +
+
+
+ + Enter Care External Results Id + + setCareExtId(e.value)} + error={state.errors.name} + />
{" "} + +
+
+ )} + <> +
+ + defaults={id ? state.form : initForm} + validate={validateForm} + onSubmit={handleSubmit} + submitLabel={buttonText} + onCancel={() => navigate("/facility")} + className="bg-transparent px-1 py-2 md:px-2" + onDraftRestore={(newState) => { + dispatch({ type: "set_state", state: newState }); + Promise.all([ + fetchDistricts(newState.form.state ?? 0), + fetchLocalBody(newState.form.district?.toString() ?? ""), + fetchWards(newState.form.local_body?.toString() ?? ""), + duplicateCheck(newState.form.phone_number ?? ""), + ]); + }} + noPadding + > + {(field) => { + if (!formField) setFormField(field); + return ( + <> +
+ { + setShowImport({ + show: true, + field, + }); + setQuery({ extId: "" }, { replace: true }); + }} + > + + Import From External Results + +
+ {enable_abdm && ( +
+

+ ABHA Details +

+ {showLinkAbhaNumberModal && ( + setShowLinkAbhaNumberModal(false)} + onSuccess={(data: any) => { + if (id) { + navigate( + `/facility/${facilityId}/patient/${id}` + ); + return; } - onSuccess={(data: any) => { - if (id) { - navigate( - `/facility/${facilityId}/patient/${id}` - ); - return; - } - handleAbhaLinking(data, field); - }} - /> - )} - {!state.form.abha_number ? ( - - ) : ( -
-
+ handleAbhaLinking(data, field); + }} + /> + )} + {!state.form.abha_number ? ( + + ) : ( +
+
+ null} + disabled={true} + error="" + /> +
+
+ {state.form.health_id ? ( null} disabled={true} error="" /> -
-
- {state.form.health_id ? ( - null} - disabled={true} - error="" - /> - ) : ( -
- No Abha Address Associated with this ABHA - Number -
- )} -
+ ) : ( +
+ No Abha Address Associated with this ABHA + Number +
+ )} +
+
+ )} +
+ )} +
+

+ Personal Details +

+
+
+ { + if (!id) duplicateCheck(event.value); + field("phone_number").onChange(event); + }} + types={["mobile", "landline"]} + /> +
+
+ +
+
+ +
+
+ +
+
+ o.text} + optionValue={(o: any) => o.id} + /> +
+ + { +
+ option.label} + optionValue={(option) => option.value} + /> +
+ } +
+
+ +
+
+ + +
+ +
+ { + field("pincode").onChange(e); + handlePincodeChange( + e, + field("pincode").onChange + ); + }} + /> + {showAutoFilledPincode && ( +
+ + + State and District auto-filled from Pincode +
)}
- )} -
-

- Personal Details -

-
-
- { - if (!id) duplicateCheck(event.value); - field("phone_number").onChange(event); - }} - types={["mobile", "landline"]} - /> -
-
- -
-
- -
-
- -
-
- o.text} - optionValue={(o: any) => o.id} - /> -
- - { -
- option.label} - optionValue={(option) => option.value} +
+ +
+
+ o} + optionValue={(o) => o} + /> +
+ {field("nationality").value === "India" ? ( + <> +
+ {isStateLoading ? ( + + ) : ( + o.name} + optionValue={(o: any) => o.id} + onChange={(e: any) => { + field("state").onChange(e); + field("district").onChange({ + name: "district", + value: undefined, + }); + field("local_body").onChange({ + name: "local_body", + value: undefined, + }); + field("ward").onChange({ + name: "ward", + value: undefined, + }); + fetchDistricts(e.value); + fetchLocalBody("0"); + fetchWards("0"); + }} /> -
- } - -
- -
-
- - -
+ )} +
-
- { - field("pincode").onChange(e); - handlePincodeChange( - e, - field("pincode").onChange - ); - }} - /> - {showAutoFilledPincode && ( -
- + {isDistrictLoading ? ( +
+ +
+ ) : ( + o.name} + optionValue={(o: any) => o.id} + onChange={(e: any) => { + field("district").onChange(e); + field("local_body").onChange({ + name: "local_body", + value: undefined, + }); + field("ward").onChange({ + name: "ward", + value: undefined, + }); + fetchLocalBody(String(e.value)); + fetchWards("0"); + }} /> - - State and District auto-filled from Pincode - -
- )} -
-
+ )} +
+ +
+ {isLocalbodyLoading ? ( +
+ +
+ ) : ( + o.name} + optionValue={(o: any) => o.id} + onChange={(e: any) => { + field("local_body").onChange(e); + field("ward").onChange({ + name: "ward", + value: undefined, + }); + fetchWards(String(e.value)); + }} + /> + )} +
+
+ {isWardLoading ? ( +
+ +
+ ) : ( + { + return { + id: e.id, + name: e.number + ": " + e.name, + }; + })} + placeholder={ + field("local_body").value + ? "Choose Ward" + : "Select Localbody First" + } + disabled={!field("local_body").value} + optionLabel={(o: any) => o.name} + optionValue={(o: any) => o.id} + onChange={(e: any) => { + field("ward").onChange(e); + }} + /> + )} +
+ o.text} + optionValue={(o) => o.id} + /> + + ) : ( +
-
- o} - optionValue={(o) => o} - /> + )} +
+
+
+ + } + title={ +

+ COVID Details +

+ } + > +
+
+
+ option.label} + optionValue={(option) => option.value} + /> +
+
+ option.label} + optionValue={(option) => option.value} + /> +
+
+ option.label} + optionValue={(option) => option.value} + /> +
- {field("nationality").value === "India" ? ( - <> -
- {isStateLoading ? ( - - ) : ( - o.name} - optionValue={(o: any) => o.id} - onChange={(e: any) => { - field("state").onChange(e); - field("district").onChange({ - name: "district", - value: undefined, - }); - field("local_body").onChange({ - name: "local_body", - value: undefined, - }); - field("ward").onChange({ - name: "ward", - value: undefined, - }); - fetchDistricts(e.value); - fetchLocalBody("0"); - fetchWards("0"); - }} - /> - )} -
- -
- {isDistrictLoading ? ( -
- +
+ + { +
+
+ +
+
+ option.label} + optionValue={(option) => option.value} + />
- ) : ( - + o} + optionValue={(o) => o} + /> +
+
+ +
+
+ } + + +
+
+ o.name} - optionValue={(o: any) => o.id} - onChange={(e: any) => { - field("district").onChange(e); - field("local_body").onChange({ - name: "local_body", - value: undefined, - }); - field("ward").onChange({ - name: "ward", - value: undefined, - }); - fetchLocalBody(String(e.value)); - fetchWards("0"); - }} + position="LEFT" /> - )} -
+
-
- {isLocalbodyLoading ? ( -
- -
- ) : ( - + o.name} - optionValue={(o: any) => o.id} - onChange={(e: any) => { - field("local_body").onChange(e); - field("ward").onChange({ - name: "ward", - value: undefined, - }); - fetchWards(String(e.value)); - }} - /> - )} -
-
- {isWardLoading ? ( -
- -
- ) : ( - { - return { - id: e.id, - name: e.number + ": " + e.name, - }; - })} - placeholder={ - field("local_body").value - ? "Choose Ward" - : "Select Localbody First" - } - disabled={!field("local_body").value} - optionLabel={(o: any) => o.name} - optionValue={(o: any) => o.id} - onChange={(e: any) => { - field("ward").onChange(e); - }} /> - )} +
+ +
o.text} - optionValue={(o) => o.id} + {...field("disease_status")} + id="disease_status" + label="COVID Disease Status" + options={diseaseStatus} + optionLabel={(o) => o} + optionValue={(o) => o} + required /> - - ) : ( -
- +
+ o} + optionValue={(o) => o} + required />
- )} -
-
-
- - } - title={ -

- COVID Details -

- } - > -
-
-
- option.label} - optionValue={(option) => option.value} - /> -
-
- option.label} - optionValue={(option) => option.value} - /> -
-
- option.label} - optionValue={(option) => option.value} - /> -
+
+
-
- - { -
-
- -
-
- - option.label - } - optionValue={(option) => option.value} - /> -
-
- o} - optionValue={(o) => o} - /> -
-
- -
-
- } -
+
+ option.label} + optionValue={(option) => option.value} + /> -
-
- -
- -
- -
+
+
-
- o} - optionValue={(o) => o} - required - /> -
-
- o} - optionValue={(o) => o} - required - /> -
-
- -
-
- option.label} - optionValue={(option) => option.value} - /> - -
- -
-
-
-
- -
- -
- -
-
- -
+
+
+ +
-
- -
-
- -
+
+ +
+
+
-
- -
-
-

- Medical History -

-
-
- -
-
- -
-
- - Any medical history? (Comorbidities) - -
- {MEDICAL_HISTORY_CHOICES.map((i) => { - return renderMedicalHistory( - i.id as number, - i.text, - field - ); - })} +
+ +
+
+
-
+
+ +
+
+

+ Medical History +

+
+
+ +
-
- +
+ +
+
+ + Any medical history? (Comorbidities) + +
+ {MEDICAL_HISTORY_CHOICES.map((i) => { + return renderMedicalHistory( + i.id as number, + i.text, + field + ); + })}
+ +
-
- o} - optionValue={(o: any) => o} - /> -
+
+
-
-
-
-

- Insurance Details -

- - setInsuranceDetails([ - ...insuranceDetails, - { - id: "", - subscriber_id: "", - policy_id: "", - insurer_id: "", - insurer_name: "", - }, - ]) - } - data-testid="add-insurance-button" - > - - Add Insurance Details - + +
+ o} + optionValue={(o: any) => o} + />
- setInsuranceDetails(value)} - error={insuranceDetailsError} - gridView - />
- - ); - }} - -
- +
+
+
+

+ Insurance Details +

+ + setInsuranceDetails([ + ...insuranceDetails, + { + id: "", + subscriber_id: "", + policy_id: "", + insurer_id: "", + insurer_name: "", + }, + ]) + } + data-testid="add-insurance-button" + > + + Add Insurance Details + +
+ setInsuranceDetails(value)} + error={insuranceDetailsError} + gridView + /> +
+ + ); + }} + +
-
+
- ); +
+ ); }; From cbe9b9534f66852e48a08c45cd48494409d7d71a Mon Sep 17 00:00:00 2001 From: Ashraf Mohammed <98876115+AshrafMd-1@users.noreply.github.com> Date: Tue, 16 Apr 2024 23:42:23 +0530 Subject: [PATCH 03/11] Update ManagePatients.tsx --- src/Components/Patient/ManagePatients.tsx | 32 +++++++++++------------ 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/Components/Patient/ManagePatients.tsx b/src/Components/Patient/ManagePatients.tsx index da74bd6997..d04c59aaf0 100644 --- a/src/Components/Patient/ManagePatients.tsx +++ b/src/Components/Patient/ManagePatients.tsx @@ -364,7 +364,7 @@ export const PatientManager = () => { let category_name; if (qParams.category) { category_name = PATIENT_CATEGORIES.find( - (item: any) => qParams.category === item.id, + (item: any) => qParams.category === item.id )?.text; return String(category_name); @@ -401,14 +401,14 @@ export const PatientManager = () => { external_id: qParams.last_consultation_current_bed__location, }, prefetch: !!qParams.last_consultation_current_bed__location, - }, + } ); const { data: permittedFacilities } = useQuery( routes.getPermittedFacilities, { query: { limit: 1 }, - }, + } ); const LastAdmittedToTypeBadges = () => { @@ -644,7 +644,7 @@ export const PatientManager = () => { !patient.is_active ) && dayjs(patient.last_consultation?.modified_date).isBefore( - new Date().getTime() - 24 * 60 * 60 * 1000, + new Date().getTime() - 24 * 60 * 60 * 1000 ) && ( { (resp) => resp.text === patient.last_consultation?.last_daily_round - ?.ventilator_interface, + ?.ventilator_interface )?.id }
@@ -954,12 +954,12 @@ export const PatientManager = () => { badge("Is Antenatal", "is_antenatal"), badge( "Is Medico-Legal Case", - "last_consultation_medico_legal_case", + "last_consultation_medico_legal_case" ), value( "Facility", "facility", - qParams.facility ? facilityData?.name || "" : "", + qParams.facility ? facilityData?.name || "" : "" ), value( "Location", @@ -967,13 +967,13 @@ export const PatientManager = () => { qParams.last_consultation_current_bed__location ? facilityAssetLocationData?.name || qParams.last_consultation_current_bed__locations - : "", + : "" ), badge("Facility Type", "facility_type"), value( "District", "district", - qParams.district ? districtData?.name || "" : "", + qParams.district ? districtData?.name || "" : "" ), ordering(), value("Category", "category", getTheCategoryFromId()), @@ -982,12 +982,12 @@ export const PatientManager = () => { "Respiratory Support", "ventilator_interface", qParams.ventilator_interface && - t(`RESPIRATORY_SUPPORT_${qParams.ventilator_interface}`), + t(`RESPIRATORY_SUPPORT_${qParams.ventilator_interface}`) ), value( "Gender", "gender", - parseOptionId(GENDER_TYPES, qParams.gender) || "", + parseOptionId(GENDER_TYPES, qParams.gender) || "" ), { name: "Admitted to", @@ -1005,15 +1005,15 @@ export const PatientManager = () => { value( DIAGNOSES_FILTER_LABELS[key], key, - getDiagnosisFilterValue(key).join(", "), - ), + getDiagnosisFilterValue(key).join(", ") + ) ), 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", + "last_consultation_symptoms_onset_date" ), ...dateRange("Last vaccinated", "last_vaccinated_date"), { @@ -1025,8 +1025,8 @@ export const PatientManager = () => { "last_consultation__new_discharge_reason", parseOptionId( DISCHARGE_REASONS, - qParams.last_consultation__new_discharge_reason, - ) || "", + qParams.last_consultation__new_discharge_reason + ) || "" ), ]} children={ From ea46df6a8fd157eec15216b5f9beec07d1163305 Mon Sep 17 00:00:00 2001 From: Ashraf Mohammed Date: Tue, 16 Apr 2024 23:50:33 +0530 Subject: [PATCH 04/11] fix linting --- src/Components/Patient/ManagePatients.tsx | 34 +++++++++++------------ 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/Components/Patient/ManagePatients.tsx b/src/Components/Patient/ManagePatients.tsx index d04c59aaf0..cdeb7cf9df 100644 --- a/src/Components/Patient/ManagePatients.tsx +++ b/src/Components/Patient/ManagePatients.tsx @@ -364,7 +364,7 @@ export const PatientManager = () => { let category_name; if (qParams.category) { category_name = PATIENT_CATEGORIES.find( - (item: any) => qParams.category === item.id + (item: any) => qParams.category === item.id, )?.text; return String(category_name); @@ -401,14 +401,14 @@ export const PatientManager = () => { external_id: qParams.last_consultation_current_bed__location, }, prefetch: !!qParams.last_consultation_current_bed__location, - } + }, ); const { data: permittedFacilities } = useQuery( routes.getPermittedFacilities, { query: { limit: 1 }, - } + }, ); const LastAdmittedToTypeBadges = () => { @@ -644,7 +644,7 @@ export const PatientManager = () => { !patient.is_active ) && dayjs(patient.last_consultation?.modified_date).isBefore( - new Date().getTime() - 24 * 60 * 60 * 1000 + new Date().getTime() - 24 * 60 * 60 * 1000, ) && ( { (resp) => resp.text === patient.last_consultation?.last_daily_round - ?.ventilator_interface + ?.ventilator_interface, )?.id }
@@ -752,7 +752,7 @@ export const PatientManager = () => { authUser.home_facility_object?.id ) { navigate( - `/facility/${authUser.home_facility_object.id}/patient` + `/facility/${authUser.home_facility_object.id}/patient`, ); } else setShowDialog("create"); }} @@ -954,12 +954,12 @@ export const PatientManager = () => { badge("Is Antenatal", "is_antenatal"), badge( "Is Medico-Legal Case", - "last_consultation_medico_legal_case" + "last_consultation_medico_legal_case", ), value( "Facility", "facility", - qParams.facility ? facilityData?.name || "" : "" + qParams.facility ? facilityData?.name || "" : "", ), value( "Location", @@ -967,13 +967,13 @@ export const PatientManager = () => { qParams.last_consultation_current_bed__location ? facilityAssetLocationData?.name || qParams.last_consultation_current_bed__locations - : "" + : "", ), badge("Facility Type", "facility_type"), value( "District", "district", - qParams.district ? districtData?.name || "" : "" + qParams.district ? districtData?.name || "" : "", ), ordering(), value("Category", "category", getTheCategoryFromId()), @@ -982,12 +982,12 @@ export const PatientManager = () => { "Respiratory Support", "ventilator_interface", qParams.ventilator_interface && - t(`RESPIRATORY_SUPPORT_${qParams.ventilator_interface}`) + t(`RESPIRATORY_SUPPORT_${qParams.ventilator_interface}`), ), value( "Gender", "gender", - parseOptionId(GENDER_TYPES, qParams.gender) || "" + parseOptionId(GENDER_TYPES, qParams.gender) || "", ), { name: "Admitted to", @@ -1005,15 +1005,15 @@ export const PatientManager = () => { value( DIAGNOSES_FILTER_LABELS[key], key, - getDiagnosisFilterValue(key).join(", ") - ) + getDiagnosisFilterValue(key).join(", "), + ), ), 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" + "last_consultation_symptoms_onset_date", ), ...dateRange("Last vaccinated", "last_vaccinated_date"), { @@ -1025,8 +1025,8 @@ export const PatientManager = () => { "last_consultation__new_discharge_reason", parseOptionId( DISCHARGE_REASONS, - qParams.last_consultation__new_discharge_reason - ) || "" + qParams.last_consultation__new_discharge_reason, + ) || "", ), ]} children={ From 4cc00f959a8cd52370f8722e4901915384e56745 Mon Sep 17 00:00:00 2001 From: Ashraf Mohammed Date: Sat, 27 Apr 2024 00:43:33 +0530 Subject: [PATCH 05/11] add error notification --- src/Components/Patient/ManagePatients.tsx | 46 +++++++++------ src/Components/Patient/PatientHome.tsx | 68 ++++++++++++++--------- 2 files changed, 69 insertions(+), 45 deletions(-) diff --git a/src/Components/Patient/ManagePatients.tsx b/src/Components/Patient/ManagePatients.tsx index dfb1e8699e..880d4216cf 100644 --- a/src/Components/Patient/ManagePatients.tsx +++ b/src/Components/Patient/ManagePatients.tsx @@ -365,7 +365,7 @@ export const PatientManager = () => { let category_name; if (qParams.category) { category_name = PATIENT_CATEGORIES.find( - (item: any) => qParams.category === item.id, + (item: any) => qParams.category === item.id )?.text; return String(category_name); @@ -402,14 +402,14 @@ export const PatientManager = () => { external_id: qParams.last_consultation_current_bed__location, }, prefetch: !!qParams.last_consultation_current_bed__location, - }, + } ); const { data: permittedFacilities } = useQuery( routes.getPermittedFacilities, { query: { limit: 1 }, - }, + } ); const LastAdmittedToTypeBadges = () => { @@ -645,7 +645,7 @@ export const PatientManager = () => { !patient.is_active ) && dayjs(patient.last_consultation?.modified_date).isBefore( - new Date().getTime() - 24 * 60 * 60 * 1000, + new Date().getTime() - 24 * 60 * 60 * 1000 ) && ( { (resp) => resp.text === patient.last_consultation?.last_daily_round - ?.ventilator_interface, + ?.ventilator_interface )?.id }
@@ -744,16 +744,26 @@ export const PatientManager = () => { id="add-patient-details" onClick={() => { const showAllFacilityUsers = ["DistrictAdmin", "StateAdmin"]; - if (qParams.facility) + if ( + qParams.facility && + showAllFacilityUsers.includes(authUser.user_type) + ) navigate(`/facility/${qParams.facility}/patient`); else if (onlyAccessibleFacility) navigate(`/facility/${onlyAccessibleFacility.id}/patient`); else if ( + !showAllFacilityUsers.includes(authUser.user_type) && + authUser.home_facility_object?.id !== qParams.facility + ) { + Notification.Error({ + msg: "Oops! Non-Home facility users don't have permission to perform this action.", + }); + } else if ( !showAllFacilityUsers.includes(authUser.user_type) && authUser.home_facility_object?.id ) { navigate( - `/facility/${authUser.home_facility_object.id}/patient`, + `/facility/${authUser.home_facility_object.id}/patient` ); } else setShowDialog("create"); }} @@ -956,12 +966,12 @@ export const PatientManager = () => { badge("Review Missed", "review_missed"), badge( "Is Medico-Legal Case", - "last_consultation_medico_legal_case", + "last_consultation_medico_legal_case" ), value( "Facility", "facility", - qParams.facility ? facilityData?.name || "" : "", + qParams.facility ? facilityData?.name || "" : "" ), value( "Location", @@ -969,13 +979,13 @@ export const PatientManager = () => { qParams.last_consultation_current_bed__location ? facilityAssetLocationData?.name || qParams.last_consultation_current_bed__locations - : "", + : "" ), badge("Facility Type", "facility_type"), value( "District", "district", - qParams.district ? districtData?.name || "" : "", + qParams.district ? districtData?.name || "" : "" ), ordering(), value("Category", "category", getTheCategoryFromId()), @@ -984,12 +994,12 @@ export const PatientManager = () => { "Respiratory Support", "ventilator_interface", qParams.ventilator_interface && - t(`RESPIRATORY_SUPPORT_${qParams.ventilator_interface}`), + t(`RESPIRATORY_SUPPORT_${qParams.ventilator_interface}`) ), value( "Gender", "gender", - parseOptionId(GENDER_TYPES, qParams.gender) || "", + parseOptionId(GENDER_TYPES, qParams.gender) || "" ), { name: "Admitted to", @@ -1007,15 +1017,15 @@ export const PatientManager = () => { value( DIAGNOSES_FILTER_LABELS[key], key, - getDiagnosisFilterValue(key).join(", "), - ), + getDiagnosisFilterValue(key).join(", ") + ) ), 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", + "last_consultation_symptoms_onset_date" ), ...dateRange("Last vaccinated", "last_vaccinated_date"), { @@ -1027,8 +1037,8 @@ export const PatientManager = () => { "last_consultation__new_discharge_reason", parseOptionId( DISCHARGE_REASONS, - qParams.last_consultation__new_discharge_reason, - ) || "", + qParams.last_consultation__new_discharge_reason + ) || "" ), ]} children={ diff --git a/src/Components/Patient/PatientHome.tsx b/src/Components/Patient/PatientHome.tsx index 3e1e9b0a09..6d98c63faf 100644 --- a/src/Components/Patient/PatientHome.tsx +++ b/src/Components/Patient/PatientHome.tsx @@ -80,7 +80,7 @@ export const PatientHome = (props: any) => { }, }); navigate( - `/facility/${shift.assigned_facility}/patient/${shift.patient}/consultation`, + `/facility/${shift.assigned_facility}/patient/${shift.patient}/consultation` ); }; @@ -170,7 +170,7 @@ export const PatientHome = (props: any) => { patient: id, }, prefetch: isShiftClicked, - }, + } ); const confirmApproval = (status: number, sample: any) => { @@ -208,7 +208,7 @@ export const PatientHome = (props: any) => { } const patientGender = GENDER_TYPES.find( - (i) => i.id === patientData.gender, + (i) => i.id === patientData.gender )?.text; let patientMedHis: any[] = []; @@ -327,7 +327,7 @@ export const PatientHome = (props: any) => { disabled={!patientData.is_active} onClick={() => navigate( - `/facility/${patientData?.facility}/patient/${id}/consultation`, + `/facility/${patientData?.facility}/patient/${id}/consultation` ) } > @@ -642,11 +642,25 @@ export const PatientHome = (props: any) => { className="mt-4 w-full" disabled={!patientData.is_active} authorizeFor={NonReadOnlyUsers} - onClick={() => - navigate( - `/facility/${patientData?.facility}/patient/${id}/update`, - ) - } + onClick={() => { + const showAllFacilityUsers = [ + "DistrictAdmin", + "StateAdmin", + ]; + if ( + !showAllFacilityUsers.includes(authUser.user_type) && + authUser.home_facility_object?.id !== + patientData.facility + ) { + Notification.Error({ + msg: "Oops! Non-Home facility users don't have permission to perform this action.", + }); + } else { + navigate( + `/facility/${patientData?.facility}/patient/${id}/update` + ); + } + }} > Update Details @@ -830,7 +844,7 @@ export const PatientHome = (props: any) => { !shift.patient_object.allow_transfer || !( ["DistrictAdmin", "StateAdmin"].includes( - authUser.user_type, + authUser.user_type ) || authUser.home_facility_object?.id === shift.assigned_facility @@ -943,7 +957,7 @@ export const PatientHome = (props: any) => { !patientData.ongoing_medication && !(patientData.gender === 2 && patientData.is_antenatal) && !patientData.medical_history?.some( - (history) => history.disease !== "NO", + (history) => history.disease !== "NO" ) && (
No Medical History Available @@ -1020,12 +1034,12 @@ export const PatientHome = (props: any) => { "w-full rounded-lg border", isPatientEligibleForNewConsultation(patientData) ? "cursor-pointer border-green-700 hover:bg-primary-400" - : "border-gray-700 text-gray-700 hover:cursor-not-allowed", + : "border-gray-700 text-gray-700 hover:cursor-not-allowed" )} onClick={() => isPatientEligibleForNewConsultation(patientData) && navigate( - `/facility/${patientData?.facility}/patient/${id}/consultation`, + `/facility/${patientData?.facility}/patient/${id}/consultation` ) } > @@ -1033,14 +1047,14 @@ export const PatientHome = (props: any) => { className={classNames( "h-full space-y-2 rounded-lg bg-white p-4 shadow", isPatientEligibleForNewConsultation(patientData) && - "hover:bg-gray-200", + "hover:bg-gray-200" )} >
@@ -1079,7 +1093,7 @@ export const PatientHome = (props: any) => { className="w-full" onClick={() => navigate( - `/facility/${patientData?.facility}/patient/${id}/files/`, + `/facility/${patientData?.facility}/patient/${id}/files/` ) } > @@ -1140,7 +1154,7 @@ export const PatientHome = (props: any) => { onClick={() => { if (!isPatientInactive(patientData, facilityId)) { navigate( - `/facility/${patientData?.facility}/patient/${id}/sample-test`, + `/facility/${patientData?.facility}/patient/${id}/sample-test` ); } }} @@ -1150,7 +1164,7 @@ export const PatientHome = (props: any) => { "h-full space-y-2 rounded-lg border bg-white p-4 shadow", isPatientInactive(patientData, facilityId) ? " border-gray-700 hover:cursor-not-allowed" - : " border-green-700 hover:cursor-pointer hover:bg-gray-200", + : " border-green-700 hover:cursor-pointer hover:bg-gray-200" )} >
{ className="w-full" onClick={() => navigate( - `/facility/${patientData?.facility}/patient/${id}/notes`, + `/facility/${patientData?.facility}/patient/${id}/notes` ) } > @@ -1210,7 +1224,7 @@ export const PatientHome = (props: any) => { "h-full space-y-2 rounded-lg border bg-white p-4 shadow", isPatientInactive(patientData, facilityId) ? "border-gray-700 hover:cursor-not-allowed" - : "border-green-700 hover:cursor-pointer hover:bg-gray-200", + : "border-green-700 hover:cursor-pointer hover:bg-gray-200" )} >
{ "text-center", isPatientInactive(patientData, facilityId) ? "text-gray-700" - : "text-green-700", + : "text-green-700" )} > @@ -1231,7 +1245,7 @@ export const PatientHome = (props: any) => { "text-center text-sm font-medium", isPatientInactive(patientData, facilityId) ? "text-gray-700" - : "text-black", + : "text-black" )} > Assign to a volunteer @@ -1256,7 +1270,7 @@ export const PatientHome = (props: any) => { } onClick={() => navigate( - `/facility/${patientData?.facility}/patient/${id}/consultation`, + `/facility/${patientData?.facility}/patient/${id}/consultation` ) } > @@ -1285,7 +1299,7 @@ export const PatientHome = (props: any) => { id="upload-patient-files" onClick={() => navigate( - `/facility/${patientData?.facility}/patient/${id}/files`, + `/facility/${patientData?.facility}/patient/${id}/files` ) } > @@ -1301,7 +1315,7 @@ export const PatientHome = (props: any) => { disabled={isPatientInactive(patientData, facilityId)} onClick={() => navigate( - `/facility/${facilityId}/patient/${id}/shift/new`, + `/facility/${facilityId}/patient/${id}/shift/new` ) } authorizeFor={NonReadOnlyUsers} @@ -1318,7 +1332,7 @@ export const PatientHome = (props: any) => { disabled={isPatientInactive(patientData, facilityId)} onClick={() => navigate( - `/facility/${patientData?.facility}/patient/${id}/sample-test`, + `/facility/${patientData?.facility}/patient/${id}/sample-test` ) } authorizeFor={NonReadOnlyUsers} @@ -1334,7 +1348,7 @@ export const PatientHome = (props: any) => { className="w-full" onClick={() => navigate( - `/facility/${patientData?.facility}/patient/${id}/notes`, + `/facility/${patientData?.facility}/patient/${id}/notes` ) } > From 0b4ec2f3c549f73f2f59fe08849cba5ad436b53d Mon Sep 17 00:00:00 2001 From: Ashraf Mohammed Date: Sat, 27 Apr 2024 21:30:04 +0530 Subject: [PATCH 06/11] fix lint --- src/Components/Patient/ManagePatients.tsx | 4 ++-- src/Components/Patient/PatientHome.tsx | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Components/Patient/ManagePatients.tsx b/src/Components/Patient/ManagePatients.tsx index 45191c7426..3c29a29432 100644 --- a/src/Components/Patient/ManagePatients.tsx +++ b/src/Components/Patient/ManagePatients.tsx @@ -747,11 +747,11 @@ export const PatientManager = () => { else if ( !showAllFacilityUsers.includes(authUser.user_type) && authUser.home_facility_object?.id !== qParams.facility - ) { + ) Notification.Error({ msg: "Oops! Non-Home facility users don't have permission to perform this action.", }); - } else if ( + else if ( !showAllFacilityUsers.includes(authUser.user_type) && authUser.home_facility_object?.id ) { diff --git a/src/Components/Patient/PatientHome.tsx b/src/Components/Patient/PatientHome.tsx index 6d98c63faf..69db6fcf38 100644 --- a/src/Components/Patient/PatientHome.tsx +++ b/src/Components/Patient/PatientHome.tsx @@ -822,6 +822,7 @@ export const PatientHome = (props: any) => {
+
Date: Sat, 27 Apr 2024 21:36:23 +0530 Subject: [PATCH 07/11] fix lint --- src/Components/Patient/ManagePatients.tsx | 34 ++++++++--------- src/Components/Patient/PatientHome.tsx | 46 +++++++++++------------ 2 files changed, 40 insertions(+), 40 deletions(-) diff --git a/src/Components/Patient/ManagePatients.tsx b/src/Components/Patient/ManagePatients.tsx index 3c29a29432..a53e53e0d2 100644 --- a/src/Components/Patient/ManagePatients.tsx +++ b/src/Components/Patient/ManagePatients.tsx @@ -358,7 +358,7 @@ export const PatientManager = () => { let category_name; if (qParams.category) { category_name = PATIENT_CATEGORIES.find( - (item: any) => qParams.category === item.id + (item: any) => qParams.category === item.id, )?.text; return String(category_name); @@ -395,14 +395,14 @@ export const PatientManager = () => { external_id: qParams.last_consultation_current_bed__location, }, prefetch: !!qParams.last_consultation_current_bed__location, - } + }, ); const { data: permittedFacilities } = useQuery( routes.getPermittedFacilities, { query: { limit: 1 }, - } + }, ); const LastAdmittedToTypeBadges = () => { @@ -638,7 +638,7 @@ export const PatientManager = () => { !patient.is_active ) && dayjs(patient.last_consultation?.modified_date).isBefore( - new Date().getTime() - 24 * 60 * 60 * 1000 + new Date().getTime() - 24 * 60 * 60 * 1000, ) && ( { (resp) => resp.text === patient.last_consultation?.last_daily_round - ?.ventilator_interface + ?.ventilator_interface, )?.id }
@@ -756,7 +756,7 @@ export const PatientManager = () => { authUser.home_facility_object?.id ) { navigate( - `/facility/${authUser.home_facility_object.id}/patient` + `/facility/${authUser.home_facility_object.id}/patient`, ); } else setShowDialog("create"); }} @@ -959,12 +959,12 @@ export const PatientManager = () => { badge("Review Missed", "review_missed"), badge( "Is Medico-Legal Case", - "last_consultation_medico_legal_case" + "last_consultation_medico_legal_case", ), value( "Facility", "facility", - qParams.facility ? facilityData?.name || "" : "" + qParams.facility ? facilityData?.name || "" : "", ), value( "Location", @@ -972,13 +972,13 @@ export const PatientManager = () => { qParams.last_consultation_current_bed__location ? facilityAssetLocationData?.name || qParams.last_consultation_current_bed__locations - : "" + : "", ), badge("Facility Type", "facility_type"), value( "District", "district", - qParams.district ? districtData?.name || "" : "" + qParams.district ? districtData?.name || "" : "", ), ordering(), value("Category", "category", getTheCategoryFromId()), @@ -987,12 +987,12 @@ export const PatientManager = () => { "Respiratory Support", "ventilator_interface", qParams.ventilator_interface && - t(`RESPIRATORY_SUPPORT_${qParams.ventilator_interface}`) + t(`RESPIRATORY_SUPPORT_${qParams.ventilator_interface}`), ), value( "Gender", "gender", - parseOptionId(GENDER_TYPES, qParams.gender) || "" + parseOptionId(GENDER_TYPES, qParams.gender) || "", ), { name: "Admitted to", @@ -1010,15 +1010,15 @@ export const PatientManager = () => { value( DIAGNOSES_FILTER_LABELS[key], key, - getDiagnosisFilterValue(key).join(", ") - ) + getDiagnosisFilterValue(key).join(", "), + ), ), 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" + "last_consultation_symptoms_onset_date", ), ...dateRange("Last vaccinated", "last_vaccinated_date"), { @@ -1030,8 +1030,8 @@ export const PatientManager = () => { "last_consultation__new_discharge_reason", parseOptionId( DISCHARGE_REASONS, - qParams.last_consultation__new_discharge_reason - ) || "" + qParams.last_consultation__new_discharge_reason, + ) || "", ), ]} children={ diff --git a/src/Components/Patient/PatientHome.tsx b/src/Components/Patient/PatientHome.tsx index 69db6fcf38..a4f6adc8d1 100644 --- a/src/Components/Patient/PatientHome.tsx +++ b/src/Components/Patient/PatientHome.tsx @@ -80,7 +80,7 @@ export const PatientHome = (props: any) => { }, }); navigate( - `/facility/${shift.assigned_facility}/patient/${shift.patient}/consultation` + `/facility/${shift.assigned_facility}/patient/${shift.patient}/consultation`, ); }; @@ -170,7 +170,7 @@ export const PatientHome = (props: any) => { patient: id, }, prefetch: isShiftClicked, - } + }, ); const confirmApproval = (status: number, sample: any) => { @@ -208,7 +208,7 @@ export const PatientHome = (props: any) => { } const patientGender = GENDER_TYPES.find( - (i) => i.id === patientData.gender + (i) => i.id === patientData.gender, )?.text; let patientMedHis: any[] = []; @@ -327,7 +327,7 @@ export const PatientHome = (props: any) => { disabled={!patientData.is_active} onClick={() => navigate( - `/facility/${patientData?.facility}/patient/${id}/consultation` + `/facility/${patientData?.facility}/patient/${id}/consultation`, ) } > @@ -657,7 +657,7 @@ export const PatientHome = (props: any) => { }); } else { navigate( - `/facility/${patientData?.facility}/patient/${id}/update` + `/facility/${patientData?.facility}/patient/${id}/update`, ); } }} @@ -845,7 +845,7 @@ export const PatientHome = (props: any) => { !shift.patient_object.allow_transfer || !( ["DistrictAdmin", "StateAdmin"].includes( - authUser.user_type + authUser.user_type, ) || authUser.home_facility_object?.id === shift.assigned_facility @@ -958,7 +958,7 @@ export const PatientHome = (props: any) => { !patientData.ongoing_medication && !(patientData.gender === 2 && patientData.is_antenatal) && !patientData.medical_history?.some( - (history) => history.disease !== "NO" + (history) => history.disease !== "NO", ) && (
No Medical History Available @@ -1035,12 +1035,12 @@ export const PatientHome = (props: any) => { "w-full rounded-lg border", isPatientEligibleForNewConsultation(patientData) ? "cursor-pointer border-green-700 hover:bg-primary-400" - : "border-gray-700 text-gray-700 hover:cursor-not-allowed" + : "border-gray-700 text-gray-700 hover:cursor-not-allowed", )} onClick={() => isPatientEligibleForNewConsultation(patientData) && navigate( - `/facility/${patientData?.facility}/patient/${id}/consultation` + `/facility/${patientData?.facility}/patient/${id}/consultation`, ) } > @@ -1048,14 +1048,14 @@ export const PatientHome = (props: any) => { className={classNames( "h-full space-y-2 rounded-lg bg-white p-4 shadow", isPatientEligibleForNewConsultation(patientData) && - "hover:bg-gray-200" + "hover:bg-gray-200", )} >
@@ -1094,7 +1094,7 @@ export const PatientHome = (props: any) => { className="w-full" onClick={() => navigate( - `/facility/${patientData?.facility}/patient/${id}/files/` + `/facility/${patientData?.facility}/patient/${id}/files/`, ) } > @@ -1155,7 +1155,7 @@ export const PatientHome = (props: any) => { onClick={() => { if (!isPatientInactive(patientData, facilityId)) { navigate( - `/facility/${patientData?.facility}/patient/${id}/sample-test` + `/facility/${patientData?.facility}/patient/${id}/sample-test`, ); } }} @@ -1165,7 +1165,7 @@ export const PatientHome = (props: any) => { "h-full space-y-2 rounded-lg border bg-white p-4 shadow", isPatientInactive(patientData, facilityId) ? " border-gray-700 hover:cursor-not-allowed" - : " border-green-700 hover:cursor-pointer hover:bg-gray-200" + : " border-green-700 hover:cursor-pointer hover:bg-gray-200", )} >
{ className="w-full" onClick={() => navigate( - `/facility/${patientData?.facility}/patient/${id}/notes` + `/facility/${patientData?.facility}/patient/${id}/notes`, ) } > @@ -1225,7 +1225,7 @@ export const PatientHome = (props: any) => { "h-full space-y-2 rounded-lg border bg-white p-4 shadow", isPatientInactive(patientData, facilityId) ? "border-gray-700 hover:cursor-not-allowed" - : "border-green-700 hover:cursor-pointer hover:bg-gray-200" + : "border-green-700 hover:cursor-pointer hover:bg-gray-200", )} >
{ "text-center", isPatientInactive(patientData, facilityId) ? "text-gray-700" - : "text-green-700" + : "text-green-700", )} > @@ -1246,7 +1246,7 @@ export const PatientHome = (props: any) => { "text-center text-sm font-medium", isPatientInactive(patientData, facilityId) ? "text-gray-700" - : "text-black" + : "text-black", )} > Assign to a volunteer @@ -1271,7 +1271,7 @@ export const PatientHome = (props: any) => { } onClick={() => navigate( - `/facility/${patientData?.facility}/patient/${id}/consultation` + `/facility/${patientData?.facility}/patient/${id}/consultation`, ) } > @@ -1300,7 +1300,7 @@ export const PatientHome = (props: any) => { id="upload-patient-files" onClick={() => navigate( - `/facility/${patientData?.facility}/patient/${id}/files` + `/facility/${patientData?.facility}/patient/${id}/files`, ) } > @@ -1316,7 +1316,7 @@ export const PatientHome = (props: any) => { disabled={isPatientInactive(patientData, facilityId)} onClick={() => navigate( - `/facility/${facilityId}/patient/${id}/shift/new` + `/facility/${facilityId}/patient/${id}/shift/new`, ) } authorizeFor={NonReadOnlyUsers} @@ -1333,7 +1333,7 @@ export const PatientHome = (props: any) => { disabled={isPatientInactive(patientData, facilityId)} onClick={() => navigate( - `/facility/${patientData?.facility}/patient/${id}/sample-test` + `/facility/${patientData?.facility}/patient/${id}/sample-test`, ) } authorizeFor={NonReadOnlyUsers} @@ -1349,7 +1349,7 @@ export const PatientHome = (props: any) => { className="w-full" onClick={() => navigate( - `/facility/${patientData?.facility}/patient/${id}/notes` + `/facility/${patientData?.facility}/patient/${id}/notes`, ) } > From 2e81525b39e8931e194ed3e393788b356f364e98 Mon Sep 17 00:00:00 2001 From: Ashraf Mohammed Date: Wed, 1 May 2024 15:21:34 +0530 Subject: [PATCH 08/11] fix codes --- .../ExternalResult/FacilitiesSelectDialogue.tsx | 4 ++-- src/Components/Patient/PatientRegister.tsx | 16 +++++++++------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/Components/ExternalResult/FacilitiesSelectDialogue.tsx b/src/Components/ExternalResult/FacilitiesSelectDialogue.tsx index 03f6e92d72..4dfe885027 100644 --- a/src/Components/ExternalResult/FacilitiesSelectDialogue.tsx +++ b/src/Components/ExternalResult/FacilitiesSelectDialogue.tsx @@ -34,12 +34,12 @@ const FacilitiesSelectDialog = (props: Props) => { district={ authUser?.user_type === "DistrictAdmin" ? authUser?.district?.toString() - : "" + : undefined } state={ authUser?.user_type === "StateAdmin" ? authUser?.state?.toString() - : "" + : undefined } />
diff --git a/src/Components/Patient/PatientRegister.tsx b/src/Components/Patient/PatientRegister.tsx index 018b0d1101..f03793fd1d 100644 --- a/src/Components/Patient/PatientRegister.tsx +++ b/src/Components/Patient/PatientRegister.tsx @@ -1063,25 +1063,27 @@ export const PatientRegister = (props: PatientRegisterProps) => { } const PatientRegisterAuth = () => { - let check = false; const showAllFacilityUsers = ["DistrictAdmin", "StateAdmin"]; if ( !showAllFacilityUsers.includes(authUser.user_type) && authUser.home_facility_object?.id === facilityId ) { - check = true; - } else if ( + return true; + } + if ( authUser.user_type === "DistrictAdmin" && authUser.district === facilityObject?.district ) { - check = true; - } else if ( + return true; + } + if ( authUser.user_type === "StateAdmin" && authUser.state === facilityObject?.state ) { - check = true; + return true; } - return check; + + return false; }; if (!isLoading && facilityId && facilityObject && !PatientRegisterAuth()) { From 5523fe2e9233d61a237f44ffc8ec0f4ad6e09c5e Mon Sep 17 00:00:00 2001 From: Ashraf Mohammed Date: Mon, 13 May 2024 11:47:04 +0530 Subject: [PATCH 09/11] fix bug --- src/Components/Patient/ManagePatients.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Components/Patient/ManagePatients.tsx b/src/Components/Patient/ManagePatients.tsx index a53e53e0d2..856294378e 100644 --- a/src/Components/Patient/ManagePatients.tsx +++ b/src/Components/Patient/ManagePatients.tsx @@ -746,6 +746,7 @@ export const PatientManager = () => { navigate(`/facility/${onlyAccessibleFacility.id}/patient`); else if ( !showAllFacilityUsers.includes(authUser.user_type) && + qParams.facility && authUser.home_facility_object?.id !== qParams.facility ) Notification.Error({ From 3a3f5f37ca64bd98113b0881f9b7642d8a8adff8 Mon Sep 17 00:00:00 2001 From: Ashraf Mohammed Date: Mon, 13 May 2024 11:50:37 +0530 Subject: [PATCH 10/11] fix bug --- src/Components/Patient/ManagePatients.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Components/Patient/ManagePatients.tsx b/src/Components/Patient/ManagePatients.tsx index 856294378e..fdd888ad96 100644 --- a/src/Components/Patient/ManagePatients.tsx +++ b/src/Components/Patient/ManagePatients.tsx @@ -742,11 +742,9 @@ export const PatientManager = () => { showAllFacilityUsers.includes(authUser.user_type) ) navigate(`/facility/${qParams.facility}/patient`); - else if (onlyAccessibleFacility) - navigate(`/facility/${onlyAccessibleFacility.id}/patient`); else if ( - !showAllFacilityUsers.includes(authUser.user_type) && qParams.facility && + !showAllFacilityUsers.includes(authUser.user_type) && authUser.home_facility_object?.id !== qParams.facility ) Notification.Error({ @@ -759,7 +757,9 @@ export const PatientManager = () => { navigate( `/facility/${authUser.home_facility_object.id}/patient`, ); - } else setShowDialog("create"); + } else if (onlyAccessibleFacility) + navigate(`/facility/${onlyAccessibleFacility.id}/patient`); + else setShowDialog("create"); }} className="w-full lg:w-fit" > From 3fa79b3ca8702c4165b92e6f58406c24102553aa Mon Sep 17 00:00:00 2001 From: Ashraf Mohammed Date: Mon, 13 May 2024 13:01:09 +0530 Subject: [PATCH 11/11] dont allow null home facility users to add patient --- src/Components/Patient/ManagePatients.tsx | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Components/Patient/ManagePatients.tsx b/src/Components/Patient/ManagePatients.tsx index 1c40e273ee..5ebfeb12d6 100644 --- a/src/Components/Patient/ManagePatients.tsx +++ b/src/Components/Patient/ManagePatients.tsx @@ -774,6 +774,13 @@ export const PatientManager = () => { ); } else if (onlyAccessibleFacility) navigate(`/facility/${onlyAccessibleFacility.id}/patient`); + else if ( + !showAllFacilityUsers.includes(authUser.user_type) && + !authUser.home_facility_object?.id + ) + Notification.Error({ + msg: "Oops! No home facility found", + }); else setShowDialog("create"); }} className="w-full lg:w-fit"