Skip to content

Commit

Permalink
update the CNS to pass the bedAssignmentStartDate prop to HL7PatientV…
Browse files Browse the repository at this point in the history
…italsMonitor component
  • Loading branch information
sriharsh05 committed Oct 27, 2023
1 parent e52c1ee commit 5371c69
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
34 changes: 33 additions & 1 deletion src/Components/Facility/CentralNursingStation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import { useTranslation } from "react-i18next";
import { SortOption } from "../Common/SortDropdown";
import { SelectFormField } from "../Form/FormFields/SelectFormField";
import useVitalsAspectRatioConfig from "../VitalsMonitor/useVitalsAspectRatioConfig";
import routes from "../../Redux/api";
import request from "../../Utils/request/request";

const PER_PAGE_LIMIT = 6;

Expand Down Expand Up @@ -51,6 +53,9 @@ export default function CentralNursingStation({ facilityId }: Props) {
const { qParams, updateQuery, removeFilter, updatePage } = useFilters({
limit: PER_PAGE_LIMIT,
});
const [bedAssignmentStartDate, setBedAssignmentStartDate] = useState<
string[]
>([]);

// To automatically collapse sidebar.
useEffect(() => {
Expand Down Expand Up @@ -118,6 +123,32 @@ export default function CentralNursingStation({ facilityId }: Props) {
qParams.bed_is_occupied,
]);

useEffect(() => {
const fetchDataAndBedAssignmentStartDate = async () => {
if (data && data.length > 0) {
const updatedBedAssignmentStartDate = await Promise.all(
data.map(async (item) => {
const { data: consultationData } = await request(
routes.getConsultationList,
{
query: { patient: item.patientAssetBed?.patient?.id },
}
);
const { data: bedData } = await request(
routes.listConsultationBeds,
{
query: { consultation: consultationData?.results[0].id },
}
);
return bedData?.results[0].created_date ?? "";
})
);
setBedAssignmentStartDate(updatedBedAssignmentStartDate);
}
};
fetchDataAndBedAssignmentStartDate();
}, [data]);

const { config, hash } = useVitalsAspectRatioConfig({
default: 6 / 11,
vs: 10 / 11,
Expand Down Expand Up @@ -270,9 +301,10 @@ export default function CentralNursingStation({ facilityId }: Props) {
</div>
) : (
<div className="mt-1 grid grid-cols-1 gap-1 lg:grid-cols-2 3xl:grid-cols-3">
{data.map((props) => (
{data.map((props, idx) => (
<div className="overflow-hidden text-clip">
<HL7PatientVitalsMonitor
patientCurrentBedAssignmentDate={bedAssignmentStartDate[idx]}
key={`${props.patientAssetBed?.bed.id}-${hash}`}
{...props}
config={config}
Expand Down
2 changes: 2 additions & 0 deletions src/Redux/api.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
AssetUpdate,
} from "../Components/Assets/AssetTypes";
import {
ConsultationModel,
CurrentBed,
FacilityModel,
LocationModel,
Expand Down Expand Up @@ -397,6 +398,7 @@ const routes = {
},
getConsultationList: {
path: "/api/v1/consultation/",
TRes: Type<PaginatedResponse<ConsultationModel>>(),
},
createConsultation: {
path: "/api/v1/consultation/",
Expand Down

0 comments on commit 5371c69

Please sign in to comment.