From a634c79c98ffba4747190beb2b95ddc789ca2ccf Mon Sep 17 00:00:00 2001 From: cp-Coder Date: Sat, 22 Apr 2023 12:41:28 +0530 Subject: [PATCH] fix(location): added duty staff section --- src/Components/Facility/AddLocationForm.tsx | 67 ++++++++++++++++++- .../Facility/LocationManagement.tsx | 15 ++++- src/Components/Facility/models.tsx | 5 +- 3 files changed, 82 insertions(+), 5 deletions(-) diff --git a/src/Components/Facility/AddLocationForm.tsx b/src/Components/Facility/AddLocationForm.tsx index 1e2413b2807..f4e8b3c1175 100644 --- a/src/Components/Facility/AddLocationForm.tsx +++ b/src/Components/Facility/AddLocationForm.tsx @@ -6,6 +6,7 @@ import { createFacilityAssetLocation, getAnyFacility, getFacilityAssetLocation, + getFacilityUsers, updateFacilityAssetLocation, } from "../../Redux/actions"; import * as Notification from "../../Utils/Notifications.js"; @@ -13,6 +14,7 @@ import { navigate } from "raviger"; import { Submit, Cancel } from "../Common/components/ButtonV2"; import TextFormField from "../Form/FormFields/TextFormField"; import TextAreaFormField from "../Form/FormFields/TextAreaFormField"; +import { MultiSelectFormField } from "../Form/FormFields/SelectFormField"; const Loading = loadable(() => import("../Common/Loading")); const PageTitle = loadable(() => import("../Common/PageTitle")); @@ -29,6 +31,10 @@ export const AddLocationForm = (props: LocationFormProps) => { const [description, setDescription] = useState(""); const [facilityName, setFacilityName] = useState(""); const [locationName, setLocationName] = useState(""); + const [doctorList, setDoctorList] = useState([]); + const [staffList, setStaffList] = useState([]); + const [doctors, setDoctors] = useState([]); + const [staff, setStaff] = useState([]); const [errors, setErrors] = useState({ name: "", description: "", @@ -40,9 +46,21 @@ export const AddLocationForm = (props: LocationFormProps) => { async function fetchFacilityName() { setIsLoading(true); if (facilityId) { - const res = await dispatchAction(getAnyFacility(facilityId)); - - setFacilityName(res?.data?.name || ""); + const facility = await dispatchAction(getAnyFacility(facilityId)); + const doctor = await dispatchAction( + getFacilityUsers(facilityId, { + user_type: "Doctor", + home_facility: facilityId, + }) + ); + const staff = await dispatchAction( + getFacilityUsers(facilityId, { + user_type: "Staff", + }) + ); + setFacilityName(facility?.data?.name || ""); + setDoctorList(doctor?.data?.results || []); + setStaffList(staff?.data?.results || []); } if (locationId) { const res = await dispatchAction( @@ -52,6 +70,8 @@ export const AddLocationForm = (props: LocationFormProps) => { setName(res?.data?.name || ""); setLocationName(res?.data?.name || ""); setDescription(res?.data?.description || ""); + setDoctors(res?.data?.doctors || []); + setStaff(res?.data?.staff || []); } setIsLoading(false); } @@ -68,6 +88,8 @@ export const AddLocationForm = (props: LocationFormProps) => { const data = { name, description, + doctors, + staff, }; const res = await dispatchAction( @@ -89,6 +111,7 @@ export const AddLocationForm = (props: LocationFormProps) => { msg: notificationMessage, }); } else if (res.status === 400) { + console.log(res.data); Object.keys(res.data).forEach((key) => { setErrors((prevState: any) => ({ ...prevState, @@ -123,6 +146,12 @@ export const AddLocationForm = (props: LocationFormProps) => {
+
+ +
+
{ error={errors.description} />
+
+ +
+
+
+ setDoctors(e.value)} + options={doctorList} + value={doctors} + optionLabel={(option: any) => + `${option.first_name} ${option.last_name}` + } + optionValue={(option: any) => option.id} + /> +
+
+ setStaff(e.value)} + options={staffList} + value={staff} + optionLabel={(option: any) => + `${option.first_name} ${option.last_name}` + } + optionValue={(option: any) => option.id} + /> +
import("../Common/PageTitle")); const Loading = loadable(() => import("../Common/Loading")); @@ -20,10 +21,12 @@ interface LocationRowProps { facilityId: string; name: string; description: string; + doctors: UserAssignedModel[]; + staff: UserAssignedModel[]; } const LocationRow = (props: LocationRowProps) => { - const { id, facilityId, name, description } = props; + const { id, facilityId, name, description, doctors, staff } = props; return (
{

{name}

{description}

+

+ {doctors.map( + (doctor) => `${doctor.first_name} ${doctor.last_name}` + )} +

+

+ {staff.map((s) => `${s.first_name} ${s.last_name}`)} +

@@ -125,6 +136,8 @@ export const LocationManagement = (props: LocationManagementProps) => { facilityId={facilityId || ""} name={locationItem.name || ""} description={locationItem.description || ""} + doctors={locationItem.doctor_objects || []} + staff={locationItem.staff_objects || []} /> )); } else if (locations && locations.length === 0) { diff --git a/src/Components/Facility/models.tsx b/src/Components/Facility/models.tsx index 88973fde3a0..e0395b8950b 100644 --- a/src/Components/Facility/models.tsx +++ b/src/Components/Facility/models.tsx @@ -1,6 +1,7 @@ -import { AssignedToObjectModel } from "../Patient/models"; import { PRNPrescriptionType } from "../Common/prescription-builder/PRNPrescriptionBuilder"; import { ProcedureType } from "../Common/prescription-builder/ProcedureBuilder"; +import { AssignedToObjectModel } from "../Patient/models"; +import { UserAssignedModel } from "../Users/models"; export interface LocalBodyModel { name: string; @@ -184,6 +185,8 @@ export interface LocationModel { facility?: { name: string; }; + doctor_objects?: UserAssignedModel[]; + staff_objects?: UserAssignedModel[]; } export interface BedModel {