Skip to content

Commit

Permalink
fix(location): added duty staff section
Browse files Browse the repository at this point in the history
  • Loading branch information
aeswibon committed Sep 30, 2023
1 parent bebb693 commit 129fa01
Show file tree
Hide file tree
Showing 3 changed files with 145 additions and 46 deletions.
91 changes: 81 additions & 10 deletions src/Components/Facility/AddLocationForm.tsx
Original file line number Diff line number Diff line change
@@ -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"));

Expand All @@ -28,7 +31,14 @@ export const AddLocationForm = (props: LocationFormProps) => {
const [description, setDescription] = useState("");
const [facilityName, setFacilityName] = useState("");
const [locationName, setLocationName] = useState("");
const [errors, setErrors] = useState<any>({
const [doctorList, setDoctorList] = useState<UserAssignedModel[]>([]);
const [staffList, setStaffList] = useState<UserAssignedModel[]>([]);
const [doctors, setDoctors] = useState<UserAssignedModel[]>([]);
const [staff, setStaff] = useState<UserAssignedModel[]>([]);
const [errors, setErrors] = useState<{
name: string;
description: string;
}>({
name: "",
description: "",
});
Expand All @@ -39,9 +49,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(
Expand All @@ -51,6 +73,16 @@ export const AddLocationForm = (props: LocationFormProps) => {
setName(res?.data?.name || "");
setLocationName(res?.data?.name || "");
setDescription(res?.data?.description || "");
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);
}
Expand Down Expand Up @@ -83,6 +115,7 @@ export const AddLocationForm = (props: LocationFormProps) => {
const data = {
name,
description,
duty_staff: [...doctors, ...staff],
};

const res = await dispatchAction(
Expand Down Expand Up @@ -136,6 +169,12 @@ export const AddLocationForm = (props: LocationFormProps) => {
<div className="cui-card">
<form onSubmit={handleSubmit}>
<div className="mt-2 grid grid-cols-1 gap-4">
<div className="flex flex-row items-center">
<label className="text-lg font-bold text-gray-900">
General Details
</label>
<hr className="ml-6 flex-1 border border-gray-400" />
</div>
<div>
<TextFormField
name="name"
Expand All @@ -157,8 +196,40 @@ export const AddLocationForm = (props: LocationFormProps) => {
error={errors.description}
/>
</div>
<div className="flex flex-row items-center">
<label className="text-lg font-bold text-gray-900">
Duty Staff
</label>
<hr className="ml-6 flex-1 border border-gray-400" />
</div>
<div>
<MultiSelectFormField
name="doctors"
label="Doctors"
onChange={(e) => setDoctors(e.value)}
options={doctorList}
value={doctors}
optionLabel={(option: any) =>
`${option.first_name} ${option.last_name}`
}
optionValue={(option: any) => option.id}
/>
</div>
<div>
<MultiSelectFormField
name="staff"
label="Staff"
onChange={(e) => setStaff(e.value)}
options={staffList}
value={staff}
optionLabel={(option: any) =>
`${option.first_name} ${option.last_name}`
}
optionValue={(option: any) => option.id}
/>
</div>
</div>
<div className="mt-4 cui-form-button-group">
<div className="cui-form-button-group mt-4">
<Cancel
onClick={() =>
navigate(`/facility/${facilityId}/location`, {
Expand Down
93 changes: 60 additions & 33 deletions src/Components/Facility/LocationManagement.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { lazy } from "react";
import ButtonV2 from "../Common/components/ButtonV2";
import { NonReadOnlyUsers } from "../../Utils/AuthorizeFor";
import CareIcon from "../../CAREUI/icons/CareIcon";
import Page from "../Common/components/Page";
import routes from "../../Redux/api";
import PaginatedList from "../../CAREUI/misc/PaginatedList";
import routes from "../../Redux/api";
import { NonReadOnlyUsers } from "../../Utils/AuthorizeFor";
import ButtonV2 from "../Common/components/ButtonV2";
import Page from "../Common/components/Page";
import { LocationModel } from "./models";

const Loading = lazy(() => import("../Common/Loading"));
Expand Down Expand Up @@ -65,35 +65,62 @@ export default function LocationManagement({ facilityId }: Props) {
);
}

const Location = ({ name, description, id }: LocationModel) => (
<div className="w-full items-center justify-between rounded border border-gray-300 bg-white p-6 shadow-sm transition-all duration-200 ease-in-out hover:border-primary-400 lg:flex">
<div className="lg:w-3/4">
<div className="w-full items-baseline lg:flex lg:items-center">
<p className="break-words text-xl lg:mr-4 lg:w-1/4">{name}</p>
<p className="break-all text-sm lg:w-3/4">{description}</p>
const Location = ({
name,
description,
id,
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 (
<div className="w-full items-center justify-between rounded border border-gray-300 bg-white p-6 shadow-sm transition-all duration-200 ease-in-out hover:border-primary-400 lg:flex">
<div className="lg:w-3/4">
<div className="w-full items-baseline space-y-2 lg:flex lg:space-x-2">
<p className="break-words text-sm lg:mr-4 lg:w-1/6">{name}</p>
<p className="break-all text-sm lg:w-1/2">{description}</p>
<p className="flex flex-col gap-y-2 text-sm lg:w-1/6">
{doctors.map((doctor) => (
<div className="flex w-full rounded-lg border border-primary-600 bg-primary-100 px-3 py-1 text-primary-900">
<CareIcon className="care-l-user-md" />
<div className="ml-3">{`${doctor.first_name} ${doctor.last_name}`}</div>
</div>
))}
</p>
<p className="flex flex-col gap-y-2 text-sm lg:w-1/6">
{staffs.map((s) => (
<div className="flex w-full rounded-lg border border-primary-600 bg-primary-100 px-3 py-1 text-primary-900">
<CareIcon className="care-l-user-nurse" />
<div className="ml-3">{`${s.first_name} ${s.last_name}`}</div>
</div>
))}
</p>
</div>
</div>
</div>

<div className="mt-4 flex flex-col gap-2 lg:mt-0 lg:flex-row">
<ButtonV2
variant="secondary"
border
className="w-full lg:w-auto"
href={`location/${id}/update`}
authorizeFor={NonReadOnlyUsers}
>
<CareIcon className="care-l-pen text-lg" />
Edit
</ButtonV2>
<ButtonV2
variant="secondary"
border
className="w-full lg:w-auto"
href={`location/${id}/beds`}
>
<CareIcon className="care-l-bed text-lg" />
Manage Beds
</ButtonV2>
<div className="mt-4 flex flex-col gap-2 lg:mt-0 lg:flex-row">
<ButtonV2
variant="secondary"
border
className="w-full lg:w-auto"
href={`location/${id}/update`}
authorizeFor={NonReadOnlyUsers}
>
<CareIcon className="care-l-pen text-lg" />
Edit
</ButtonV2>
<ButtonV2
variant="secondary"
border
className="w-full lg:w-auto"
href={`location/${id}/beds`}
>
<CareIcon className="care-l-bed text-lg" />
Manage Beds
</ButtonV2>
</div>
</div>
</div>
);
);
};
7 changes: 4 additions & 3 deletions src/Components/Facility/models.tsx
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -189,6 +189,7 @@ export interface LocationModel {
facility?: {
name: string;
};
duty_staff_objects?: UserAssignedModel[];
}

export interface BedModel {
Expand Down

0 comments on commit 129fa01

Please sign in to comment.