@@ -108,14 +108,17 @@ function validateFormsArgs(formUuid: string, rawFormJson: any): Error {
108108 * @param {string } [formSessionIntent] - The optional form session intent.
109109 * @returns {FormSchema } - The refined form JSON object of type FormSchema.
110110 */
111- function refineFormJson (
111+ async function refineFormJson (
112112 formJson : any ,
113113 schemaTransformers : FormSchemaTransformer [ ] = [ ] ,
114114 formSessionIntent ?: string ,
115- ) : FormSchema {
115+ ) : Promise < FormSchema > {
116116 removeInlineSubForms ( formJson , formSessionIntent ) ;
117117 // apply form schema transformers
118- schemaTransformers . reduce ( ( draftForm , transformer ) => transformer . transform ( draftForm ) , formJson ) ;
118+ for ( let transformer of schemaTransformers ) {
119+ const draftForm = await transformer . transform ( formJson ) ;
120+ formJson = draftForm ;
121+ }
119122 setEncounterType ( formJson ) ;
120123 return applyFormIntent ( formSessionIntent , formJson ) ;
121124}
@@ -134,7 +137,7 @@ function parseFormJson(formJson: any): FormSchema {
134137 * @param {FormSchema } formJson - The input form JSON object of type FormSchema.
135138 * @param {string } formSessionIntent - The form session intent.
136139 */
137- function removeInlineSubForms ( formJson : FormSchema , formSessionIntent : string ) : void {
140+ async function removeInlineSubForms ( formJson : FormSchema , formSessionIntent : string ) : Promise < void > {
138141 for ( let i = formJson . pages . length - 1 ; i >= 0 ; i -- ) {
139142 const page = formJson . pages [ i ] ;
140143 if (
@@ -143,7 +146,7 @@ function removeInlineSubForms(formJson: FormSchema, formSessionIntent: string):
143146 page . subform ?. form ?. encounterType === formJson . encounterType
144147 ) {
145148 const nonSubformPages = page . subform . form . pages . filter ( ( page ) => ! isTrue ( page . isSubform ) ) ;
146- formJson . pages . splice ( i , 1 , ...refineFormJson ( page . subform . form , [ ] , formSessionIntent ) . pages ) ;
149+ formJson . pages . splice ( i , 1 , ...( await refineFormJson ( page . subform . form , [ ] , formSessionIntent ) ) . pages ) ;
147150 }
148151 }
149152}
0 commit comments