@@ -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
588590function 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
593595function validateInteger ( errorListElement , value , optional , valueName ) {
@@ -830,7 +832,7 @@ function getValueOfDifferential(differentials, path, property) {
830832}
831833
832834function 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+
877883function 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