From 764d6400a2d64fabc4b27fe4f3f1ac67c607e592 Mon Sep 17 00:00:00 2001 From: Abhiuday Date: Sat, 30 Sep 2023 11:18:54 +0530 Subject: [PATCH] fix(location): added duty staff section --- src/Components/Facility/AddLocationForm.tsx | 90 ++++++++++++++++-- .../Facility/LocationManagement.tsx | 95 +++++++++++-------- src/Components/Facility/models.tsx | 7 +- 3 files changed, 141 insertions(+), 51 deletions(-) diff --git a/src/Components/Facility/AddLocationForm.tsx b/src/Components/Facility/AddLocationForm.tsx index e71b68cc95c..ea8e1aa6e59 100644 --- a/src/Components/Facility/AddLocationForm.tsx +++ b/src/Components/Facility/AddLocationForm.tsx @@ -1,17 +1,20 @@ -import { useState, useEffect, lazy, SyntheticEvent } from "react"; +import { navigate } from "raviger"; +import { SyntheticEvent, lazy, useEffect, useState } from "react"; import { useDispatch } from "react-redux"; import { createFacilityAssetLocation, getAnyFacility, getFacilityAssetLocation, + getFacilityUsers, updateFacilityAssetLocation, } from "../../Redux/actions"; import * as Notification from "../../Utils/Notifications.js"; -import { navigate } from "raviger"; -import { Submit, Cancel } from "../Common/components/ButtonV2"; -import TextFormField from "../Form/FormFields/TextFormField"; -import TextAreaFormField from "../Form/FormFields/TextAreaFormField"; +import { Cancel, Submit } from "../Common/components/ButtonV2"; import Page from "../Common/components/Page"; +import { MultiSelectFormField } from "../Form/FormFields/SelectFormField"; +import TextAreaFormField from "../Form/FormFields/TextAreaFormField"; +import TextFormField from "../Form/FormFields/TextFormField"; +import { UserAssignedModel } from "../Users/models"; const Loading = lazy(() => import("../Common/Loading")); @@ -29,7 +32,15 @@ export const AddLocationForm = (props: LocationFormProps) => { const [description, setDescription] = useState(""); const [facilityName, setFacilityName] = useState(""); const [locationName, setLocationName] = useState(""); - const [errors, setErrors] = useState({ + const [doctorList, setDoctorList] = useState([]); + const [staffList, setStaffList] = useState([]); + const [doctors, setDoctors] = useState([]); + const [staff, setStaff] = useState([]); + const [errors, setErrors] = useState<{ + name: string; + description: string; + middlewareAddress: string; + }>({ name: "", description: "", middlewareAddress: "", @@ -41,9 +52,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( @@ -54,6 +77,16 @@ export const AddLocationForm = (props: LocationFormProps) => { setLocationName(res?.data?.name || ""); setDescription(res?.data?.description || ""); setMiddlewareAddress(res?.data?.middleware_address || ""); + setDoctors( + res?.data?.duty_staff_objects + .filter((doc: UserAssignedModel) => doc.user_type === "Doctor") + .map((doc: UserAssignedModel) => doc.id) || [] + ); + setStaff( + res?.data?.duty_staff_objects + .filter((s: UserAssignedModel) => s.user_type === "Staff") + .map((s: UserAssignedModel) => s.id) || [] + ); } setIsLoading(false); } @@ -98,6 +131,7 @@ export const AddLocationForm = (props: LocationFormProps) => { name, description, middleware_address: middlewareAddress, + duty_staff: [...doctors, ...staff], }; const res = await dispatchAction( @@ -151,6 +185,12 @@ export const AddLocationForm = (props: LocationFormProps) => {
+
+ +
+
{ error={errors.middlewareAddress} />
+
+ +
+
+
+ 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/Loading")); @@ -70,42 +70,59 @@ const Location = ({ description, middleware_address, id, -}: LocationModel) => ( -
-
-
-

- {name} -

- {description || "-"} + duty_staff_objects, +}: LocationModel) => { + const doctors = + duty_staff_objects?.filter((u) => u.user_type === "Doctor") || []; + const staffs = + duty_staff_objects?.filter((u) => u.user_type === "Staff") || []; + return ( +

+
+
+

{name}

+

{description}

+

{middleware_address}

+

+ {doctors.map((doctor) => ( +

+ +
{`${doctor.first_name} ${doctor.last_name}`}
+
+ ))} +

+

+ {staffs.map((s) => ( +

+ +
{`${s.first_name} ${s.last_name}`}
+
+ ))}

-

-

- {middleware_address} -

+
-
-
- - - Edit - - - - Manage Beds - +
+ + + Edit + + + + Manage Beds + +
-
-); + ); +}; diff --git a/src/Components/Facility/models.tsx b/src/Components/Facility/models.tsx index a9861a4869c..ca64479031a 100644 --- a/src/Components/Facility/models.tsx +++ b/src/Components/Facility/models.tsx @@ -1,8 +1,8 @@ -import { AssignedToObjectModel } from "../Patient/models"; +import { AssetData } from "../Assets/AssetTypes"; import { ProcedureType } from "../Common/prescription-builder/ProcedureBuilder"; import { NormalPrescription, PRNPrescription } from "../Medicine/models"; -import { AssetData } from "../Assets/AssetTypes"; -import { UserBareMinimum } from "../Users/models"; +import { AssignedToObjectModel } from "../Patient/models"; +import { UserAssignedModel, UserBareMinimum } from "../Users/models"; export interface LocalBodyModel { name: string; @@ -193,6 +193,7 @@ export interface LocationModel { facility?: { name: string; }; + duty_staff_objects?: UserAssignedModel[]; } export interface BedModel {