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-2211: draw using a custom simple svg editor #5

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,15 @@
},
"dependencies": {
"@carbon/react": "^1.33.0",
"lodash-es": "^4.17.21",
"react-image-annotate": "^1.8.0"
"@openmrs/esm-patient-common-lib": "^5.0.0",
"@openmrs/openmrs-form-engine-lib": "latest",
"canvas-to-image": "^2.0.3",
"fabric": "^5.3.0",
"lodash-es": "^4.17.21"
},
"peerDependencies": {
"@openmrs/esm-framework": "*",
"@openmrs/esm-patient-common-lib": "5.x",
"dayjs": "1.x",
"react": "18.x",
"react-i18next": "11.x",
Expand Down
24 changes: 24 additions & 0 deletions src/attachments-types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
export interface UploadedFile {
file?: File;
base64Content: string;
fileName: string;
fileType: string;
fileDescription: string;
status?: "uploading" | "complete";
}
export interface Attachment {
id: string;
src: string;
title: string;
description: string;
dateTime: string;
bytesMimeType: string;
bytesContentFamily: string;
}
export interface AttachmentResponse {
bytesContentFamily: string;
bytesMimeType: string;
comment: string;
dateTime: string;
uuid: string;
}
88 changes: 88 additions & 0 deletions src/attachments/attachments.resource.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import { useMemo } from "react";
import useSWR from "swr";
import { FetchResponse, openmrsFetch } from "@openmrs/esm-framework";
import { AttachmentResponse, UploadedFile } from "../attachments-types";

export const attachmentUrl = "/ws/rest/v1/attachment";

export function getAttachmentByUuid(
attachmentUuid: string,
abortController: AbortController
) {
return openmrsFetch(`${attachmentUrl}/${attachmentUuid}`, {
signal: abortController.signal,
});
}

export function useAttachments(
patientUuid: string,
includeEncounterless: boolean
) {
const { data, error, mutate, isLoading, isValidating } = useSWR<
FetchResponse<{ results: Array<AttachmentResponse> }>
>(
`${attachmentUrl}?patient=${patientUuid}&includeEncounterless=${includeEncounterless}`,
openmrsFetch
);

const results = useMemo(
() => ({
isLoading,
data: data?.data.results ?? [],
error,
mutate,
isValidating,
}),
[data, error, isLoading, isValidating, mutate]
);

return results;
}

export function getAttachments(
patientUuid: string,
includeEncounterless: boolean,
abortController: AbortController
) {
return openmrsFetch(
`${attachmentUrl}?patient=${patientUuid}&includeEncounterless=${includeEncounterless}`,
{
signal: abortController.signal,
}
);
}

export async function createAttachment(
patientUuid: string,
fileToUpload: UploadedFile
) {
const formData = new FormData();

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

if (fileToUpload.file) {
formData.append("file", fileToUpload.file);
} else {
formData.append(
"file",
new File([""], fileToUpload.fileName),
fileToUpload.fileName
);
formData.append("base64Content", fileToUpload.base64Content);
}
return openmrsFetch(attachmentUrl, {
method: "POST",
body: formData,
});
}

export function deleteAttachmentPermanently(
attachmentUuid: string,
abortController: AbortController
) {
return openmrsFetch(`${attachmentUrl}/${attachmentUuid}`, {
method: "DELETE",
signal: abortController.signal,
});
}
Loading
Loading