-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
31 changed files
with
785 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
src/components/accessories/currentAdmission/CurrentAdmission.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import React, { FunctionComponent, useEffect, useState } from "react"; | ||
import { useTranslation } from "react-i18next"; | ||
import { useDispatch, useSelector } from "react-redux"; | ||
import { AdmissionDTO, OpdDTO, PatientDTO } from "../../../generated"; | ||
import { updateAdmission } from "../../../state/admissions/actions"; | ||
import { IState } from "../../../types"; | ||
import { useFields } from "../admission/useFields"; | ||
import { CurrentAdmissionData } from "./currentAdmissionData/CurrentAdmissionData"; | ||
import { CurrentAdmissionForm } from "./currentAdmissionForm/CurrentAdmissionForm"; | ||
import "./styles.scss"; | ||
import { IOwnProps } from "./types"; | ||
|
||
export const CurrentAdmission: FunctionComponent<IOwnProps> = ({ | ||
onEditChange, | ||
}) => { | ||
const { t } = useTranslation(); | ||
const dispatch = useDispatch(); | ||
const [editionMode, setEditionMode] = useState(false); | ||
const currentAdmission = useSelector( | ||
(state: IState) => state.admissions.currentAdmissionByPatientId.data | ||
); | ||
const lastOpd = useSelector<IState, OpdDTO | undefined>( | ||
(state) => state.opds.lastOpd.data | ||
); | ||
|
||
const handleEdit = () => { | ||
setEditionMode(true); | ||
}; | ||
|
||
const handleDiscard = () => { | ||
setEditionMode(false); | ||
}; | ||
|
||
const fields = useFields(currentAdmission, lastOpd?.disease); | ||
|
||
const onSubmit = (adm: AdmissionDTO) => { | ||
let admissionToSave: AdmissionDTO = { | ||
...currentAdmission, | ||
deleted: "N", | ||
type: adm.type, | ||
admitted: adm.admitted, | ||
fhu: adm.fhu, | ||
admDate: adm.admDate, | ||
admType: adm.admType, | ||
diseaseIn: adm.diseaseIn, | ||
note: adm.note, | ||
ward: adm.ward, | ||
}; | ||
dispatch(updateAdmission(admissionToSave)); | ||
}; | ||
|
||
useEffect(() => { | ||
onEditChange(editionMode); | ||
}, [editionMode]); | ||
|
||
return ( | ||
<div className="currentAdmission"> | ||
{currentAdmission && !editionMode && ( | ||
<CurrentAdmissionData | ||
onEdit={handleEdit} | ||
admission={currentAdmission} | ||
/> | ||
)} | ||
{currentAdmission && editionMode && ( | ||
<CurrentAdmissionForm | ||
fields={fields} | ||
onSubmit={onSubmit} | ||
onDiscard={handleDiscard} | ||
/> | ||
)} | ||
</div> | ||
); | ||
}; |
75 changes: 75 additions & 0 deletions
75
src/components/accessories/currentAdmission/currentAdmissionData/CurrentAdmissionData.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { IconButton } from "@material-ui/core"; | ||
import { Edit } from "@material-ui/icons"; | ||
import React, { FunctionComponent } from "react"; | ||
import { useTranslation } from "react-i18next"; | ||
import { useDispatch, useSelector } from "react-redux"; | ||
import { AdmissionDTO, PatientDTO } from "../../../../generated"; | ||
import { parseDate } from "../../../../libraries/formDataHandling/functions"; | ||
import { IState } from "../../../../types"; | ||
import Button from "../../button/Button"; | ||
import TextField from "../../textField/TextField"; | ||
import "../styles.scss"; | ||
import AutocompleteField from "../../autocompleteField/AutocompleteField"; | ||
import DateField from "../../dateField/DateField"; | ||
import isEmpty from "lodash.isempty"; | ||
import { renderDate } from "../../../../libraries/formatUtils/dataFormatting"; | ||
|
||
interface IOwnProps { | ||
onEdit: () => void; | ||
admission: AdmissionDTO; | ||
} | ||
|
||
export const CurrentAdmissionData: FunctionComponent<IOwnProps> = ({ | ||
onEdit, | ||
admission, | ||
}) => { | ||
const { t } = useTranslation(); | ||
|
||
return ( | ||
<div className="currentAdmissionData"> | ||
<div className="currentAdmission_leading"> | ||
<IconButton onClick={onEdit}> | ||
<Edit /> | ||
</IconButton> | ||
</div> | ||
<div className="currentAdmissionData__content"> | ||
{!isEmpty(admission?.ward?.description) && ( | ||
<div className="currentAdmissionData__item"> | ||
<span className="item_label">{t("admission.ward")}</span> | ||
<p className="item_content">{admission?.ward?.description}</p> | ||
</div> | ||
)} | ||
{!isEmpty(admission?.fhu) && ( | ||
<div className="currentAdmissionData__item"> | ||
<span className="item_label">{t("admission.fhu")}</span> | ||
<p className="item_content">{admission?.fhu}</p> | ||
</div> | ||
)} | ||
{!isEmpty(admission?.admDate) && ( | ||
<div className="currentAdmissionData__item"> | ||
<span className="item_label">{t("admission.admDate")}</span> | ||
<p className="item_content">{renderDate(admission?.admDate)}</p> | ||
</div> | ||
)} | ||
{!isEmpty(admission?.admType?.description) && ( | ||
<div className="currentAdmissionData__item"> | ||
<span className="item_label">{t("admission.admType")}</span> | ||
<p className="item_content">{admission?.admType?.description}</p> | ||
</div> | ||
)} | ||
{!isEmpty(admission?.diseaseIn?.description) && ( | ||
<div className="currentAdmissionData__item"> | ||
<span className="item_label">{t("admission.diseaseIn")}</span> | ||
<p className="item_content">{admission?.diseaseIn?.description}</p> | ||
</div> | ||
)} | ||
{!isEmpty(admission?.note) && ( | ||
<div className="fullWidth currentAdmissionData__item"> | ||
<span className="item_label">{t("admission.note")}</span> | ||
<p className="item_content">{admission?.note}</p> | ||
</div> | ||
)} | ||
</div> | ||
</div> | ||
); | ||
}; |
Oops, something went wrong.