-
Notifications
You must be signed in to change notification settings - Fork 59
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
(fix) revise logic for saving attachments #270
(fix) revise logic for saving attachments #270
Conversation
…-lib into revise-logic-for-saving-encounter
if (EncounterFormManager.evaluatedAttachmentFields(fields)?.length) { | ||
try { | ||
const attachmentsResponse = await Promise.all( | ||
EncounterFormManager.saveAttachments(fields, savedEncounter, abortController), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you just make sure that if there are zero attachments this function returns an empty value for attachmentsResponse
and implement the necessary filters internally?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean something like this?
const evaluatedFields = EncounterFormManager.evaluatedAttachmentFields(fields);
if (evaluatedFields?.length) {
try {
const attachmentsResponse = await Promise.all(
EncounterFormManager.saveAttachments(fields, savedEncounter, abortController),
);
if (attachmentsResponse?.length) {
showSnackbar({
title: t('attachmentsSaved', 'Attachment(s) saved successfully'),
kind: 'success',
isLowContrast: true,
});
}
} catch (error) {
const errorMessages = extractErrorMessagesFromResponse(error);
return Promise.reject({
title: t('errorSavingAttachments', 'Error saving attachment(s)'),
subtitle: errorMessages.join(', '),
kind: 'error',
isLowContrast: false,
});
}
} else {
return [];
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the logic can be handled in the EncounterFormManager.saveAttachments
function,
static saveAttachments(fields: FormField[], encounter: OpenmrsEncounter, abortController: AbortController) {
const complexFields = fields?.filter((field) => field?.questionOptions.rendering === 'file');
return complexFields.map((field) => {
const patientUuid = typeof encounter?.patient === 'string' ? encounter?.patient : encounter?.patient?.uuid;
return saveAttachment(
patientUuid,
field,
field?.questionOptions.concept,
new Date().toISOString(),
encounter?.uuid,
abortController,
);
});
}
Somewhere in here, before return saveAttachment(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the clarification @CynthiaKamau
…-lib into revise-logic-for-saving-encounter
* reivse logic for saving attachments * move logic to encounter form manager * refactor * cleanup
Requirements
Summary
This PR seeks to ensure that no request is made to the attachments endpoint if no field bearing an attachment was filled at the point of submission.
Screenshots
Related Issue
Other