@@ -18,7 +18,6 @@ import {IEntityCreatedResponse} from 'src/app/interfaces/entity-created-response
1818import { ENTER , COMMA } from '@angular/cdk/keycodes' ;
1919import { DataAcquisitionService } from 'src/app/services/gateway/data-acquisition/data-acquisition.service' ;
2020import { MatSelectModule } from "@angular/material/select" ;
21- import { MeasureDefinitionService } from "../../../services/gateway/measure-definition/measure.service" ;
2221
2322@Component ( {
2423 selector : 'app-data-acquisition-fhir-list-config-form' ,
@@ -36,11 +35,11 @@ import {MeasureDefinitionService} from "../../../services/gateway/measure-defini
3635 MatSelectModule ,
3736 ReactiveFormsModule ,
3837 MatSelectModule
39- ] ,
38+ ] ,
4039 templateUrl : './data-acquisition-fhir-list-config-form.component.html' ,
4140 styleUrls : [ './data-acquisition-fhir-list-config-form.component.scss' ]
4241} )
43- export class DataAcquisitionFhirListConfigFormComponent {
42+ export class DataAcquisitionFhirListConfigFormComponent implements OnInit , OnChanges {
4443 @Input ( ) item ! : IDataAcquisitionFhirListConfigModel ;
4544
4645 @Input ( ) formMode ! : FormMode ;
@@ -64,35 +63,34 @@ export class DataAcquisitionFhirListConfigFormComponent {
6463 readonly separatorKeysCodes = [ ENTER , COMMA ] as const ;
6564
6665 reportTypes : string [ ] = [ ] ;
67-
68- constructor ( private snackBar : MatSnackBar , private dataAcquisitionService : DataAcquisitionService , private measureDefinitionConfigurationService : MeasureDefinitionService , private fb : FormBuilder ) {
69-
70- //initialize form with fields based on IDataAcquisitionQueryConfigModel
66+ statuses = [ 'Admit' , 'Discharge' ] ;
67+ timeCategories : string [ ] = [ 'LessThan24Hours' , 'Between24To48Hours' , 'MoreThan48Hours' ] ;
68+
69+ constructor (
70+ private snackBar : MatSnackBar ,
71+ private dataAcquisitionService : DataAcquisitionService ,
72+ private fb : FormBuilder
73+ ) {
74+ // Initialize form with a single patient row
7175 this . configForm = this . fb . group ( {
7276 facilityId : this . fb . control ( '' , Validators . required ) ,
7377 fhirServerBaseUrl : this . fb . control ( '' , Validators . required ) ,
74- patientListControl : this . fb . array ( [ // Initialize FormArray with an array of FormGroups
75- this . fb . group ( {
76- listIds : [ '' , Validators . required ] ,
77- measureIds : [ '' , Validators . required ]
78- } )
79- ] )
78+ patientListControl : this . fb . array ( [ this . createPatientFormGroup ( ) ] )
79+ } ) ;
80+ }
81+
82+ // Method must be a class-level method, not inside constructor
83+ createPatientFormGroup ( ehrPatient ?: IEhrPatientListModel ) : FormGroup {
84+ return this . fb . group ( {
85+ status : this . fb . control ( ehrPatient ?. status ?? '' , Validators . required ) ,
86+ timeFrame : this . fb . control ( ehrPatient ?. timeFrame ?? '' , Validators . required ) ,
87+ fhirId : this . fb . control ( ehrPatient ?. fhirId ?? '' , Validators . required )
8088 } ) ;
8189 }
8290
8391 ngOnInit ( ) : void {
8492 this . configForm . reset ( ) ;
8593
86- this . measureDefinitionConfigurationService . getMeasureDefinitionConfigurations ( ) . subscribe (
87- {
88- next : ( response ) => {
89- this . reportTypes = response . map ( model => model . id ) ;
90- } ,
91- error : ( err ) => {
92- this . submittedConfiguration . emit ( { id : '' , message : err . message } ) ;
93- }
94- } ) ;
95-
9694 if ( this . item ) {
9795 console . log ( "DataAcquisitionFhirListConfigFormComponent ngOnInit" ) ;
9896 console . log ( this . item ) ;
@@ -103,10 +101,12 @@ export class DataAcquisitionFhirListConfigFormComponent {
103101 this . fhirServerBaseUrlControl . setValue ( this . item . fhirBaseServerUrl ) ;
104102 this . fhirServerBaseUrlControl . updateValueAndValidity ( ) ;
105103
106- this . loadPatientLists ( this . item . ehrPatientLists ) ;
104+ // this.loadPatientLists(this.item.ehrPatientLists);
105+ this . populateAllCombinations ( this . item . ehrPatientLists ) ;
107106 this . patientListControl . updateValueAndValidity ( ) ;
108107
109108 } else {
109+ this . populateAllCombinations ( ) ;
110110 this . formMode = FormMode . Create ;
111111 }
112112
@@ -115,6 +115,21 @@ export class DataAcquisitionFhirListConfigFormComponent {
115115 } ) ;
116116 }
117117
118+ private populateAllCombinations ( ehrPatientList ?: IEhrPatientListModel [ ] ) : void {
119+ this . patientListControl . clear ( ) ;
120+
121+ for ( const status of this . statuses ) {
122+ for ( const time of this . timeCategories ) {
123+ const existingPatient = ehrPatientList ?. find ( p => p . status === status && p . timeFrame === time ) ;
124+ this . patientListControl . push ( this . fb . group ( {
125+ status : [ { value : status , disabled : true } ] ,
126+ timeFrame : [ { value : time , disabled : true } ] ,
127+ fhirId : [ existingPatient ?. fhirId ?? '' , Validators . required ]
128+ } ) ) ;
129+ }
130+ }
131+ }
132+
118133 ngOnChanges ( changes : SimpleChanges ) {
119134
120135 if ( changes [ 'item' ] && changes [ 'item' ] . currentValue ) {
@@ -124,7 +139,8 @@ export class DataAcquisitionFhirListConfigFormComponent {
124139 this . fhirServerBaseUrlControl . setValue ( this . item . fhirBaseServerUrl ) ;
125140 this . fhirServerBaseUrlControl . updateValueAndValidity ( ) ;
126141
127- this . loadPatientLists ( this . item . ehrPatientLists ) ;
142+ //this.loadPatientLists(this.item.ehrPatientLists);
143+ this . populateAllCombinations ( this . item . ehrPatientLists ) ;
128144 this . patientListControl . updateValueAndValidity ( ) ;
129145
130146 // toggle view
@@ -161,21 +177,21 @@ export class DataAcquisitionFhirListConfigFormComponent {
161177 this . fhirServerBaseUrlControl . updateValueAndValidity ( ) ;
162178 }
163179
164- clearPatientList ( ) : void {
165- this . patientListControl . setValue ( [ ] ) ;
166- this . patientListControl . updateValueAndValidity ( ) ;
180+ clearFhirId ( patientForm : FormGroup ) {
181+ const control = patientForm . get ( 'fhirId' ) ;
182+ control ?. setValue ( '' ) ; // Clear the value
183+ control ?. markAsTouched ( ) ; // Mark it touched so error shows immediately
167184 }
168185
169186 submitConfiguration ( ) : void {
170187 if ( this . configForm . valid ) {
171- const ehrPatientLists = this . patientListControl . controls . map ( ( control , index ) => {
188+ const ehrPatientLists = this . patientListControl . controls . map ( control => {
172189 const patientForm = control as FormGroup ;
173190 return {
174- measureIds : patientForm . value . measureIds ,
175- listIds : patientForm . value . listIds
176- ? patientForm . value . listIds . split ( ',' )
177- : [ ]
178- } ;
191+ status : patientForm . get ( 'status' ) ?. value ,
192+ timeFrame : patientForm . get ( 'timeFrame' ) ?. value ,
193+ fhirId : patientForm . get ( 'fhirId' ) ?. value
194+ } as IEhrPatientListModel ;
179195 } ) ;
180196 if ( this . formMode == FormMode . Create ) {
181197 this . dataAcquisitionService . createFhirListConfiguration ( this . facilityIdControl . value , {
@@ -217,48 +233,4 @@ export class DataAcquisitionFhirListConfigFormComponent {
217233 }
218234 }
219235
220- addPatientList ( itemIndex : number ) {
221- const patientForm = this . fb . group ( {
222- measureIds : this . fb . control ( '' , Validators . required ) ,
223- listIds : this . fb . control ( '' , Validators . required )
224- } ) ;
225- this . patientListControl . push ( patientForm ) ;
226- }
227-
228- removePatientList ( itemIndex : number ) {
229- this . patientListControl . removeAt ( itemIndex ) ;
230- }
231-
232- private loadPatientLists ( ehrPatientList : IEhrPatientListModel [ ] ) : void {
233-
234- this . patientListControl . clear ( ) ;
235- this . patientListControl . updateValueAndValidity ( ) ;
236-
237- if ( ehrPatientList ?. length ) {
238-
239- ehrPatientList . forEach ( ( ehrPatientListItem : IEhrPatientListModel ) => {
240-
241- let measureIds = ( ehrPatientListItem . measureIds ?? [ ] ) ;
242- let listIds = ( ehrPatientListItem . listIds ?? [ ] ) . join ( ", " ) ;
243-
244- const patientForm = this . fb . group ( {
245- measureIds : this . fb . control ( measureIds , Validators . required ) ,
246- listIds : this . fb . control ( listIds , Validators . required )
247- } ) ;
248- this . patientListControl . push ( patientForm ) ;
249- } ) ;
250- } else {
251- const patientForm = this . fb . group ( {
252- measureIds : this . fb . control ( '' , Validators . required ) ,
253- listIds : this . fb . control ( '' , Validators . required )
254- } ) ;
255- this . patientListControl . push ( patientForm ) ;
256- }
257-
258- }
259-
260- compareReportTypes ( object1 : any , object2 : any ) {
261- return ( object1 && object2 ) && object1 === object2 ;
262- }
263-
264236}
0 commit comments