Skip to content

Commit

Permalink
(feat) Extend createAttachment to handle descriptions of image uplo…
Browse files Browse the repository at this point in the history
…ads (#915)

* (feat) Extend createAttachment function to include file description in payload

* Review feedback
  • Loading branch information
denniskigen authored Feb 2, 2024
1 parent b7d9b1c commit 41a6a18
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 26 deletions.
3 changes: 2 additions & 1 deletion packages/framework/esm-api/src/attachments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function getAttachments(patientUuid: string, includeEncounterless: boolea
export async function createAttachment(patientUuid: string, fileToUpload: UploadedFile) {
const formData = new FormData();

formData.append('fileCaption', fileToUpload.fileName);
formData.append('fileCaption', fileToUpload.fileDescription);
formData.append('patient', patientUuid);

if (fileToUpload.file) {
Expand All @@ -28,6 +28,7 @@ export async function createAttachment(patientUuid: string, fileToUpload: Upload
formData.append('file', new File([''], fileToUpload.fileName), fileToUpload.fileName);
formData.append('base64Content', fileToUpload.base64Content);
}

return openmrsFetch(`${attachmentUrl}`, {
method: 'POST',
body: formData,
Expand Down
5 changes: 3 additions & 2 deletions packages/framework/esm-api/src/types/attachments-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ export interface UploadedFile {
export interface Attachment {
id: string;
src: string;
title: string;
description: string;
filename: string;
comment: string;
dateTime: string;
bytesMimeType: string;
bytesContentFamily: string;
}

export interface AttachmentResponse {
bytesContentFamily: string;
bytesMimeType: string;
Expand Down
2 changes: 1 addition & 1 deletion packages/framework/esm-framework/docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -991,7 +991,7 @@ ___

#### Defined in

[packages/framework/esm-api/src/attachments.ts:37](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-api/src/attachments.ts#L37)
[packages/framework/esm-api/src/attachments.ts:38](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-api/src/attachments.ts#L38)

___

Expand Down
30 changes: 15 additions & 15 deletions packages/framework/esm-framework/docs/interfaces/Attachment.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@

- [bytesContentFamily](Attachment.md#bytescontentfamily)
- [bytesMimeType](Attachment.md#bytesmimetype)
- [comment](Attachment.md#comment)
- [dateTime](Attachment.md#datetime)
- [description](Attachment.md#description)
- [filename](Attachment.md#filename)
- [id](Attachment.md#id)
- [src](Attachment.md#src)
- [title](Attachment.md#title)

## Properties

Expand All @@ -36,6 +36,16 @@ ___

___

### comment

**comment**: `string`

#### Defined in

[packages/framework/esm-api/src/types/attachments-types.ts:14](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-api/src/types/attachments-types.ts#L14)

___

### dateTime

**dateTime**: `string`
Expand All @@ -46,13 +56,13 @@ ___

___

### description
### filename

**description**: `string`
**filename**: `string`

#### Defined in

[packages/framework/esm-api/src/types/attachments-types.ts:14](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-api/src/types/attachments-types.ts#L14)
[packages/framework/esm-api/src/types/attachments-types.ts:13](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-api/src/types/attachments-types.ts#L13)

___

Expand All @@ -73,13 +83,3 @@ ___
#### Defined in

[packages/framework/esm-api/src/types/attachments-types.ts:12](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-api/src/types/attachments-types.ts#L12)

___

### title

**title**: `string`

#### Defined in

[packages/framework/esm-api/src/types/attachments-types.ts:13](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-api/src/types/attachments-types.ts#L13)
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

#### Defined in

[packages/framework/esm-api/src/types/attachments-types.ts:20](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-api/src/types/attachments-types.ts#L20)
[packages/framework/esm-api/src/types/attachments-types.ts:21](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-api/src/types/attachments-types.ts#L21)

___

Expand All @@ -30,7 +30,7 @@ ___

#### Defined in

[packages/framework/esm-api/src/types/attachments-types.ts:21](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-api/src/types/attachments-types.ts#L21)
[packages/framework/esm-api/src/types/attachments-types.ts:22](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-api/src/types/attachments-types.ts#L22)

___

Expand All @@ -40,7 +40,7 @@ ___

#### Defined in

[packages/framework/esm-api/src/types/attachments-types.ts:22](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-api/src/types/attachments-types.ts#L22)
[packages/framework/esm-api/src/types/attachments-types.ts:23](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-api/src/types/attachments-types.ts#L23)

___

Expand All @@ -50,7 +50,7 @@ ___

#### Defined in

[packages/framework/esm-api/src/types/attachments-types.ts:23](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-api/src/types/attachments-types.ts#L23)
[packages/framework/esm-api/src/types/attachments-types.ts:24](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-api/src/types/attachments-types.ts#L24)

___

Expand All @@ -60,4 +60,4 @@ ___

#### Defined in

[packages/framework/esm-api/src/types/attachments-types.ts:24](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-api/src/types/attachments-types.ts#L24)
[packages/framework/esm-api/src/types/attachments-types.ts:25](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-api/src/types/attachments-types.ts#L25)
4 changes: 2 additions & 2 deletions packages/framework/esm-react-utils/src/useAttachments.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useMemo } from 'react';
import useSWR from 'swr';
import type { FetchResponse, AttachmentResponse } from '@openmrs/esm-api';
import { attachmentUrl, openmrsFetch } from '@openmrs/esm-api';
import { attachmentUrl, openmrsFetch, type AttachmentResponse, type FetchResponse } from '@openmrs/esm-api';

export function useAttachments(patientUuid: string, includeEncounterless: boolean) {
const { data, error, mutate, isLoading, isValidating } = useSWR<
FetchResponse<{ results: Array<AttachmentResponse> }>
Expand Down

0 comments on commit 41a6a18

Please sign in to comment.