diff --git a/src/Components/Facility/ConsultationDetails.tsx b/src/Components/Facility/ConsultationDetails.tsx index bb7098e697f..25b24139550 100644 --- a/src/Components/Facility/ConsultationDetails.tsx +++ b/src/Components/Facility/ConsultationDetails.tsx @@ -95,6 +95,55 @@ export const ConsultationDetails = (props: any) => { } }; + const [hl7SocketUrl, setHL7SocketUrl] = useState(); + const [ventilatorSocketUrl, setVentilatorSocketUrl] = useState(); + + useEffect(() => { + if ( + !consultationData.facility || + !consultationData.current_bed?.bed_object.id + ) + return; + + const fetchData = async () => { + const [facilityRes, assetBedRes] = await Promise.all([ + dispatch(getPermittedFacility(consultationData.facility as any)), + dispatch( + listAssetBeds({ + facility: consultationData.facility as any, + bed: consultationData.current_bed?.bed_object.id, + }) + ), + ]); + + const { middleware_address } = facilityRes.data as FacilityModel; + const assetBeds = assetBedRes.data.results as AssetBedModel[]; + + const hl7Meta = assetBeds.find( + (i) => i.asset_object.asset_class === AssetClass.HL7MONITOR + )?.asset_object?.meta; + const hl7Middleware = hl7Meta?.middleware_hostname || middleware_address; + if (hl7Middleware && hl7Meta?.local_ip_address) { + setHL7SocketUrl( + `wss://${hl7Middleware}/observations/${hl7Meta.local_ip_address}` + ); + } + + const ventilatorMeta = assetBeds.find( + (i) => i.asset_object.asset_class === AssetClass.VENTILATOR + )?.asset_object?.meta; + const ventilatorMiddleware = + ventilatorMeta?.middleware_hostname || middleware_address; + if (ventilatorMiddleware && ventilatorMeta?.local_ip_address) { + setVentilatorSocketUrl( + `wss://${ventilatorMiddleware}/observations/${ventilatorMeta?.local_ip_address}` + ); + } + }; + + fetchData(); + }, [consultationData]); + const fetchData = useCallback( async (status: statusType) => { setIsLoading(true); @@ -443,15 +492,50 @@ export const ConsultationDetails = (props: any) => { {tab === "UPDATES" && (
- {!consultationData.discharge_date && ( -
- -
- )} + {!consultationData.discharge_date && + hl7SocketUrl && + ventilatorSocketUrl && ( +
+
+
+ +
+
+ +
+
+
+ )}
+ {!consultationData.discharge_date && + ((hl7SocketUrl && !ventilatorSocketUrl) || + (!hl7SocketUrl && ventilatorSocketUrl)) && ( +
+ {(hl7SocketUrl || ventilatorSocketUrl) && ( +
+ {hl7SocketUrl && ( +
+ +
+ )} + {ventilatorSocketUrl && ( +
+ +
+ )} +
+ )} +
+ )} {consultationData.discharge_date && (
{
); }; - -const VitalsCard = ({ consultation }: { consultation: ConsultationModel }) => { - const dispatch = useDispatch(); - const [loading, setLoading] = useState(false); - const [hl7SocketUrl, setHL7SocketUrl] = useState(); - const [ventilatorSocketUrl, setVentilatorSocketUrl] = useState(); - - useEffect(() => { - if (!consultation.facility || !consultation.current_bed?.bed_object.id) - return; - - const fetchData = async () => { - setLoading(true); - - const [facilityRes, assetBedRes] = await Promise.all([ - dispatch(getPermittedFacility(consultation.facility as any)), - dispatch( - listAssetBeds({ - facility: consultation.facility as any, - bed: consultation.current_bed?.bed_object.id, - }) - ), - ]); - - const { middleware_address } = facilityRes.data as FacilityModel; - const assetBeds = assetBedRes.data.results as AssetBedModel[]; - - const hl7Meta = assetBeds.find( - (i) => i.asset_object.asset_class === AssetClass.HL7MONITOR - )?.asset_object?.meta; - const hl7Middleware = hl7Meta?.middleware_hostname || middleware_address; - if (hl7Middleware && hl7Meta?.local_ip_address) { - setHL7SocketUrl( - `wss://${hl7Middleware}/observations/${hl7Meta.local_ip_address}` - ); - } - - const ventilatorMeta = assetBeds.find( - (i) => i.asset_object.asset_class === AssetClass.VENTILATOR - )?.asset_object?.meta; - const ventilatorMiddleware = - ventilatorMeta?.middleware_hostname || middleware_address; - if (ventilatorMiddleware && ventilatorMeta?.local_ip_address) { - setVentilatorSocketUrl( - `wss://${ventilatorMiddleware}/observations/${ventilatorMeta?.local_ip_address}` - ); - } - - setLoading(false); - }; - - fetchData(); - }, [consultation]); - - if (loading) { - return ( -
- -
- ); - } - - if (!hl7SocketUrl && !ventilatorSocketUrl) { - return ( - - No HL7 Monitor or Ventilator configured for this patient - - ); - } - - return ( -
-
- {hl7SocketUrl ? ( - - ) : ( - - )} -
-
- {ventilatorSocketUrl ? ( - - ) : ( - - )} -
-
- ); -}; - -const VitalsDeviceNotConfigured = ({ device }: { device: string }) => { - return ( -
- - - No {device} configured for this bed - -
- ); -}; diff --git a/src/Components/Patient/PatientRegister.tsx b/src/Components/Patient/PatientRegister.tsx index 7f9685479a2..6eb283679cb 100644 --- a/src/Components/Patient/PatientRegister.tsx +++ b/src/Components/Patient/PatientRegister.tsx @@ -73,7 +73,7 @@ import { MaterialUiPickersDate } from "@material-ui/pickers/typings/date"; import InsuranceDetailsBuilder from "../HCX/InsuranceDetailsBuilder"; import { HCXPolicyModel } from "../HCX/models"; import HCXPolicyValidator from "../HCX/validators"; -import { FieldError } from "../Form/Fi1eldValidators"; +import { FieldError } from "../Form/FieldValidators"; import useAppHistory from "../../Common/hooks/useAppHistory"; import DialogModal from "../Common/Dialog"; import { DraftSection, useAutoSaveReducer } from "../../Utils/AutoSave";