Skip to content

Commit b953328

Browse files
committed
Merge remote-tracking branch
'origin/issue/442_form_js_builds_invalid_Task_resource_when_submitting_form' into develop
2 parents 61f98bb + 7fb05ad commit b953328

2 files changed

Lines changed: 29 additions & 18 deletions

File tree

dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/adapter/ResourceTask.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,10 @@ private Function<ParameterComponent, InputItem> toInputItem(Map<String, Integer>
177177
id = id + '|' + count;
178178
}
179179
else
180+
{
180181
idCounter.put(id, 0);
182+
id = id + '|' + 0;
183+
}
181184

182185
String label = i.hasType() && i.getType().hasCoding() ? i.getType().getCoding().stream()
183186
.filter(Coding::hasSystemElement).filter(c -> c.getSystemElement().hasValue())

dsf-fhir/dsf-fhir-server/src/main/resources/fhir/static/form.js

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,14 @@ function readTaskInputsFromForm() {
3535

3636
if (id !== "http://dsf.dev/fhir/CodeSystem/bpmn-message|message-name") {
3737
document.querySelectorAll(`div.row[for^="${CSS.escape(id)}"]`).forEach(row => {
38-
const result = readAndValidateTaskInput(input, row)
38+
if (id === toIdWithoutIndex(row.getAttribute("for"))) {
39+
const result = readAndValidateTaskInput(input, row)
3940

40-
if (result.input)
41-
newInputs.push(result.input)
42-
else if (!result.valid)
43-
valid = false
41+
if (result.input)
42+
newInputs.push(result.input)
43+
else if (!result.valid)
44+
valid = false
45+
}
4446
})
4547
} else {
4648
newInputs.push(input)
@@ -95,12 +97,12 @@ function readAndValidateTaskInput(input, row) {
9597
return newTaskInputBoolean(input.type, id, htmlInputs[0].checked, htmlInputs[1].checked, optional)
9698
}
9799
else if (htmlInputs?.length === 5) {
98-
const input0FhirType = htmlInputs[0].getAttribute("fhir-type")
100+
const input0FhirType = htmlInputs[0].getAttribute("fhir-type")
99101

100-
if (input0FhirType.startsWith("Quantity")) {
101-
return new newTaskInputQuantity(input.type, id, htmlInputs[0].value, htmlInputs[1].value, htmlInputs[2].value, htmlInputs[3].value, htmlInputs[4].value, optional)
102-
}
103-
}
102+
if (input0FhirType.startsWith("Quantity")) {
103+
return new newTaskInputQuantity(input.type, id, htmlInputs[0].value, htmlInputs[1].value, htmlInputs[2].value, htmlInputs[3].value, htmlInputs[4].value, optional)
104+
}
105+
}
104106

105107
return { input: null, valid: false }
106108
}
@@ -267,7 +269,7 @@ function readQuestionnaireResponseAnswersFromForm() {
267269
}
268270
}
269271
})
270-
272+
271273
const practitionerIdentifierValue = document.querySelector('#practitionerIdentifierValue')?.value
272274
if (practitionerIdentifierValue !== undefined) {
273275
questionnaireResponse.author.type = "Practitioner"
@@ -440,8 +442,8 @@ function newQuestionnaireResponseItemQuantity(text, id, comparator, value, unit,
440442
code: result.value.code
441443
}
442444
}]
443-
}
444-
return { item: item, valid: true }
445+
}
446+
return { item: item, valid: true }
445447
} else
446448
return { input: null, valid: result.valid }
447449
}
@@ -587,7 +589,7 @@ function validateString(errorListElement, value, optional, valueName) {
587589

588590
function validateStringInList(errorListElement, value, list, optional, valueName) {
589591
const valueInList = s => list.includes(s)
590-
return validateType(errorListElement, value, optional, valueName, valueInList, "not in [" + list.toString() + "]" , v => v)
592+
return validateType(errorListElement, value, optional, valueName, valueInList, "not in [" + list.toString() + "]", v => v)
591593
}
592594

593595
function validateInteger(errorListElement, value, optional, valueName) {
@@ -830,7 +832,7 @@ function getValueOfDifferential(differentials, path, property) {
830832
}
831833

832834
function modifyTaskInputRow(definition) {
833-
const id = definition.typeSystem + "|" + definition.typeCode
835+
const id = definition.typeSystem + "|" + definition.typeCode + "|0"
834836
const row = document.querySelector(`div.row[for="${CSS.escape(id)}"]`)
835837

836838
if (row) {
@@ -874,14 +876,20 @@ function modifyQuestionnaireInputRow(item) {
874876
}
875877
}
876878

879+
function toIdWithoutIndex(id) {
880+
return id.slice(0, id.lastIndexOf('|'))
881+
}
882+
877883
function appendInputRowAfter(id) {
878-
const rows = document.querySelectorAll(`div.row[for^="${CSS.escape(id)}"]`)
884+
id = toIdWithoutIndex(id);
885+
886+
const rows = document.querySelectorAll(`div.row[for^="${CSS.escape(id)}"]`).values().filter(e => id === toIdWithoutIndex(e.getAttribute("for"))).toArray()
879887

880888
if (rows.length <= 0)
881889
return
882890

883-
const idParts = rows[rows.length - 1].getAttribute("for")?.split("|")
884-
const index = idParts && idParts.length === 3 ? parseInt(idParts[2]) + 1 : 1
891+
const forAttr = rows[rows.length - 1].getAttribute("for")
892+
const index = parseInt(forAttr.slice(forAttr.lastIndexOf("|") + 1)) + 1
885893
const clone = rows[0].cloneNode(true)
886894

887895
clone.setAttribute("for", id + "|" + index)

0 commit comments

Comments
 (0)