Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Edit feature for facilities in organization | pincode, geo_organization info auto populates #9662

Open
wants to merge 43 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
03fd617
pincode updated
Mahendar0701 Jan 2, 2025
d1a6ca1
Merge branch 'develop' into facility-edit
Mahendar0701 Jan 2, 2025
7db9c3a
populated geo_organization values
Mahendar0701 Jan 3, 2025
080f442
Merge branch 'develop' into facility-edit
Mahendar0701 Jan 3, 2025
8159f13
Merge branch 'develop' into facility-edit
Mahendar0701 Jan 3, 2025
fc0413e
Merge branch 'develop' into facility-edit
Mahendar0701 Jan 3, 2025
d0daf9c
autofill of state and districts
Mahendar0701 Jan 4, 2025
f7db9bc
Merge branch 'develop' into facility-edit
Mahendar0701 Jan 4, 2025
02a4ca0
Merge branch 'facility-edit' of https://github.com/Mahendar0701/care_…
Mahendar0701 Jan 4, 2025
ab383d5
translation
Mahendar0701 Jan 4, 2025
7dff65f
commit
Mahendar0701 Jan 4, 2025
4eda986
added usequery
Mahendar0701 Jan 4, 2025
c811b60
Merge branch 'develop' into facility-edit
Mahendar0701 Jan 4, 2025
d9078ad
Merge branch 'develop' into facility-edit
Mahendar0701 Jan 5, 2025
884fc82
Merge branch 'develop' into facility-edit
Mahendar0701 Jan 5, 2025
0f49a53
Merge branch 'facility-edit' of https://github.com/Mahendar0701/care_…
Mahendar0701 Jan 5, 2025
b6b2318
Merge branch 'develop' into facility-edit
Mahendar0701 Jan 5, 2025
fd3241f
moved useFetchOrganizationByName organizationapi.ts
Mahendar0701 Jan 5, 2025
f9d4e49
Merge branch 'facility-edit' of https://github.com/Mahendar0701/care_…
Mahendar0701 Jan 5, 2025
3a9dcbf
Merge branch 'develop' into facility-edit
Mahendar0701 Jan 5, 2025
e87535d
Merge branch 'develop' into facility-edit
Mahendar0701 Jan 5, 2025
213eb95
Merge branch 'develop' into facility-edit
Mahendar0701 Jan 6, 2025
87db767
added conditions
Mahendar0701 Jan 6, 2025
4599c93
Merge branch 'facility-edit' of https://github.com/Mahendar0701/care_…
Mahendar0701 Jan 6, 2025
8df1055
Merge branch 'develop' into facility-edit
Mahendar0701 Jan 9, 2025
80dde3f
added edit option
Mahendar0701 Jan 9, 2025
f63a324
Merge branch 'develop' into facility-edit
Mahendar0701 Jan 9, 2025
dcad86a
added edit option
Mahendar0701 Jan 9, 2025
0e370c9
Merge branch 'develop' into facility-edit
Mahendar0701 Jan 10, 2025
9b57759
resolved conflicts
Mahendar0701 Jan 10, 2025
a5d9d6e
Merge branch 'develop' into facility-edit
Mahendar0701 Jan 11, 2025
a932b00
autopopulation of existing details
Mahendar0701 Jan 11, 2025
15eb9d3
added i18n and pincode limit
Mahendar0701 Jan 11, 2025
f735ac9
added i18n and pincode limit
Mahendar0701 Jan 11, 2025
a68184f
link wrap in button
Mahendar0701 Jan 11, 2025
4a9f3a6
autofill pincode
Mahendar0701 Jan 11, 2025
43caefd
Merge branch 'develop' into facility-edit
Mahendar0701 Jan 12, 2025
5ffb199
added form.watch
Mahendar0701 Jan 12, 2025
5bda95e
Merge branch 'develop' into facility-edit
Mahendar0701 Jan 12, 2025
ed06a75
Merge branch 'develop' into facility-edit
Mahendar0701 Jan 13, 2025
f763eba
facility edit sheet
Mahendar0701 Jan 13, 2025
8dbda7e
Merge branch 'facility-edit' of https://github.com/Mahendar0701/care_…
Mahendar0701 Jan 13, 2025
ec1014e
Merge branch 'develop' into facility-edit
Mahendar0701 Jan 13, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions public/locale/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@
"add_insurance_details": "Add Insurance Details",
"add_location": "Add Location",
"add_new_beds": "Add New Bed(s)",
"add_new_facility": "Add New Facility",
"add_new_patient": "Add New Patient",
"add_new_user": "Add New User",
"add_notes": "Add notes",
Expand Down Expand Up @@ -663,6 +664,7 @@
"create_new_abha_address": "Create New ABHA Address",
"create_new_abha_profile": "Don't have an ABHA Number",
"create_new_asset": "Create New Asset",
"create_new_facility": "Create a new facility and add it to the organization.",
"create_position_preset": "Create a new position preset",
"create_position_preset_description": "Creates a new position preset in Care from the current position of the camera for the given name",
"create_preset_prerequisite": "To create presets for this bed, you'll need to link the camera to the bed first.",
Expand All @@ -675,6 +677,7 @@
"created_date": "Created Date",
"created_on": "Created On",
"creating": "Creating...",
"creating_facility": "Creating Facility...",
"criticality": "Criticality",
"csv_file_in_the_specified_format": "Select a CSV file in the specified format",
"current_address": "Current Address",
Expand Down Expand Up @@ -786,6 +789,7 @@
"edit_avatar_permission_error": "You do not have permissions to edit the avatar of this user",
"edit_caution_note": "A new prescription will be added to the consultation with the edited details and the current prescription will be discontinued.",
"edit_cover_photo": "Edit Cover Photo",
"edit_facility": "Edit Facility",
"edit_history": "Edit History",
"edit_policy": "Edit Insurance Policy",
"edit_policy_description": "Add or edit patient's insurance details",
Expand Down Expand Up @@ -1030,7 +1034,9 @@
"geolocation_is_not_supported_by_this_browser": "Geolocation is not supported by this browser",
"get_auth_methods": "Get Available Authentication Methods",
"get_auth_mode_error": "Could not find any supported authentication methods, Please try again with a different authentication method",
"get_current_location": "Get Current Location",
"get_tests": "Get Tests",
"getting_location": "Getting Location...",
"goal": "Our goal is to continuously improve the quality and accessibility of public healthcare services using digital tools.",
"granted_on": "Granted On",
"has_allergies": "Has Allergies",
Expand Down Expand Up @@ -1194,6 +1200,7 @@
"local_ip_address_example": "e.g. 192.168.0.123",
"location": "Location",
"location_beds_empty": "No beds available in this location",
"location_details": "Location Details",
"location_management": "Location Management",
"location_updated_successfully": "Location updated successfully",
"log_lab_results": "Log Lab Results",
Expand Down Expand Up @@ -1758,6 +1765,7 @@
"select_investigation_groups": "Select Investigation Groups",
"select_investigations": "Select Investigations",
"select_local_body": "Select Local Body",
"select_location_from": "Select location from",
"select_new_role": "Select New Role",
"select_patient": "Select Patient",
"select_policy": "Select an Insurance Policy",
Expand Down Expand Up @@ -1950,6 +1958,7 @@
"update_asset_service_record": "Update Asset Service Record",
"update_available": "Update Available",
"update_bed": "Update Bed",
"update_existing_facility": "Update the details of the existing facility.",
"update_facility": "Update Facility",
"update_facility_middleware_success": "Facility middleware updated successfully",
"update_log": "Update Log",
Expand All @@ -1969,6 +1978,7 @@
"updated_on": "Updated On",
"updates": "Updates",
"updating": "Updating...",
"updating_facility": "Updating Facility...",
"upload": "Upload",
"upload_an_image": "Upload an image",
"upload_file": "Upload File",
Expand Down Expand Up @@ -2056,6 +2066,7 @@
"view_users": "View Users",
"village": "Village",
"virtual_nursing_assistant": "Virtual Nursing Assistant",
"visibility_settings": "Visibility Settings",
"vitals": "Vitals",
"vitals_monitor": "Vitals Monitor",
"vitals_present": "Vitals Monitor present",
Expand Down
4 changes: 4 additions & 0 deletions src/Utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,10 @@ export const getPincodeDetails = async (pincode: string, apiKey: string) => {
`https://api.data.gov.in/resource/6176ee09-3d56-4a3b-8115-21841576b2f6?api-key=${apiKey}&format=json&filters[pincode]=${pincode}&limit=1`,
);
const data = await response.json();
if (!data.records || data.records.length === 0) {
toast.error("Invalid pincode");
Mahendar0701 marked this conversation as resolved.
Show resolved Hide resolved
return null;
}
return data.records[0];
};

Expand Down
56 changes: 51 additions & 5 deletions src/components/Facility/FacilityCreate.tsx
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file could be deleted now, no? 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Jacobjeevan this file is being used for updating facility in facility detials page

image

Copy link
Contributor

@Jacobjeevan Jacobjeevan Jan 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add an EditFacilitySheet (instead of modifying AddFacilitySheet) and call that component here and for the edit link in Organization Facilities page.

Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import careConfig from "@careConfig";
import {
Popover,
PopoverButton,
Expand Down Expand Up @@ -59,8 +60,10 @@ import {
import routes from "@/Utils/request/api";
import query from "@/Utils/request/query";
import request from "@/Utils/request/request";
import { parsePhoneNumber } from "@/Utils/utils";
import { getPincodeDetails, parsePhoneNumber } from "@/Utils/utils";
Mahendar0701 marked this conversation as resolved.
Show resolved Hide resolved
import OrganizationSelector from "@/pages/Organization/components/OrganizationSelector";
import { Organization } from "@/types/organization/organization";
import { useFetchOrganizationByName } from "@/types/organization/organizationApi";

interface FacilityProps {
facilityId?: string;
Expand All @@ -69,6 +72,9 @@ export const FacilityCreate = (props: FacilityProps) => {
const { t } = useTranslation();
const { facilityId } = props;
const [isLoading, setIsLoading] = useState(false);
const [selectedLevels, setSelectedLevels] = useState<Organization[]>([]);
const [pincode, setPincode] = useState("");

const { goBack } = useAppHistory();

const facilityFormSchema = z.object({
Expand Down Expand Up @@ -215,9 +221,42 @@ export const FacilityCreate = (props: FacilityProps) => {
}
};

const { data: pincodeData, isError: isPincodeError } = useQuery({
queryKey: ["pincodeDetails", pincode],
queryFn: () => getPincodeDetails(pincode, careConfig.govDataApiKey),
enabled: validatePincode(pincode) && pincode != facilityData?.pincode,
});

if (isPincodeError) {
toast.error("Invalid pincode");
}
Mahendar0701 marked this conversation as resolved.
Show resolved Hide resolved

const stateName = pincodeData?.statename;

const districtName = pincodeData?.districtname;

const { data: stateOrg } = useFetchOrganizationByName(stateName);
const { data: districtOrg } = useFetchOrganizationByName(
districtName,
stateOrg?.id,
);

useEffect(() => {
if (stateOrg && districtOrg) {
setSelectedLevels([stateOrg, districtOrg]);
} else {
setSelectedLevels([]);
}
}, [stateOrg, districtOrg]);
Mahendar0701 marked this conversation as resolved.
Show resolved Hide resolved

const handlePincodeChange = (value: string) => {
setPincode(value);
setSelectedLevels([]);
};

return (
<Page
title={facilityId ? "Update Facility" : "Create Facility"}
title={facilityId ? t("update_facility") : t("create_facility")}
crumbsReplacements={{
[facilityId || "????"]: { name: form.watch("name") },
}}
Expand Down Expand Up @@ -321,6 +360,7 @@ export const FacilityCreate = (props: FacilityProps) => {
required
onChange={(value) => {
field.onChange(value.value);
handlePincodeChange(value.value);
}}
error={form.formState.errors.pincode?.message}
/>
Expand All @@ -332,7 +372,11 @@ export const FacilityCreate = (props: FacilityProps) => {
<div className="col-span-2 grid grid-cols-2 gap-5">
<OrganizationSelector
required={true}
onChange={(value) => form.setValue("geo_organization", value)}
value={facilityData?.geo_organization}
parentSelectedLevels={selectedLevels}
onChange={(value) => {
form.setValue("geo_organization", value);
}}
Mahendar0701 marked this conversation as resolved.
Show resolved Hide resolved
/>
</div>

Expand Down Expand Up @@ -414,7 +458,7 @@ export const FacilityCreate = (props: FacilityProps) => {
>
<CareIcon icon="l-map-marker" className="text-xl" />
<span className="tooltip-text tooltip-bottom">
Select location from map
{t("select_location_from")}
</span>
</Button>
</PopoverButton>
Expand Down Expand Up @@ -466,7 +510,9 @@ export const FacilityCreate = (props: FacilityProps) => {

{/* Visibility Settings */}
<div className="space-y-4 rounded-lg border p-4">
<h3 className="text-lg font-medium">Visibility Settings</h3>
<h3 className="text-lg font-medium">
{t("visibility_settings")}
</h3>
<FormField
control={form.control}
name="is_public"
Expand Down
Loading
Loading