This repository has been archived by the owner on Jan 9, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix #1771
- Loading branch information
Showing
8 changed files
with
241 additions
and
1 deletion.
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
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,4 @@ | ||
export default interface Note { | ||
noteDate: Date | ||
text: string | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import React, { useState } from 'react' | ||
import { Modal, Alert, RichText, Label } from '@hospitalrun/components' | ||
import { useTranslation } from 'react-i18next' | ||
import Note from '../../model/Note' | ||
|
||
interface Props { | ||
show: boolean | ||
toggle: () => void | ||
onCloseButtonClick: () => void | ||
onSave: (note: Note) => void | ||
} | ||
|
||
const NewNoteModal = (props: Props) => { | ||
const { show, toggle, onCloseButtonClick, onSave } = props | ||
const { t } = useTranslation() | ||
const [errorMessage, setErrorMessage] = useState('') | ||
const [note, setNote] = useState({ | ||
noteDate: new Date(), | ||
text: '', | ||
}) | ||
|
||
const onFieldChange = (key: string, value: string | any) => { | ||
setNote({ | ||
...note, | ||
[key]: value, | ||
}) | ||
} | ||
|
||
const onRichTextElementChange = ( | ||
event: React.KeyboardEvent<HTMLTextAreaElement>, | ||
fieldName: string, | ||
) => { | ||
onFieldChange(fieldName, event) | ||
} | ||
|
||
const body = ( | ||
<form> | ||
{errorMessage && <Alert color="danger" title={t('states.error')} message={errorMessage} />} | ||
<div className="row"> | ||
<div className="col-md-12"> | ||
<div className="form-group"> | ||
<Label text={t('patient.note')} htmlFor="noteText" /> | ||
<RichText | ||
id="noteText" | ||
value={note.text} | ||
onChange={(event: React.KeyboardEvent<HTMLTextAreaElement>) => { | ||
onRichTextElementChange(event, 'text') | ||
}} | ||
/> | ||
</div> | ||
</div> | ||
</div> | ||
</form> | ||
) | ||
|
||
return ( | ||
<Modal | ||
show={show} | ||
toggle={toggle} | ||
title={t('patient.notes.new')} | ||
body={body} | ||
closeButton={{ | ||
children: t('actions.cancel'), | ||
color: 'danger', | ||
onClick: onCloseButtonClick, | ||
}} | ||
successButton={{ | ||
children: t('patient.notes.new'), | ||
color: 'success', | ||
icon: 'add', | ||
iconLocation: 'left', | ||
onClick: () => { | ||
let newErrorMessage = '' | ||
|
||
if (!note) { | ||
newErrorMessage += `${t('patient.notes.error.noteRequired')} ` | ||
} | ||
|
||
if (!newErrorMessage) { | ||
onSave(note as Note) | ||
} else { | ||
setErrorMessage(newErrorMessage.trim()) | ||
} | ||
}, | ||
}} | ||
/> | ||
) | ||
} | ||
|
||
export default NewNoteModal |
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,96 @@ | ||
/* eslint-disable react/no-danger */ | ||
import React, { useState } from 'react' | ||
import { useSelector, useDispatch } from 'react-redux' | ||
import { useTranslation } from 'react-i18next' | ||
import { Button, List, ListItem, Toast, Alert } from '@hospitalrun/components' | ||
import NewNoteModal from 'patients/notes/NewNoteModal' | ||
import Note from 'model/Note' | ||
import Patient from 'model/Patient' | ||
import { updatePatient } from 'patients/patient-slice' | ||
import { RootState } from '../../store' | ||
import Permissions from '../../model/Permissions' | ||
|
||
interface Props { | ||
patient: Patient | ||
} | ||
|
||
const NoteTab = (props: Props) => { | ||
const dispatch = useDispatch() | ||
const { patient } = props | ||
const { t } = useTranslation() | ||
const { permissions } = useSelector((state: RootState) => state.user) | ||
const [showNewNoteModal, setShowNoteModal] = useState<boolean>(false) | ||
|
||
const onNewNoteClick = () => { | ||
setShowNoteModal(true) | ||
} | ||
|
||
const closeNewNoteModal = () => { | ||
setShowNoteModal(false) | ||
} | ||
|
||
const onAddNoteSuccess = () => { | ||
Toast('success', t('Success!'), t('patients.successfullyAddedNote')) | ||
} | ||
|
||
const onNoteSave = (note: Note) => { | ||
const newNotes: Note[] = [] | ||
|
||
if (patient.notes) { | ||
newNotes.push(...patient.notes) | ||
} | ||
|
||
newNotes.push(note) | ||
|
||
const patientToUpdate = { | ||
...patient, | ||
notes: newNotes, | ||
} | ||
|
||
dispatch(updatePatient(patientToUpdate, onAddNoteSuccess)) | ||
closeNewNoteModal() | ||
} | ||
return ( | ||
<div> | ||
<div className="row"> | ||
<div className="col-md-12 d-flex justify-content-end"> | ||
{permissions.includes(Permissions.WritePatients) && ( | ||
<Button | ||
outlined | ||
color="success" | ||
icon="add" | ||
iconLocation="left" | ||
onClick={onNewNoteClick} | ||
> | ||
{t('patient.notes.new')} | ||
</Button> | ||
)} | ||
</div> | ||
</div> | ||
<br /> | ||
{(!patient.notes || patient.notes.length === 0) && ( | ||
<Alert | ||
color="warning" | ||
title={t('patient.notes.warning.noNotes')} | ||
message={t('patient.notes.addNoteAbove')} | ||
/> | ||
)} | ||
<List> | ||
{patient.notes?.map((a: Note) => ( | ||
<ListItem> | ||
{new Date(a.noteDate).toLocaleString()} | ||
<div dangerouslySetInnerHTML={{ __html: a.text }} /> | ||
</ListItem> | ||
))} | ||
</List> | ||
<NewNoteModal | ||
show={showNewNoteModal} | ||
toggle={closeNewNoteModal} | ||
onCloseButtonClick={closeNewNoteModal} | ||
onSave={onNoteSave} | ||
/> | ||
</div> | ||
) | ||
} | ||
|
||
export default NoteTab |
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