import React, { useEffect, useState } from 'react'; import dayjs from 'dayjs'; import { useTranslation } from 'react-i18next'; import { SkeletonText, Tile, OverflowMenu, OverflowMenuItem, Stack, TextArea, Button, Layer, InlineLoading, } from '@carbon/react'; import { getCoreTranslation, isDesktop, showModal, showSnackbar, useEmrConfiguration, useLayoutType, } from '@openmrs/esm-framework'; import { type PatientNote } from '../types'; import { editPatientNote } from '../notes.resource'; import styles from './styles.scss'; export const InPatientNoteSkeleton: React.FC = () => { return (
); }; interface InPatientNoteProps { mutatePatientNotes(): void; note: PatientNote; promptBeforeClosing(hasUnsavedChanges: boolean): void; } /** * This component shows a note (obs) created with concept as either: * - `consultFreeTextCommentsConcept` from emrapi configuration * - one of the concepts defined in additionalInpatientNotesConceptUuids. * * Note that only notes with encounter type emrConfiguration.inpatientNoteEncounterType are creatable, * editable and deletable from the ward app. * */ const InPatientNote: React.FC = ({ note, mutatePatientNotes, promptBeforeClosing }) => { const { t } = useTranslation(); const [editMode, setEditMode] = useState(false); const [editedNote, setEditedNote] = useState(note.encounterNote); const isTablet = !isDesktop(useLayoutType()); const [isSaving, setIsSaving] = useState(false); const { emrConfiguration } = useEmrConfiguration(); const isInpatientNoteEncounter = note.encounterTypeUuid === emrConfiguration?.inpatientNoteEncounterType?.uuid; useEffect(() => { promptBeforeClosing(editMode); }, [editMode, promptBeforeClosing]); const onSave = async () => { try { setIsSaving(true); await editPatientNote(note.obsUuid, editedNote); setEditMode(false); showSnackbar({ isLowContrast: true, kind: 'success', subtitle: t('patientNoteNowVisible', 'It should be now visible in the notes history'), title: t('visitNoteSaved', 'Patient note saved'), }); mutatePatientNotes(); } catch (e) { showSnackbar({ isLowContrast: true, kind: 'error', subtitle: e?.responseBody?.error?.translatedMessage ?? e?.responseBody?.error?.message, title: t('errorSavingPatientNote', 'Error saving patient note'), }); } finally { setIsSaving(false); } }; return (
{isInpatientNoteEncounter && ( {!editMode && note.obsUuid && ( { setEditMode(true); }} /> )} {note.isEdited && ( { const dispose = showModal('note-history-modal', { close: () => dispose(), note, }); }} /> )} { const dispose = showModal('delete-note-modal', { close: () => dispose(), encounterUuid: note.encounterUuid, onDelete: () => mutatePatientNotes(), }); }} /> )}
{editMode ? (