Skip to content

Commit

Permalink
Fix bug with modified loaded form being saved to EHR and then being r…
Browse files Browse the repository at this point in the history
…everted
  • Loading branch information
jtquach1 committed May 20, 2024
1 parent b5893f1 commit eb5e048
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/views/Questionnaire/QuestionnaireForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,18 @@ type PopupAction =
>;
};

const getNewPopupOption = (questionnaireResponse: QuestionnaireResponse) => {
const date = new Date(questionnaireResponse?.authored || Date.now());
const option =
date.toLocaleDateString(undefined, DATE_TIME_FORMAT_OPTIONS) +
' (' +
questionnaireResponse?.status +
')';
return option;
};

const getNewPopupOptions = (questionnaireResponses: QuestionnaireResponse[]) => {
return questionnaireResponses.map(resource => {
const date = new Date(resource?.authored || Date.now());
const option =
date.toLocaleDateString(undefined, DATE_TIME_FORMAT_OPTIONS) + ' (' + resource?.status + ')';
return option;
});
return questionnaireResponses.map(getNewPopupOption);
};

const reducer = (state: PopupState, action: PopupAction): PopupState => {
Expand Down Expand Up @@ -1431,6 +1436,10 @@ export function QuestionnaireForm(props: QuestionnaireProps) {
const showPopup = !isAdaptiveForm() || isAdaptiveFormWithoutItem();
storeQuestionnaireResponseToEhr(qr, showPopup);
popupDispatch({ type: PopupActionType.SAVED_TO_EHR });

// After saving the form to the EHR, keep it loaded.
const popupOption = getNewPopupOption(qr as QuestionnaireResponse);
popupCallback(popupOption);
if (showPopup) {
popupDispatch({ type: PopupActionType.OPEN_POPUP });
} else {
Expand Down

0 comments on commit eb5e048

Please sign in to comment.