Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Enhancement] Ventilator Parameters Input - Validate Consultation Bed for Linked Ventilator Asset is resolved #7522

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/Components/Common/DialogModal.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
type reactClass
module DialogModal = {
@module("./Dialog.tsx") @react.component
external make: (
~title: React.element,
~show: bool,
~onClose: unit => unit,
~className: string,
~children: React.element,
) => React.element = "default"
}

@react.component
let make = (
~title: React.element,
~show: bool,
~onClose: unit => unit,
~className: string,
~children: React.element,
) => <DialogModal title show onClose className> {children} </DialogModal>
16 changes: 16 additions & 0 deletions src/Components/CriticalCareRecording/CriticalCare__API.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { fireRequestV2 } from "../../Redux/fireRequest";
import routes from "../../Redux/api";
import request from "../../Utils/request/request";

export const loadDailyRound = (
consultationId: string,
Expand All @@ -24,3 +26,17 @@ export const updateDailyRound = (
id,
});
};

export const getAsset = (
consultationId: string,
setAsset: React.Dispatch<React.SetStateAction<number>>
) => {
request(routes.listConsultationBeds, {
query: { consultation: consultationId },
}).then((result) => {
manasvi-gaur marked this conversation as resolved.
Show resolved Hide resolved
manasvi-gaur marked this conversation as resolved.
Show resolved Hide resolved
const data = result.data?.results[0].assets_objects?.filter(
(asset) => asset.asset_class == "VENTILATOR"
);
setAsset(data?.length || 0);
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ let make = (~id, ~facilityId, ~patientId, ~consultationId, ~dailyRound) => {
updateCB={updateDailyRound(send, VentilatorParametersEditor)}
id
consultationId
patientId
facilityId
/>
| ArterialBloodGasAnalysisEditor =>
<CriticalCare__ABGAnalysisEditor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ open CriticalCare__Types
external updateDailyRound: (string, string, Js.Json.t, _ => unit, _ => unit) => unit =
"updateDailyRound"

@module("../CriticalCare__API")
external getAsset: (string, (int => int) => unit) => option<unit => unit> = "getAsset"

open VentilatorParameters

let string_of_int = data => Belt.Option.mapWithDefault(data, "", Js.Int.toString)
Expand All @@ -14,19 +17,19 @@ let reducer = (state: VentilatorParameters.state, action: VentilatorParameters.a
switch action {
| SetBilateralAirEntry(bilateral_air_entry) => {
...state,
bilateral_air_entry: bilateral_air_entry,
bilateral_air_entry,
}
| SetETCO2(etco2) => {
...state,
etco2: etco2,
etco2,
}
| SetVentilatorInterface(ventilator_interface) => {
...state,
ventilator_interface: ventilator_interface,
ventilator_interface,
}
| SetVentilatorMode(ventilator_mode) => {
...state,
ventilator_mode: ventilator_mode,
ventilator_mode,
}

| SetOxygenModality(oxygen_modality) => {
Expand Down Expand Up @@ -59,7 +62,7 @@ let reducer = (state: VentilatorParameters.state, action: VentilatorParameters.a
}
| SetOxygenModalityOxygenRate(ventilator_oxygen_modality_oxygen_rate) => {
...state,
ventilator_oxygen_modality_oxygen_rate: ventilator_oxygen_modality_oxygen_rate,
ventilator_oxygen_modality_oxygen_rate,
}
| SetOxygenModalityFlowRate(oxygen_modality_flow_rate) => {
...state,
Expand Down Expand Up @@ -204,8 +207,22 @@ let initialState: VentilatorParameters.t => VentilatorParameters.state = ventila
}

@react.component
let make = (~ventilatorParameters: VentilatorParameters.t, ~id, ~consultationId, ~updateCB) => {
let make = (
~ventilatorParameters: VentilatorParameters.t,
~id,
~consultationId,
~updateCB,
~facilityId,
~patientId,
) => {
let (state, send) = React.useReducer(reducer, initialState(ventilatorParameters))
let (isOpen, setIsOpen) = React.useState(() => false)
let toggleOpen = () => setIsOpen(prevState => !prevState)
let (asset, setAsset) = React.useState(() => 0)

React.useEffect1(() => {
getAsset(consultationId, setAsset)
}, [isOpen])

let editor = switch state.ventilator_interface {
| INVASIVE => <CriticalCare__VentilatorParametersEditor__Invasive state send />
Expand All @@ -216,7 +233,7 @@ let make = (~ventilatorParameters: VentilatorParameters.t, ~id, ~consultationId,

<div>
<CriticalCare__PageTitle title="Respiratory Support" />
<div>
<div>
<div className="px-5 my-10">
<div className=" text-xl font-bold my-2"> {str("Bilateral Air Entry")} </div>
<div className="flex md:flex-row flex-col md:space-y-0 space-y-2 space-x-0 md:space-x-4">
Expand All @@ -225,19 +242,18 @@ let make = (~ventilatorParameters: VentilatorParameters.t, ~id, ~consultationId,
id="bilateral-air-entry-yes"
label="Yes"
checked={switch state.bilateral_air_entry {
| Some(bae) => bae
| None => false
| Some(bae) => bae
| None => false
}}
onChange={_ => send(SetBilateralAirEntry(Some(true)))}
/>

<Radio
key="bilateral-air-entry-no"
id="bilateral-air-entry-no"
label="No"
checked={switch state.bilateral_air_entry {
| Some(bae) => !bae
| None => false
| Some(bae) => !bae
| None => false
}}
onChange={_ => send(SetBilateralAirEntry(Some(false)))}
/>
Expand All @@ -255,7 +271,6 @@ let make = (~ventilatorParameters: VentilatorParameters.t, ~id, ~consultationId,
hasError={ValidationUtils.isInputInRangeInt(0, 200, state.etco2)}
/>
</div>

<div className="py-6">
<div className="mb-6">
<h4> {str("Respiratory Support")} </h4>
Expand All @@ -282,10 +297,38 @@ let make = (~ventilatorParameters: VentilatorParameters.t, ~id, ~consultationId,
</div>
<button
disabled={state.saving}
onClick={_ => saveData(id, consultationId, state, send, updateCB)}
onClick={_ => {
if (
asset == 0 &&
(state.ventilator_interface !=
CriticalCare__VentilatorParameters.decodeVentilatorInterfaceType(
ventilatorInterfaceOptions[0].value,
) ||
switch state.bilateral_air_entry {
| Some(true) => true
| _ => false
})
) {
toggleOpen()
} else {
saveData(id, consultationId, state, send, updateCB)
}
}}
className="btn btn-primary btn-large w-full">
{str("Update Details")}
</button>
<DialogModal
title={str("Link an asset to proceed")}
show={isOpen}
onClose={_ => toggleOpen()}
className="md:max-w-3xl">
<Beds
facilityId={facilityId}
patientId={patientId}
consultationId={consultationId}
setState={_ => toggleOpen()}
/>
</DialogModal>
</div>
</div>
}
18 changes: 18 additions & 0 deletions src/Components/Facility/Consultations/Beds.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
type reactClass
module Beds = {
@module("./Beds.tsx") @react.component
external make: (
~facilityId: string,
~patientId: string,
~consultationId: string,
~setState: unit => unit,
) => React.element = "default"
}

@react.component
let make = (
~facilityId: string,
~patientId: string,
~consultationId: string,
~setState: unit => unit,
) => <Beds facilityId patientId consultationId setState />
Loading