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

(feat) O3-2618: Attachments not hooked up in Visit Note #1522

Merged
merged 6 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
25 changes: 0 additions & 25 deletions packages/esm-patient-attachments-app/src/attachments-types.ts

This file was deleted.

62 changes: 0 additions & 62 deletions packages/esm-patient-attachments-app/src/attachments.resource.tsx

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import classNames from 'classnames';
import { SkeletonPlaceholder } from '@carbon/react';
import { type Attachment } from '../attachments-types';
import { type Attachment } from '@openmrs/esm-framework';
import AttachmentThumbnail from './attachment-thumbnail.component';
import styles from './attachments-grid-overview.scss';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
import React, { useState, useEffect, useCallback, useMemo } from 'react';
import { useTranslation } from 'react-i18next';
import { Button, ContentSwitcher, Loading, Switch } from '@carbon/react';
import { showModal, showSnackbar, useLayoutType, UserHasAccess } from '@openmrs/esm-framework';
import {
type UploadedFile,
type Attachment,
showModal,
showSnackbar,
useLayoutType,
UserHasAccess,
createAttachment,
deleteAttachmentPermanently,
useAttachments,
} from '@openmrs/esm-framework';
import { CardHeader, EmptyState } from '@openmrs/esm-patient-common-lib';
import { createAttachment, deleteAttachmentPermanently, useAttachments } from '../attachments.resource';
import { createGalleryEntry } from '../utils';
import { type UploadedFile, type Attachment } from '../attachments-types';
import AttachmentsGridOverview from './attachments-grid-overview.component';
import AttachmentsTableOverview from './attachments-table-overview.component';
import AttachmentPreview from './image-preview.component';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ import {
TableHeader,
TableRow,
} from '@carbon/react';
import { useLayoutType } from '@openmrs/esm-framework';
import { type Attachment, useLayoutType } from '@openmrs/esm-framework';
import React, { useMemo } from 'react';
import { useTranslation } from 'react-i18next';
import { type Attachment } from '../attachments-types';
import styles from './attachments-table-overview.scss';

interface AttachmentsTableOverviewProps {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { useTranslation } from 'react-i18next';
import { Button, ModalHeader, ModalBody, ModalFooter } from '@carbon/react';
import { type Attachment } from '../attachments-types';
import { type Attachment } from '@openmrs/esm-framework';
import styles from './delete-attachment-confirmation-modal.scss';

interface DeleteAttachmentConfirmationProps {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import classNames from 'classnames';
import { useTranslation } from 'react-i18next';
import { Button, OverflowMenu, OverflowMenuItem } from '@carbon/react';
import { Close } from '@carbon/react/icons';
import { useLayoutType } from '@openmrs/esm-framework';
import { type Attachment } from '../attachments-types';
import { type Attachment, useLayoutType } from '@openmrs/esm-framework';
import styles from './image-preview.scss';

interface AttachmentPreviewProps {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { type UploadedFile } from '../attachments-types';
import { type FetchResponse } from '@openmrs/esm-framework';
import { type UploadedFile, type FetchResponse } from '@openmrs/esm-framework';

export interface CameraMediaUploaderContextType {
multipleFiles?: boolean;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, { useState, useCallback, useMemo, useEffect, useRef, useContext } from 'react';
import { type UploadedFile } from '../attachments-types';
import { type FetchResponse, showSnackbar } from '@openmrs/esm-framework';
import { type UploadedFile, type FetchResponse, showSnackbar } from '@openmrs/esm-framework';
import CameraMediaUploaderContext from './camera-media-uploader-context.resources';
import { useTranslation } from 'react-i18next';
import CameraComponent from './camera.component';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import React, { type SyntheticEvent, useCallback, useEffect, useState, useContext } from 'react';
import { useTranslation } from 'react-i18next';
import { Button, TextArea, TextInput, ModalHeader, ModalBody, ModalFooter } from '@carbon/react';
import { UserHasAccess } from '@openmrs/esm-framework';
import { type UploadedFile, UserHasAccess } from '@openmrs/esm-framework';
import styles from './file-review.scss';
import { type UploadedFile } from '../attachments-types';
import CameraMediaUploaderContext from './camera-media-uploader-context.resources';
import { DocumentPdf, DocumentUnknown } from '@carbon/react/icons';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import React, { useContext, useCallback } from 'react';
import { FileUploaderDropContainer } from '@carbon/react';
import styles from './media-uploader.scss';
import CameraMediaUploaderContext from './camera-media-uploader-context.resources';
import { readFileAsString } from '../utils';
import { useTranslation } from 'react-i18next';
import { showSnackbar, useConfig } from '@openmrs/esm-framework';
import { readFileAsString } from '../utils';
import CameraMediaUploaderContext from './camera-media-uploader-context.resources';
import styles from './media-uploader.scss';

const MediaUploaderComponent = () => {
const { setFilesToUpload, allowedExtensions, multipleFiles } = useContext(CameraMediaUploaderContext);
const { t } = useTranslation();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React, { useState, useEffect, useContext } from 'react';
import { useTranslation } from 'react-i18next';
import { showSnackbar } from '@openmrs/esm-framework';
import styles from './uploading-status.scss';
import { FileUploaderItem, Button, ButtonSet, ModalHeader, ModalBody, ModalFooter } from '@carbon/react';
import CameraMediaUploaderContext from './camera-media-uploader-context.resources';
import styles from './uploading-status.scss';

interface UploadingStatusComponentProps {}

Expand Down
4 changes: 1 addition & 3 deletions packages/esm-patient-attachments-app/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { type AttachmentResponse, type Attachment } from './attachments-types';
import { attachmentUrl } from './attachments.resource';
import { formatDate } from '@openmrs/esm-framework';
import { type AttachmentResponse, type Attachment, attachmentUrl, formatDate } from '@openmrs/esm-framework';

export function readFileAsString(file: File) {
return new Promise<string>((resolve) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,17 @@ import {
TextArea,
Tile,
} from '@carbon/react';
import { Add, WarningFilled } from '@carbon/react/icons';
import { Add, Edit, WarningFilled } from '@carbon/react/icons';
import {
type UploadedFile,
createErrorHandler,
ExtensionSlot,
showModal,
showSnackbar,
useConfig,
useLayoutType,
useSession,
createAttachment,
} from '@openmrs/esm-framework';
import { type DefaultWorkspaceProps } from '@openmrs/esm-patient-common-lib';
import type { ConfigObject } from '../config-schema';
Expand All @@ -41,6 +44,9 @@ import {
useVisitNotes,
} from './visit-notes.resource';
import styles from './visit-notes-form.scss';
import { mutate } from 'swr';

const allowedImageTypes = ['image/jpeg', 'image/png', 'image/webp'];

const visitNoteFormSchema = z.object({
noteDate: z.date(),
Expand All @@ -49,8 +55,11 @@ const visitNoteFormSchema = z.object({
}),
secondaryDiagnosisSearch: z.string().optional(),
clinicalNote: z.string().optional(),
image: z.any(),
});

type VisitNotesFormData = z.infer<typeof visitNoteFormSchema>;

interface DiagnosisSearchProps {
name: 'noteDate' | 'primaryDiagnosisSearch' | 'secondaryDiagnosisSearch' | 'clinicalNote';
labelText: string;
Expand All @@ -60,8 +69,6 @@ interface DiagnosisSearchProps {
error?: Object;
}

type VisitNotesFormData = z.infer<typeof visitNoteFormSchema>;

const VisitNotesForm: React.FC<DefaultWorkspaceProps> = ({ closeWorkspace, patientUuid }) => {
const searchTimeoutInMs = 500;
const { t } = useTranslation();
Expand Down Expand Up @@ -89,7 +96,9 @@ const VisitNotesForm: React.FC<DefaultWorkspaceProps> = ({ closeWorkspace, patie
},
});

const currentImage = watch('image');
const { mutateVisitNotes } = useVisitNotes(patientUuid);
const mutateAttachments = () => mutate((key) => typeof key === 'string' && key.startsWith(`/ws/rest/v1/attachment`));
const locationUuid = session?.sessionLocation?.uuid;
const providerUuid = session?.currentProvider?.uuid;

Expand Down Expand Up @@ -173,6 +182,22 @@ const VisitNotesForm: React.FC<DefaultWorkspaceProps> = ({ closeWorkspace, patie
};
};

const showImageCaptureModal = useCallback(() => {
const close = showModal('capture-photo-modal', {
saveFile: (file: UploadedFile) => {
setValue('image', file);
close();
return Promise.resolve();
},
closeModal: () => {
close();
},
allowedExtensions: allowedImageTypes,
multipleFiles: false,
collectDescription: false,
});
}, [patientUuid]);

const onSubmit = useCallback(
(data: VisitNotesFormData, event: SyntheticEvent) => {
const { noteDate, clinicalNote } = data;
Expand Down Expand Up @@ -221,8 +246,16 @@ const VisitNotesForm: React.FC<DefaultWorkspaceProps> = ({ closeWorkspace, patie
);
}
})
.then(() => {
if (data.image) {
return createAttachment(patientUuid, data.image);
}
})
.then(() => {
mutateVisitNotes();
if (data.image) {
mutateAttachments();
}
closeWorkspace();

showSnackbar({
Expand Down Expand Up @@ -503,18 +536,34 @@ const VisitNotesForm: React.FC<DefaultWorkspaceProps> = ({ closeWorkspace, patie
<span className={styles.columnLabel}>{t('image', 'Image')}</span>
</Column>
<Column sm={3}>
<FormGroup legendText={t('addImageToVisit', 'Add an image to this visit')}>
<FormGroup>
<p className={styles.imgUploadHelperText}>
{t('imageUploadHelperText', "Upload an image or use this device's camera to capture an image")}
</p>
<Button
style={{ marginTop: '1rem' }}
kind={isTablet ? 'ghost' : 'tertiary'}
onClick={() => {}}
renderIcon={(props) => <Add size={16} {...props} />}
>
{t('addImage', 'Add image')}
</Button>
{currentImage?.base64Content ? (
<Button
style={{ marginTop: '1rem' }}
kind={isTablet ? 'ghost' : 'tertiary'}
onClick={() => showImageCaptureModal()}
renderIcon={(props) => <Edit size={16} {...props} />}
>
{t('changeImage', 'Change image')}
</Button>
) : (
<Button
style={{ marginTop: '1rem' }}
kind={isTablet ? 'ghost' : 'tertiary'}
onClick={() => showImageCaptureModal()}
renderIcon={(props) => <Add size={16} {...props} />}
>
{t('addImage', 'Add image')}
</Button>
)}
{currentImage?.base64Content && currentImage?.fileType == 'image' ? (
<div className={styles.imgThumbnailContainer}>
<img src={currentImage.base64Content} className={styles.imgThumbnail} />
</div>
) : null}
</FormGroup>
</Column>
</Row>
Expand Down
12 changes: 12 additions & 0 deletions packages/esm-patient-notes-app/src/notes/visit-notes-form.scss
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,18 @@
color: $text-02;
}

.imgThumbnailContainer {
height: 5rem;
width: 6rem;
margin-top: spacing.$spacing-04;
}

.imgThumbnail {
width: 100%;
height: 100%;
object-fit: cover;
}

.button {
height: 4rem;
display: flex;
Expand Down
2 changes: 1 addition & 1 deletion packages/esm-patient-notes-app/translations/am.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"add": "Add",
"addImage": "Add image",
"addImageToVisit": "Add an image to this visit",
"addVisitNote": "Add a visit note",
"changeImage": "Change image",
"clinicalNoteLabel": "Write your notes",
"clinicalNotePlaceholder": "Write any notes here",
"date": "Date",
Expand Down
2 changes: 1 addition & 1 deletion packages/esm-patient-notes-app/translations/ar.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"add": "أضف",
"addImage": "أضف صورة",
"addImageToVisit": "أضف صورة لهذه الزيارة",
"addVisitNote": "أضف ملاحظة للزيارة",
"changeImage": "Change image",
"clinicalNoteLabel": "اكتب ملاحظاتك",
"clinicalNotePlaceholder": "اكتب أي ملاحظات هنا",
"date": "تاريخ",
Expand Down
Loading
Loading