@@ -33,6 +33,7 @@ import { MinLengthValidationModel } from '../question-models/min-length-validati
33
33
import { WorkspaceLauncherQuestion } from '../question-models' ;
34
34
import { DecimalValidationModel } from '../question-models/decimal-validation.model' ;
35
35
import { DisallowDecimalsValidationModel } from '../question-models/disallow-decimals-validation.model' ;
36
+ import { RemoteSelectQuestion } from '../question-models/remote-select-question' ;
36
37
@Injectable ( )
37
38
export class QuestionFactory {
38
39
dataSources : any = { } ;
@@ -745,6 +746,38 @@ export class QuestionFactory {
745
746
return question ;
746
747
}
747
748
749
+ toRemoteSelectQuestion ( schemaQuestion : any ) : RemoteSelectQuestion {
750
+ const dataSource = this . getDataSourceConfig ( schemaQuestion ) ;
751
+ const question = new RemoteSelectQuestion ( {
752
+ dataSource : dataSource . name ,
753
+ dataSourceOptions : dataSource . options ,
754
+ type : '' ,
755
+ key : ''
756
+ } ) ;
757
+ question . questionIndex = this . quetionIndex ;
758
+ question . label = schemaQuestion . label ;
759
+ question . prefix = schemaQuestion . prefix ;
760
+ question . key = schemaQuestion . id ;
761
+ question . renderingType = 'remote-select' ;
762
+ question . validators = this . addValidators ( schemaQuestion ) ;
763
+ question . extras = schemaQuestion ;
764
+ return question ;
765
+ }
766
+
767
+ private getDataSourceConfig (
768
+ schemaQuestion : any
769
+ ) : { name : string ; options : any } {
770
+ const dataSourceName = schemaQuestion . questionOptions ?. dataSource ;
771
+ const dataSourceOptions = schemaQuestion . questionOptions ?. dataSourceOptions ;
772
+ // See https://github.com/openmrs/openmrs-contrib-json-schemas/blob/main/form.schema.json
773
+ const legacyDataSource = schemaQuestion . questionOptions ?. datasource ;
774
+
775
+ return {
776
+ name : dataSourceName ?? legacyDataSource ?. name ?? '' ,
777
+ options : dataSourceOptions ?? legacyDataSource ?. config ?? { }
778
+ } ;
779
+ }
780
+
748
781
toDecimalQuestion ( schemaQuestion : any ) : TextInputQuestion {
749
782
const question = new TextInputQuestion ( {
750
783
placeholder : '' ,
@@ -938,6 +971,8 @@ export class QuestionFactory {
938
971
return this . toFileUploadQuestion ( schema ) ;
939
972
case 'workspace-launcher' :
940
973
return this . toWorkspaceLauncher ( schema ) ;
974
+ case 'remote-select' :
975
+ return this . toRemoteSelectQuestion ( schema ) ;
941
976
default :
942
977
console . warn ( 'New Schema Question Type found.........' + renderType ) ;
943
978
return this . toTextQuestion ( schema ) ;
0 commit comments