@@ -118,14 +118,17 @@ function validateFormsArgs(formUuid: string, rawFormJson: any): Error {
118118 * @param {string } [formSessionIntent] - The optional form session intent.
119119 * @returns {FormSchema } - The refined form JSON object of type FormSchema.
120120 */
121- function refineFormJson (
121+ async function refineFormJson (
122122 formJson : any ,
123123 schemaTransformers : FormSchemaTransformer [ ] = [ ] ,
124124 formSessionIntent ?: string ,
125- ) : FormSchema {
125+ ) : Promise < FormSchema > {
126126 removeInlineSubForms ( formJson , formSessionIntent ) ;
127127 // apply form schema transformers
128- schemaTransformers . reduce ( ( draftForm , transformer ) => transformer . transform ( draftForm ) , formJson ) ;
128+ for ( let transformer of schemaTransformers ) {
129+ const draftForm = await transformer . transform ( formJson ) ;
130+ formJson = draftForm ;
131+ }
129132 setEncounterType ( formJson ) ;
130133 return applyFormIntent ( formSessionIntent , formJson ) ;
131134}
@@ -144,7 +147,7 @@ function parseFormJson(formJson: any): FormSchema {
144147 * @param {FormSchema } formJson - The input form JSON object of type FormSchema.
145148 * @param {string } formSessionIntent - The form session intent.
146149 */
147- function removeInlineSubForms ( formJson : FormSchema , formSessionIntent : string ) : void {
150+ async function removeInlineSubForms ( formJson : FormSchema , formSessionIntent : string ) : Promise < void > {
148151 for ( let i = formJson . pages . length - 1 ; i >= 0 ; i -- ) {
149152 const page = formJson . pages [ i ] ;
150153 if (
@@ -153,7 +156,7 @@ function removeInlineSubForms(formJson: FormSchema, formSessionIntent: string):
153156 page . subform ?. form ?. encounterType === formJson . encounterType
154157 ) {
155158 const nonSubformPages = page . subform . form . pages . filter ( ( page ) => ! isTrue ( page . isSubform ) ) ;
156- formJson . pages . splice ( i , 1 , ...refineFormJson ( page . subform . form , [ ] , formSessionIntent ) . pages ) ;
159+ formJson . pages . splice ( i , 1 , ...( await refineFormJson ( page . subform . form , [ ] , formSessionIntent ) ) . pages ) ;
157160 }
158161 }
159162}
0 commit comments