diff --git a/src/Components/Common/LocationSelect.tsx b/src/Components/Common/LocationSelect.tsx index a4ad5f284ea..ef7280f1907 100644 --- a/src/Components/Common/LocationSelect.tsx +++ b/src/Components/Common/LocationSelect.tsx @@ -5,6 +5,7 @@ import AutocompleteFormField from "../Form/FormFields/Autocomplete"; import AutocompleteMultiSelectFormField from "../Form/FormFields/AutocompleteMultiselect"; interface LocationSelectProps { name: string; + disabled?: boolean; margin?: string; errors: string; className?: string; @@ -26,6 +27,7 @@ export const LocationSelect = (props: LocationSelectProps) => { errors, className = "", facilityId, + disabled = false, } = props; const [locations, setLocations] = useState<{ name: string; id: string }[]>( [] @@ -40,6 +42,7 @@ export const LocationSelect = (props: LocationSelectProps) => { }; useEffect(() => { + if (!facilityId) return; const params = { limit: 14, search_text: query, @@ -56,6 +59,7 @@ export const LocationSelect = (props: LocationSelectProps) => { return props.multiple ? ( handleValueChange(value as unknown as string[])} @@ -72,6 +76,7 @@ export const LocationSelect = (props: LocationSelectProps) => { ) : ( handleValueChange([value])} diff --git a/src/Components/Form/AutoCompleteAsync.tsx b/src/Components/Form/AutoCompleteAsync.tsx index 5f33c6388c5..0d860b178ce 100644 --- a/src/Components/Form/AutoCompleteAsync.tsx +++ b/src/Components/Form/AutoCompleteAsync.tsx @@ -100,29 +100,31 @@ const AutoCompleteAsync = (props: Props) => { }} autoComplete="off" /> - -
- {hasSelection && !loading && !required && ( -
- { - e.preventDefault(); - onChange(null); - }} - /> - - {t("clear_selection")} - -
- )} - {loading ? ( - - ) : ( - - )} -
-
+ {!disabled && ( + +
+ {hasSelection && !loading && !required && ( +
+ { + e.preventDefault(); + onChange(null); + }} + /> + + {t("clear_selection")} + +
+ )} + {loading ? ( + + ) : ( + + )} +
+
+ )} diff --git a/src/Components/Form/FormFields/Autocomplete.tsx b/src/Components/Form/FormFields/Autocomplete.tsx index c4b3ea3686e..bf3840b2c44 100644 --- a/src/Components/Form/FormFields/Autocomplete.tsx +++ b/src/Components/Form/FormFields/Autocomplete.tsx @@ -160,32 +160,34 @@ export const Autocomplete = (props: AutocompleteProps) => { onBlur={() => value && setQuery("")} autoComplete="off" /> - -
- {value?.icon} - - {value && !props.isLoading && !props.required && ( -
- { - e.preventDefault(); - props.onChange(undefined); - }} - /> - - {t("clear_selection")} - -
- )} - - {props.isLoading ? ( - - ) : ( - - )} -
-
+ {!props.disabled && ( + +
+ {value?.icon} + + {value && !props.isLoading && !props.required && ( +
+ { + e.preventDefault(); + props.onChange(undefined); + }} + /> + + {t("clear_selection")} + +
+ )} + + {props.isLoading ? ( + + ) : ( + + )} +
+
+ )} diff --git a/src/Components/Form/FormFields/AutocompleteMultiselect.tsx b/src/Components/Form/FormFields/AutocompleteMultiselect.tsx index 35a125ae07d..9004dea939d 100644 --- a/src/Components/Form/FormFields/AutocompleteMultiselect.tsx +++ b/src/Components/Form/FormFields/AutocompleteMultiselect.tsx @@ -119,15 +119,17 @@ export const AutocompleteMutliSelect = ( onChange={(event) => setQuery(event.target.value.toLowerCase())} autoComplete="off" /> - -
- {props.isLoading ? ( - - ) : ( - - )} -
-
+ {!props.disabled && ( + +
+ {props.isLoading ? ( + + ) : ( + + )} +
+
+ )} {value.length !== 0 && (
diff --git a/src/Components/Patient/ManagePatients.tsx b/src/Components/Patient/ManagePatients.tsx index 6e83eb9bc91..0abc89ef187 100644 --- a/src/Components/Patient/ManagePatients.tsx +++ b/src/Components/Patient/ManagePatients.tsx @@ -16,6 +16,7 @@ import { getAllPatient, getAnyFacility, getDistrict, + getFacilityAssetLocation, getLocalBody, } from "../../Redux/actions"; import { statusType, useAbortableEffect } from "../../Common/utils"; @@ -104,6 +105,7 @@ export const PatientManager = () => { const [districtName, setDistrictName] = useState(""); const [localbodyName, setLocalbodyName] = useState(""); const [facilityBadgeName, setFacilityBadge] = useState(""); + const [locationBadgeName, setLocationBadge] = useState(""); const [phone_number, setPhoneNumber] = useState(""); const [phoneNumberError, setPhoneNumberError] = useState(""); const [emergency_phone_number, setEmergencyPhoneNumber] = useState(""); @@ -167,6 +169,7 @@ export const PatientManager = () => { : undefined, local_body: qParams.lsgBody || undefined, facility: qParams.facility, + location: qParams.location || undefined, facility_type: qParams.facility_type || undefined, district: qParams.district || undefined, offset: (qParams.page ? qParams.page - 1 : 0) * resultsPerPage, @@ -342,6 +345,7 @@ export const PatientManager = () => { qParams.last_consultation_admitted_bed_type_list, qParams.last_consultation_discharge_reason, qParams.facility, + qParams.location, qParams.facility_type, qParams.district, qParams.category, @@ -440,12 +444,29 @@ export const PatientManager = () => { [dispatch, qParams.facility] ); + const fetchLocationBadgeName = useCallback( + async (status: statusType) => { + const res = + qParams.location && + (await dispatch( + getFacilityAssetLocation(qParams.facility, qParams.location) + )); + + if (!status.aborted) { + setLocationBadge(res?.data?.name); + } + }, + [dispatch, qParams.location] + ); + useAbortableEffect( (status: statusType) => { fetchFacilityBadgeName(status); + fetchLocationBadgeName(status); }, - [fetchFacilityBadgeName] + [fetchFacilityBadgeName, fetchLocationBadgeName] ); + const LastAdmittedToTypeBadges = () => { const badge = (key: string, value: any, id: string) => { return ( @@ -933,6 +954,7 @@ export const PatientManager = () => { badge("COWIN ID", "covin_id"), badge("Is Antenatal", "is_antenatal"), value("Facility", "facility", facilityBadgeName), + value("Location", "location", locationBadgeName), badge("Facility Type", "facility_type"), value("District", "district", districtName), ordering(), diff --git a/src/Components/Patient/PatientFilter.tsx b/src/Components/Patient/PatientFilter.tsx index 205ac39ac9c..afaa43eae28 100644 --- a/src/Components/Patient/PatientFilter.tsx +++ b/src/Components/Patient/PatientFilter.tsx @@ -34,6 +34,7 @@ import FiltersSlideover from "../../CAREUI/interactive/FiltersSlideover"; import AccordionV2 from "../Common/components/AccordionV2"; import { dateQueryString } from "../../Utils/utils"; import dayjs from "dayjs"; +import { LocationSelect } from "../Common/LocationSelect"; const getDate = (value: any) => value && dayjs(value).isValid() && dayjs(value).toDate(); @@ -45,6 +46,7 @@ export default function PatientFilter(props: any) { const [filterState, setFilterState] = useMergeState({ district: filter.district || "", facility: filter.facility || "", + location: filter.location || "", facility_type: filter.facility_type || "", lsgBody: filter.lsgBody || "", facility_ref: null, @@ -100,6 +102,7 @@ export default function PatientFilter(props: any) { const clearFilterState = { district: "", facility: "", + location: "", facility_type: "", lsgBody: "", facility_ref: null, @@ -213,6 +216,7 @@ export default function PatientFilter(props: any) { const { district, facility, + location, facility_type, lsgBody, date_declared_positive_before, @@ -252,6 +256,7 @@ export default function PatientFilter(props: any) { district: district || "", lsgBody: lsgBody || "", facility: facility || "", + location: location || "", facility_type: facility_type || "", date_declared_positive_before: dateQueryString( date_declared_positive_before @@ -565,13 +570,29 @@ export default function PatientFilter(props: any) { setFacility(obj, "facility")} />
-
+ Location + + setFilterState({ + ...filterState, + location: selected, + }) + } + /> +
+
Facility type