diff --git a/src/Components/Facility/AddLocationForm.tsx b/src/Components/Facility/AddLocationForm.tsx index 91e9c718f72..605595e06df 100644 --- a/src/Components/Facility/AddLocationForm.tsx +++ b/src/Components/Facility/AddLocationForm.tsx @@ -1,19 +1,21 @@ import loadable from "@loadable/component"; -import React, { useState, useEffect } from "react"; +import { navigate } from "raviger"; +import React, { 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 TextAreaFormField from "../Form/FormFields/TextAreaFormField"; +import TextFormField from "../Form/FormFields/TextFormField"; +import { MultiSelectFormField } from "../Form/FormFields/SelectFormField"; const Loading = loadable(() => import("../Common/Loading")); interface LocationFormProps { @@ -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, @@ -105,9 +128,9 @@ export const AddLocationForm = (props: LocationFormProps) => { return ( { uri: `/facility/${facilityId}/location`, }, }), - }} + } } >
-
+
+
+ +
+
setName(e.value)} - error={errors.name} + value={ name } + onChange={ (e) => setName(e.value) } + error={ errors.name } />
setDescription(e.value)} - error={errors.description} + value={ description } + onChange={ (e) => setDescription(e.value) } + 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 } />
+ onClick={ () => navigate(`/facility/${facilityId}/location`, { replace: true, }) } /> - +
diff --git a/src/Components/Facility/LocationManagement.tsx b/src/Components/Facility/LocationManagement.tsx index 78b7fa7ef4c..8645bca4e0f 100644 --- a/src/Components/Facility/LocationManagement.tsx +++ b/src/Components/Facility/LocationManagement.tsx @@ -1,14 +1,15 @@ -import { useCallback, useState, ReactElement } from "react"; import loadable from "@loadable/component"; +import { ReactElement, useCallback, useState } from "react"; import { useDispatch } from "react-redux"; +import CareIcon from "../../CAREUI/icons/CareIcon"; import { statusType, useAbortableEffect } from "../../Common/utils"; -import { listFacilityAssetLocation, getAnyFacility } from "../../Redux/actions"; +import { getAnyFacility, listFacilityAssetLocation } from "../../Redux/actions"; +import { NonReadOnlyUsers } from "../../Utils/AuthorizeFor"; import Pagination from "../Common/Pagination"; -import { LocationModel } from "./models"; import ButtonV2 from "../Common/components/ButtonV2"; -import { NonReadOnlyUsers } from "../../Utils/AuthorizeFor"; -import CareIcon from "../../CAREUI/icons/CareIcon"; import Page from "../Common/components/Page"; +import { UserAssignedModel } from "../Users/models"; +import { LocationModel } from "./models"; const Loading = loadable(() => import("../Common/Loading")); interface LocationManagementProps { @@ -20,20 +21,30 @@ 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}

+

{ name }

+

{ description }

+

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

+

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

@@ -41,8 +52,8 @@ const LocationRow = (props: LocationRowProps) => { variant="secondary" border className="w-full lg:w-auto" - href={`/facility/${facilityId}/location/${id}/update`} - authorizeFor={NonReadOnlyUsers} + href={ `/facility/${facilityId}/location/${id}/update` } + authorizeFor={ NonReadOnlyUsers } > Edit @@ -51,7 +62,7 @@ const LocationRow = (props: LocationRowProps) => { variant="secondary" border className="w-full lg:w-auto" - href={`/facility/${facilityId}/location/${id}/beds`} + href={ `/facility/${facilityId}/location/${id}/beds` } > Manage Beds @@ -114,11 +125,13 @@ export const LocationManagement = (props: LocationManagementProps) => { if (locations?.length) { locationsList = locations.map((locationItem: LocationModel) => ( )); } else if (locations && locations.length === 0) { @@ -133,18 +146,18 @@ export const LocationManagement = (props: LocationManagementProps) => { location = ( <>
- {locationsList} + { locationsList }
- {totalCount > limit && ( + { totalCount > limit && (
- )} + ) } ); } @@ -156,20 +169,20 @@ export const LocationManagement = (props: LocationManagementProps) => { return (
Add New Location
- {location} + { location }
); diff --git a/src/Components/Facility/models.tsx b/src/Components/Facility/models.tsx index ea7787a7e38..7e6d4cab42c 100644 --- a/src/Components/Facility/models.tsx +++ b/src/Components/Facility/models.tsx @@ -1,6 +1,7 @@ -import { AssignedToObjectModel } from "../Patient/models"; import { ProcedureType } from "../Common/prescription-builder/ProcedureBuilder"; import { NormalPrescription, PRNPrescription } from "../Medicine/models"; +import { AssignedToObjectModel } from "../Patient/models"; +import { UserAssignedModel } from "../Users/models"; export interface LocalBodyModel { name: string; @@ -182,6 +183,8 @@ export interface LocationModel { facility?: { name: string; }; + doctor_objects?: UserAssignedModel[]; + staff_objects?: UserAssignedModel[]; } export interface BedModel {