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

#1219|DEA fails if no options provided for Duration #1237

Closed
wants to merge 1 commit into from
Closed
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
164 changes: 40 additions & 124 deletions src/formDesigner/common/FormDesignerHandlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,7 @@ export const formDesignerAddFormElement = (draft, draftFormElements, elementInde
draft.detectBrowserCloseEvent = true;
};

export const formDesignerHandleGroupElementChange = (
draft,
draftFormElementGroup,
propertyName,
value,
elementIndex = -1
) => {
export const formDesignerHandleGroupElementChange = (draft, draftFormElementGroup, propertyName, value, elementIndex = -1) => {
if (elementIndex === -1) {
draftFormElementGroup[propertyName] = value;
} else {
Expand All @@ -74,35 +68,19 @@ export const formDesignerHandleGroupElementChange = (
draft.detectBrowserCloseEvent = true;
};

export const formDesignerHandleInlineNumericAttributes = (
draftFormElement,
propertyName,
value
) => {
export const formDesignerHandleInlineNumericAttributes = (draftFormElement, propertyName, value) => {
draftFormElement["inlineNumericDataTypeAttributes"][propertyName] = value;
};

export const formDesignerHandleInlineCodedConceptAnswers = (
draftFormElement,
answerName,
answerIndex
) => {
export const formDesignerHandleInlineCodedConceptAnswers = (draftFormElement, answerName, answerIndex) => {
draftFormElement.inlineCodedAnswers[answerIndex].name = answerName;
};

export const formDesignerOnToggleInlineConceptCodedAnswerAttribute = (
draftFormElement,
propertyName,
answerIndex
) => {
draftFormElement.inlineCodedAnswers[answerIndex][propertyName] = !draftFormElement
.inlineCodedAnswers[answerIndex][propertyName];
export const formDesignerOnToggleInlineConceptCodedAnswerAttribute = (draftFormElement, propertyName, answerIndex) => {
draftFormElement.inlineCodedAnswers[answerIndex][propertyName] = !draftFormElement.inlineCodedAnswers[answerIndex][propertyName];
};

export const formDesignerOnDeleteInlineConceptCodedAnswerDelete = (
draftFormElement,
answerIndex
) => {
export const formDesignerOnDeleteInlineConceptCodedAnswerDelete = (draftFormElement, answerIndex) => {
draftFormElement.inlineCodedAnswers.splice(answerIndex, 1);
};

Expand All @@ -121,12 +99,7 @@ export const formDesignerOnConceptAnswerAlphabeticalSort = draftFormElement => {
draftFormElement.inlineCodedAnswers = alphabeticalSort(conceptAnswers);
};

export const formDesignerHandleInlineConceptAttributes = (
draftFormElement,
attributeName,
propertyName,
value
) => {
export const formDesignerHandleInlineConceptAttributes = (draftFormElement, attributeName, propertyName, value) => {
draftFormElement[attributeName][propertyName] = value;
};

Expand All @@ -143,23 +116,20 @@ export const formDesignerHandleInlineCodedAnswerAddition = draftFormElement => {
});
};

export const formDesignerHandleGroupElementKeyValueChange = (
draft,
draftFormElement,
propertyName,
value
) => {
if (
includes(
["IdSourceUUID", "unique", "groupSubjectTypeUUID", "groupSubjectRoleUUID"],
propertyName
)
) {
export const formDesignerHandleGroupElementKeyValueChange = (draft, draftFormElement, propertyName, value) => {
if (propertyName === "durationOptions") {
if (value === "") {
draftFormElement.keyValues.durationOptions = [];
draftFormElement.keyValues.durationOptionsError = true;
} else {
draftFormElement.keyValues.durationOptions = value;
draftFormElement.keyValues.durationOptionsError = false;
}
}
if (includes(["IdSourceUUID", "unique", "groupSubjectTypeUUID", "groupSubjectRoleUUID"], propertyName)) {
draftFormElement.keyValues[propertyName] = value;
} else if (propertyName === "editable") {
value === "undefined"
? (draftFormElement.keyValues[propertyName] = false)
: delete draftFormElement.keyValues[propertyName];
value === "undefined" ? (draftFormElement.keyValues[propertyName] = false) : delete draftFormElement.keyValues[propertyName];
} else if (["datePickerMode", "timePickerMode"].includes(propertyName)) {
draftFormElement.keyValues[propertyName] = value;
} else if (
Expand All @@ -183,10 +153,7 @@ export const formDesignerHandleGroupElementKeyValueChange = (
draftFormElement.keyValues["durationOptions"] = [];
}
if (draftFormElement.keyValues["durationOptions"].includes(propertyName)) {
draftFormElement.keyValues["durationOptions"].splice(
draftFormElement.keyValues["durationOptions"].indexOf(propertyName),
1
);
draftFormElement.keyValues["durationOptions"].splice(draftFormElement.keyValues["durationOptions"].indexOf(propertyName), 1);
} else {
draftFormElement.keyValues["durationOptions"].push(value);
}
Expand Down Expand Up @@ -215,9 +182,7 @@ export const formDesignerHandleExcludedAnswers = (draft, draftFormElement, name,
};

export const formDesignerHandleModeForDate = (draftFormElement, propertyName, value) => {
value === "durationOptions"
? delete draftFormElement.keyValues["datePickerMode"]
: delete draftFormElement.keyValues["durationOptions"];
value === "durationOptions" ? delete draftFormElement.keyValues["datePickerMode"] : delete draftFormElement.keyValues["durationOptions"];
draftFormElement[propertyName] = value;
};

Expand All @@ -226,11 +191,7 @@ export const formDesignerHandleRegex = (draftFormElement, propertyName, value) =
draftFormElement[propertyName] = value;
};

export const formDesignerHandleConceptFormLibrary = (
draftFormElement,
value,
inlineConcept = false
) => {
export const formDesignerHandleConceptFormLibrary = (draftFormElement, value, inlineConcept = false) => {
if (inlineConcept) {
draftFormElement.showConceptLibrary = value;
draftFormElement.inlineConceptErrorMessage = formDesignerGetEmptyFormElement().inlineConceptErrorMessage;
Expand Down Expand Up @@ -292,16 +253,12 @@ export const formDesignerOnSaveInlineConcept = (clonedFormElement, updateState)
lowNormal: clonedFormElement["inlineNumericDataTypeAttributes"].lowNormal,
highNormal: clonedFormElement["inlineNumericDataTypeAttributes"].highNormal,
unit:
clonedFormElement["inlineNumericDataTypeAttributes"].unit === ""
? null
: clonedFormElement["inlineNumericDataTypeAttributes"].unit,
clonedFormElement["inlineNumericDataTypeAttributes"].unit === "" ? null : clonedFormElement["inlineNumericDataTypeAttributes"].unit,
answers: clonedFormElement["inlineCodedAnswers"]
};

if (inlineConceptObject.dataType === "Location") {
if (
clonedFormElement["inlineLocationDataTypeKeyValues"].lowestAddressLevelTypeUUIDs.length === 0
) {
if (clonedFormElement["inlineLocationDataTypeKeyValues"].lowestAddressLevelTypeUUIDs.length === 0) {
locationValidation = true;
} else {
const keyValues = [];
Expand All @@ -313,9 +270,7 @@ export const formDesignerOnSaveInlineConcept = (clonedFormElement, updateState)
key: "lowestAddressLevelTypeUUIDs",
value: clonedFormElement["inlineLocationDataTypeKeyValues"].lowestAddressLevelTypeUUIDs
};
if (
!isEmpty(clonedFormElement["inlineLocationDataTypeKeyValues"].highestAddressLevelTypeUUID)
) {
if (!isEmpty(clonedFormElement["inlineLocationDataTypeKeyValues"].highestAddressLevelTypeUUID)) {
keyValues[2] = {
key: "highestAddressLevelTypeUUID",
value: clonedFormElement["inlineLocationDataTypeKeyValues"].highestAddressLevelTypeUUID
Expand Down Expand Up @@ -366,23 +321,15 @@ export const formDesignerOnSaveInlineConcept = (clonedFormElement, updateState)
}

if (inlineConceptObject.dataType === "Numeric") {
if (
parseInt(inlineConceptObject.lowAbsolute) === null ||
parseInt(inlineConceptObject.highAbsolute) === null
) {
if (parseInt(inlineConceptObject.lowAbsolute) === null || parseInt(inlineConceptObject.highAbsolute) === null) {
absoluteValidation = false;
} else if (
parseInt(inlineConceptObject.lowAbsolute) > parseInt(inlineConceptObject.highAbsolute)
) {
} else if (parseInt(inlineConceptObject.lowAbsolute) > parseInt(inlineConceptObject.highAbsolute)) {
absoluteValidation = true;
} else {
absoluteValidation = false;
}

if (
parseInt(inlineConceptObject.lowNormal) === null ||
parseInt(inlineConceptObject.highNormal === null)
) {
if (parseInt(inlineConceptObject.lowNormal) === null || parseInt(inlineConceptObject.highNormal === null)) {
normalValidation = false;
} else if (parseInt(inlineConceptObject.lowNormal) > parseInt(inlineConceptObject.highNormal)) {
normalValidation = true;
Expand Down Expand Up @@ -430,12 +377,7 @@ export const formDesignerOnSaveInlineConcept = (clonedFormElement, updateState)
counter = counter + 1;

if (counter === length) {
!flagForEmptyAnswer &&
formDesignerOnSubmitInlineConcept(
inlineConceptObject,
clonedFormElement,
updateState
);
!flagForEmptyAnswer && formDesignerOnSubmitInlineConcept(inlineConceptObject, clonedFormElement, updateState);
}
}
})
Expand All @@ -460,12 +402,7 @@ export const formDesignerOnSaveInlineConcept = (clonedFormElement, updateState)
console.log("Dynamic concept added through Coded", response);
counter = counter + 1;
if (counter === length) {
!flagForEmptyAnswer &&
formDesignerOnSubmitInlineConcept(
inlineConceptObject,
clonedFormElement,
updateState
);
!flagForEmptyAnswer && formDesignerOnSubmitInlineConcept(inlineConceptObject, clonedFormElement, updateState);
}
}
});
Expand All @@ -481,29 +418,15 @@ export const formDesignerOnSaveInlineConcept = (clonedFormElement, updateState)
formDesignerOnSubmitInlineConcept(inlineConceptObject, clonedFormElement, updateState);
}
} else {
clonedFormElement.inlineConceptErrorMessage["name"] =
inlineConceptObject.name.trim() === "" ? "concept name is required" : "";
clonedFormElement.inlineConceptErrorMessage["dataType"] =
inlineConceptObject.dataType === "" ? "concept datatype is required" : "";
clonedFormElement.inlineConceptErrorMessage["name"] = inlineConceptObject.name.trim() === "" ? "concept name is required" : "";
clonedFormElement.inlineConceptErrorMessage["dataType"] = inlineConceptObject.dataType === "" ? "concept datatype is required" : "";
clonedFormElement.inlineNumericDataTypeAttributes.error["normalValidation"] = normalValidation;
clonedFormElement.inlineNumericDataTypeAttributes.error[
"absoluteValidation"
] = absoluteValidation;
clonedFormElement.inlineLocationDataTypeKeyValues.error[
"lowestAddressLevelRequired"
] = locationValidation;
clonedFormElement.inlineSubjectDataTypeKeyValues.error[
"subjectTypeRequired"
] = subjectValidation;
clonedFormElement.inlineEncounterDataTypeKeyValues.error[
"encounterTypeRequired"
] = encounterTypeUUIDValidation;
clonedFormElement.inlineEncounterDataTypeKeyValues.error[
"encounterScopeRequired"
] = encounterScopeValidation;
clonedFormElement.inlineEncounterDataTypeKeyValues.error[
"encounterIdentifierRequired"
] = encounterIdentifierValidation;
clonedFormElement.inlineNumericDataTypeAttributes.error["absoluteValidation"] = absoluteValidation;
clonedFormElement.inlineLocationDataTypeKeyValues.error["lowestAddressLevelRequired"] = locationValidation;
clonedFormElement.inlineSubjectDataTypeKeyValues.error["subjectTypeRequired"] = subjectValidation;
clonedFormElement.inlineEncounterDataTypeKeyValues.error["encounterTypeRequired"] = encounterTypeUUIDValidation;
clonedFormElement.inlineEncounterDataTypeKeyValues.error["encounterScopeRequired"] = encounterScopeValidation;
clonedFormElement.inlineEncounterDataTypeKeyValues.error["encounterIdentifierRequired"] = encounterIdentifierValidation;

updateState();
}
Expand Down Expand Up @@ -532,21 +455,14 @@ export const formDesignerUpdateDragDropOrderForFirstGroup = (
}
});
} else {
draftDestinationFormElementGroup.formElements.splice(
destinationElementIndex,
0,
sourceElement
);
draftDestinationFormElementGroup.formElements.splice(destinationElementIndex, 0, sourceElement);
}
draftSourceFormElementGroup.formElements[sourceElementIndex].voided = true;
} else {
draftSourceFormElementGroup.formElements.forEach((element, index) => {
if (!element.voided) {
if (counter === destinationElementIndex) {
const sourceElement = draftSourceFormElementGroup.formElements.splice(
sourceElementIndex,
1
)[0];
const sourceElement = draftSourceFormElementGroup.formElements.splice(sourceElementIndex, 1)[0];
draftSourceFormElementGroup.formElements.splice(index, 0, sourceElement);
}
counter += 1;
Expand Down
Loading