@iapps/ng-dhis2-ui 1.1.78 → 1.1.79

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3564,6 +3564,78 @@ class LineListService {
3564
3564
  // })
3565
3565
  // );
3566
3566
  // }
3567
+ //tracker/trackedEntities.json?program=${programId}&orgUnit=${orgUnit}${ouModeIdentifier}&page=${page}&pageSize=${pageSize}&fields=trackedEntity,orgUnit,attributes[*],enrollments[*]&totalPages=true&${filterParams}${dateFilter}&order=createdAt:desc&trackedEntities=uid1,uid2,uid3
3568
+ // private getTrackedEntityInstances(
3569
+ // programId: string,
3570
+ // orgUnit: string,
3571
+ // page: number,
3572
+ // pageSize: number,
3573
+ // filters: AttributeFilter[] = [],
3574
+ // startDate?: string,
3575
+ // endDate?: string,
3576
+ // ouMode?: string,
3577
+ // filterRootOrgUnit?: boolean,
3578
+ // useOuModeWithOlderDHIS2Instance?: boolean,
3579
+ // filtersFromEvents: FilterConfig[] = []
3580
+ // ): Observable<TrackedEntityResponse> {
3581
+ // const filterParams = buildFilters(filters);
3582
+ // const filterParamsFromEvents = buildFiltersFromEvents(filtersFromEvents);
3583
+ // const dateFilter = [
3584
+ // startDate ? `enrollmentEnrolledAfter=${startDate}` : '',
3585
+ // endDate ? `enrollmentEnrolledBefore=${endDate}` : '',
3586
+ // ]
3587
+ // .filter(Boolean)
3588
+ // .join('&');
3589
+ // const ouModeIdentifier =
3590
+ // ouMode && useOuModeWithOlderDHIS2Instance
3591
+ // ? `&ouMode=${ouMode}`
3592
+ // : `&orgUnitMode=${ouMode}`;
3593
+ // return this.httpClient
3594
+ // .get(
3595
+ // `tracker/trackedEntities.json?program=${programId}&orgUnit=${orgUnit}${ouModeIdentifier}&page=${page}&pageSize=${pageSize}&fields=trackedEntity,orgUnit,attributes[*],enrollments[*]&totalPages=true&${filterParams}${dateFilter}&order=createdAt:desc`
3596
+ // )
3597
+ // .pipe(
3598
+ // switchMap((response: any) => {
3599
+ // if (filterRootOrgUnit) {
3600
+ // response.trackedEntities = response.trackedEntities.filter(
3601
+ // (tei: any) => tei.orgUnit !== orgUnit
3602
+ // );
3603
+ // }
3604
+ // // **Step 1:** Extract unique orgUnits from enrollments
3605
+ // const uniqueOrgUnitIds = new Set<string>();
3606
+ // if (response && response.trackedEntities) {
3607
+ // response.trackedEntities.forEach((tei: any) => {
3608
+ // tei.enrollments?.forEach((enrollment: any) => {
3609
+ // if (enrollment.program === programId) {
3610
+ // uniqueOrgUnitIds.add(enrollment.orgUnit);
3611
+ // }
3612
+ // });
3613
+ // });
3614
+ // } else {
3615
+ // if (response && response.instances) {
3616
+ // response?.instances?.forEach((tei: any) => {
3617
+ // tei.enrollments?.forEach((enrollment: any) => {
3618
+ // if (enrollment.program === programId) {
3619
+ // uniqueOrgUnitIds.add(enrollment?.orgUnit);
3620
+ // }
3621
+ // });
3622
+ // });
3623
+ // }
3624
+ // }
3625
+ // // If no unique orgUnits found, return immediately
3626
+ // if (uniqueOrgUnitIds.size === 0) {
3627
+ // return of({ ...response, orgUnitsMap: new Map<string, string>() });
3628
+ // }
3629
+ // // **Step 2:** Fetch orgUnit names in a single request
3630
+ // return this.fetchOrgUnits(Array.from(uniqueOrgUnitIds)).pipe(
3631
+ // map((orgUnitsMap: Map<string, string>) => ({
3632
+ // ...response,
3633
+ // orgUnitsMap, // Attach orgUnitId → orgUnitName map
3634
+ // }))
3635
+ // );
3636
+ // })
3637
+ // );
3638
+ // }
3567
3639
  getTrackedEntityInstances(programId, orgUnit, page, pageSize, filters = [], startDate, endDate, ouMode, filterRootOrgUnit, useOuModeWithOlderDHIS2Instance, filtersFromEvents = []) {
3568
3640
  const filterParams = buildFilters(filters);
3569
3641
  const filterParamsFromEvents = buildFiltersFromEvents(filtersFromEvents);
@@ -3576,13 +3648,17 @@ class LineListService {
3576
3648
  const ouModeIdentifier = ouMode && useOuModeWithOlderDHIS2Instance
3577
3649
  ? `&ouMode=${ouMode}`
3578
3650
  : `&orgUnitMode=${ouMode}`;
3579
- return this.httpClient
3580
- .get(`tracker/trackedEntities.json?program=${programId}&orgUnit=${orgUnit}${ouModeIdentifier}&page=${page}&pageSize=${pageSize}&fields=trackedEntity,orgUnit,attributes[*],enrollments[*]&totalPages=true&${filterParams}${dateFilter}&order=createdAt:desc`)
3581
- .pipe(switchMap((response) => {
3651
+ let baseUrl = '';
3652
+ if (filtersFromEvents.length === 0) {
3653
+ baseUrl = `tracker/trackedEntities.json?program=${programId}&orgUnit=${orgUnit}${ouModeIdentifier}&page=${page}&pageSize=${pageSize}&fields=trackedEntity,orgUnit,attributes[*],enrollments[*]&totalPages=true&${filterParams}${dateFilter}&order=createdAt:desc`;
3654
+ }
3655
+ else {
3656
+ baseUrl = `tracker/trackedEntities.json?program=${programId}&orgUnit=${orgUnit}${ouModeIdentifier}&fields=trackedEntity,orgUnit,attributes[*],enrollments[*]&${filterParams}${dateFilter}&order=createdAt:desc&paging=false`;
3657
+ }
3658
+ return this.httpClient.get(baseUrl).pipe(switchMap((response) => {
3582
3659
  if (filterRootOrgUnit) {
3583
3660
  response.trackedEntities = response.trackedEntities.filter((tei) => tei.orgUnit !== orgUnit);
3584
3661
  }
3585
- // **Step 1:** Extract unique orgUnits from enrollments
3586
3662
  const uniqueOrgUnitIds = new Set();
3587
3663
  if (response && response.trackedEntities) {
3588
3664
  response.trackedEntities.forEach((tei) => {
@@ -3594,28 +3670,51 @@ class LineListService {
3594
3670
  });
3595
3671
  }
3596
3672
  else {
3597
- if (response && response.instances) {
3598
- response?.instances?.forEach((tei) => {
3599
- tei.enrollments?.forEach((enrollment) => {
3600
- if (enrollment.program === programId) {
3601
- uniqueOrgUnitIds.add(enrollment?.orgUnit);
3602
- }
3603
- });
3673
+ response?.instances?.forEach((tei) => {
3674
+ tei.enrollments?.forEach((enrollment) => {
3675
+ if (enrollment.program === programId) {
3676
+ uniqueOrgUnitIds.add(enrollment.orgUnit);
3677
+ }
3604
3678
  });
3679
+ });
3680
+ }
3681
+ if (filtersFromEvents.length === 0) {
3682
+ if (uniqueOrgUnitIds.size === 0) {
3683
+ return of({ ...response, orgUnitsMap: new Map() });
3605
3684
  }
3685
+ return this.fetchOrgUnits(Array.from(uniqueOrgUnitIds)).pipe(map$1((orgUnitsMap) => ({
3686
+ ...response,
3687
+ orgUnitsMap,
3688
+ })));
3606
3689
  }
3607
- // If no unique orgUnits found, return immediately
3608
- if (uniqueOrgUnitIds.size === 0) {
3609
- return of({ ...response, orgUnitsMap: new Map() });
3690
+ // NEW LOGIC STARTS HERE if filtersFromEvents is present
3691
+ const filteredTrackedEntities = getFilteredTrackedEntites(response.trackedEntities, filtersFromEvents);
3692
+ const trackedEntityIds = filteredTrackedEntities
3693
+ .map((tei) => tei.trackedEntity)
3694
+ .join(',');
3695
+ if (!trackedEntityIds) {
3696
+ return of({
3697
+ trackedEntities: [],
3698
+ orgUnitsMap: new Map(),
3699
+ });
3610
3700
  }
3611
- // **Step 2:** Fetch orgUnit names in a single request
3612
- return this.fetchOrgUnits(Array.from(uniqueOrgUnitIds)).pipe(map$1((orgUnitsMap) => ({
3613
- ...response,
3614
- orgUnitsMap, // Attach orgUnitId → orgUnitName map
3615
- })));
3701
+ const refetchUrl = `tracker/trackedEntities.json?program=${programId}&orgUnit=${orgUnit}${ouModeIdentifier}&page=${page}&pageSize=${pageSize}&fields=trackedEntity,orgUnit,attributes[*],enrollments[*]&totalPages=true&${filterParams}${dateFilter}&order=createdAt:desc&trackedEntities=${trackedEntityIds}`;
3702
+ return this.httpClient.get(refetchUrl).pipe(switchMap((filteredResponse) => {
3703
+ const orgUnitIds = new Set();
3704
+ filteredResponse.trackedEntities?.forEach((tei) => {
3705
+ tei.enrollments?.forEach((enrollment) => {
3706
+ if (enrollment.program === programId) {
3707
+ orgUnitIds.add(enrollment.orgUnit);
3708
+ }
3709
+ });
3710
+ });
3711
+ return this.fetchOrgUnits(Array.from(orgUnitIds)).pipe(map$1((orgUnitsMap) => ({
3712
+ ...filteredResponse,
3713
+ orgUnitsMap,
3714
+ })));
3715
+ }));
3616
3716
  }));
3617
3717
  }
3618
- //filter=id:in:[id1,id2,id3]
3619
3718
  /**
3620
3719
  * Fetch orgUnit names for given orgUnit IDs
3621
3720
  */
@@ -3906,9 +4005,9 @@ const getTrackedEntityData = (response, programId, pager, isOptionSetNameVisible
3906
4005
  : null,
3907
4006
  sortOrder: attr.sortOrder,
3908
4007
  }));
3909
- if (filters) {
3910
- teis = getFilteredTrackedEntites(teis, filters);
3911
- }
4008
+ // if (filters) {
4009
+ // teis = getFilteredTrackedEntites(teis, filters);
4010
+ // }
3912
4011
  const allAttributes = new Set();
3913
4012
  teis.forEach((tei) => {
3914
4013
  const matchingEnrollment = tei.enrollments.find((enrollment) => enrollment.program === programId);
@@ -4344,6 +4443,22 @@ class LineListTableComponent extends ReactWrapperModule {
4344
4443
  return updatedFilters;
4345
4444
  });
4346
4445
  };
4446
+ //TODO: MERGE THIS WITH HANDLE INPUT CHANGE PUT A CHECK FOR IF ITS A SELECT FIELD TO USE EQ
4447
+ const handleInputChangeForSelectField = (key, value) => {
4448
+ setInputValues((prevValues) => ({
4449
+ ...prevValues,
4450
+ [key]: value ?? '',
4451
+ }));
4452
+ setAttributeFiltersState((prevFilters = []) => {
4453
+ // Remove old filter for this key
4454
+ const filteredFilters = prevFilters.filter((f) => f.attribute !== key);
4455
+ // Only add new filter if value is not empty
4456
+ const updatedFilters = value.trim()
4457
+ ? [...filteredFilters, { attribute: key, operator: 'eq', value }]
4458
+ : filteredFilters;
4459
+ return updatedFilters;
4460
+ });
4461
+ };
4347
4462
  const handleDateSelect = (key, selectedDate) => {
4348
4463
  const selectedDateString = selectedDate?.calendarDateString ?? ''; // Default to empty string if null
4349
4464
  // Update dateStates
@@ -4410,12 +4525,15 @@ class LineListTableComponent extends ReactWrapperModule {
4410
4525
  } },
4411
4526
  React__default.createElement(InputField$1, { key: "location",
4412
4527
  //label={orgUnitLabel}
4413
- label: orgUnitLabel ? orgUnitLabel : 'registering unit', value: selectedOrgUnit, clearable: true, onFocus: () => setHide(false), className: "custom-input", onChange: (event) => {
4528
+ label: orgUnitLabel ? orgUnitLabel : 'registering unit', value: selectedOrgUnit, onFocus: () => setHide(false), className: "custom-input", onChange: (event) => {
4414
4529
  setSelectedOrgUnit(event.value);
4415
4530
  setOrgUnitState(defaultOrgUnit);
4416
4531
  } }),
4417
4532
  React__default.createElement(CalendarInput, { label: "Start date:", calendar: "gregory", locale: "en-GB", timeZone: "Africa/Dar_es_Salaam", className: "custom-input", date: startDateState, onDateSelect: (selectedDate) => {
4418
- setStartDateState(selectedDate.calendarDateString);
4533
+ if (selectedDate?.calendarDateString) {
4534
+ setStartDateState(selectedDate.calendarDateString);
4535
+ }
4536
+ // setStartDateState(selectedDate.calendarDateString);
4419
4537
  } }),
4420
4538
  React__default.createElement(CalendarInput, { label: "End date:", calendar: "gregory", locale: "en-GB", timeZone: "Africa/Dar_es_Salaam", className: "custom-input", date: endDateState, onDateSelect: (selectedDate) => {
4421
4539
  setEndDateState(selectedDate.calendarDateString);
@@ -4432,7 +4550,7 @@ class LineListTableComponent extends ReactWrapperModule {
4432
4550
  ...prevValues,
4433
4551
  [key]: selected ?? '',
4434
4552
  }));
4435
- handleInputChange(key, selected ?? '');
4553
+ handleInputChangeForSelectField(key, selected ?? '');
4436
4554
  } }, (options.options ?? []).map((opt) => (React__default.createElement(SingleSelectOption, { key: opt.id, label: opt.name, value: opt.code })))));
4437
4555
  }
4438
4556
  // Fallback: default InputField
@@ -4538,11 +4656,11 @@ class LineListTableComponent extends ReactWrapperModule {
4538
4656
  this.render();
4539
4657
  }
4540
4658
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.1.8", ngImport: i0, type: LineListTableComponent, deps: null, target: i0.ɵɵFactoryTarget.Component }); }
4541
- static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.1.8", type: LineListTableComponent, isStandalone: false, selector: "ng-dhis2-ui-line-list", inputs: { programId: "programId", orgUnit: "orgUnit", programStageId: "programStageId", actionOptions: "actionOptions", actionOptionOrientation: "actionOptionOrientation", attributeFilters: "attributeFilters", useOuModeWithOlderDHIS2Instance: "useOuModeWithOlderDHIS2Instance", startDate: "startDate", endDate: "endDate", filters: "filters", ouMode: "ouMode", dispatchTeis: "dispatchTeis", isButtonLoading: "isButtonLoading", buttonLabel: "buttonLabel", buttonFilter: "buttonFilter", filterRootOrgUnit: "filterRootOrgUnit", showFilters: "showFilters", isOptionSetNameVisible: "isOptionSetNameVisible" }, outputs: { actionSelected: "actionSelected", approvalSelected: "approvalSelected", firstValue: "firstValue" }, usesInheritance: true, usesOnChanges: true, ngImport: i0, template: '<ng-content></ng-content>', isInline: true, styles: ["::ng-deep .custom-input{display:flex!important;gap:4px!important;align-items:center!important;border:1px solid #9fadba!important;border-radius:4px!important;margin:0;padding:0 0 0 8px;background-color:#fff!important}::ng-deep .custom-input div{margin:0!important}::ng-deep .custom-input label{font-size:12px;padding-right:0}::ng-deep .custom-input input{border:none!important;font-size:12px!important;display:flex;align-items:center;padding-left:4px;height:40px;outline:none!important;box-shadow:none!important}::ng-deep .custom-input input:focus{border:none!important;box-shadow:none!important}::ng-deep .custom-input label{color:gray!important;opacity:1}::ng-deep .table-top-toolbar{background-color:var(--colors-grey100)!important;color:var(--colors-grey900)!important}::ng-deep .custom-select-input{display:flex!important;gap:4px!important;align-items:center!important;border:1px solid #9fadba!important;border-radius:4px!important;margin:0;padding:0 0 0 8px;background-color:#fff!important}::ng-deep .custom-select-input div{margin:0!important}::ng-deep .custom-select-input [data-test=dhis2-uiwidgets-singleselectfield-label]{font-size:12px;color:gray!important}::ng-deep .custom-select-input [data-test=dhis2-uicore-select-input]{border:none!important;font-size:12px!important;display:flex;align-items:center;padding-left:4px;height:40px;outline:none!important;box-shadow:none!important}::ng-deep .custom-select-input [data-test=dhis2-uicore-select-input]:focus-within{box-shadow:none!important}::ng-deep .custom-select-input input:focus{border:none!important;box-shadow:none!important}\n"] }); }
4659
+ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.1.8", type: LineListTableComponent, isStandalone: false, selector: "ng-dhis2-ui-line-list", inputs: { programId: "programId", orgUnit: "orgUnit", programStageId: "programStageId", actionOptions: "actionOptions", actionOptionOrientation: "actionOptionOrientation", attributeFilters: "attributeFilters", useOuModeWithOlderDHIS2Instance: "useOuModeWithOlderDHIS2Instance", startDate: "startDate", endDate: "endDate", filters: "filters", ouMode: "ouMode", dispatchTeis: "dispatchTeis", isButtonLoading: "isButtonLoading", buttonLabel: "buttonLabel", buttonFilter: "buttonFilter", filterRootOrgUnit: "filterRootOrgUnit", showFilters: "showFilters", isOptionSetNameVisible: "isOptionSetNameVisible" }, outputs: { actionSelected: "actionSelected", approvalSelected: "approvalSelected", firstValue: "firstValue" }, usesInheritance: true, usesOnChanges: true, ngImport: i0, template: '<ng-content></ng-content>', isInline: true, styles: ["::ng-deep .custom-input{display:flex!important;gap:4px!important;align-items:center!important;border:1px solid #9fadba!important;border-radius:4px!important;margin:0;padding:0 0 0 8px;background-color:#fff!important}::ng-deep .custom-input div{margin:0!important}::ng-deep .custom-input label{font-size:12px;padding-right:0}::ng-deep .custom-input input{border:none!important;font-size:12px!important;display:flex;align-items:center;padding-left:4px;height:40px;outline:none!important;box-shadow:none!important}::ng-deep .custom-input input:focus{border:none!important;box-shadow:none!important}::ng-deep .custom-input [data-test=calendar-clear-button]{background-color:#f2f2f2!important;color:#870808!important;border-radius:6px!important;padding:4px 10px!important;font-size:14px!important}::ng-deep .custom-input [data-test=calendar-clear-button]:hover{background-color:#ddd}::ng-deep .custom-input label{color:gray!important;opacity:1}::ng-deep .table-top-toolbar{background-color:var(--colors-grey100)!important;color:var(--colors-grey900)!important}::ng-deep .custom-select-input{display:flex!important;gap:4px!important;align-items:center!important;border:1px solid #9fadba!important;border-radius:4px!important;margin:0;padding:0 0 0 8px;background-color:#fff!important}::ng-deep .custom-select-input div{margin:0!important}::ng-deep .custom-select-input [data-test=dhis2-uiwidgets-singleselectfield-label]{font-size:12px;color:gray!important}::ng-deep .custom-select-input [data-test=dhis2-uicore-select-input]{border:none!important;font-size:12px!important;display:flex;align-items:center;padding-left:4px;height:40px;outline:none!important;box-shadow:none!important}::ng-deep .custom-select-input [data-test=dhis2-uicore-select-input]:focus-within{box-shadow:none!important}::ng-deep .custom-select-input input:focus{border:none!important;box-shadow:none!important}\n"] }); }
4542
4660
  }
4543
4661
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.1.8", ngImport: i0, type: LineListTableComponent, decorators: [{
4544
4662
  type: Component,
4545
- args: [{ selector: 'ng-dhis2-ui-line-list', template: '<ng-content></ng-content>', standalone: false, styles: ["::ng-deep .custom-input{display:flex!important;gap:4px!important;align-items:center!important;border:1px solid #9fadba!important;border-radius:4px!important;margin:0;padding:0 0 0 8px;background-color:#fff!important}::ng-deep .custom-input div{margin:0!important}::ng-deep .custom-input label{font-size:12px;padding-right:0}::ng-deep .custom-input input{border:none!important;font-size:12px!important;display:flex;align-items:center;padding-left:4px;height:40px;outline:none!important;box-shadow:none!important}::ng-deep .custom-input input:focus{border:none!important;box-shadow:none!important}::ng-deep .custom-input label{color:gray!important;opacity:1}::ng-deep .table-top-toolbar{background-color:var(--colors-grey100)!important;color:var(--colors-grey900)!important}::ng-deep .custom-select-input{display:flex!important;gap:4px!important;align-items:center!important;border:1px solid #9fadba!important;border-radius:4px!important;margin:0;padding:0 0 0 8px;background-color:#fff!important}::ng-deep .custom-select-input div{margin:0!important}::ng-deep .custom-select-input [data-test=dhis2-uiwidgets-singleselectfield-label]{font-size:12px;color:gray!important}::ng-deep .custom-select-input [data-test=dhis2-uicore-select-input]{border:none!important;font-size:12px!important;display:flex;align-items:center;padding-left:4px;height:40px;outline:none!important;box-shadow:none!important}::ng-deep .custom-select-input [data-test=dhis2-uicore-select-input]:focus-within{box-shadow:none!important}::ng-deep .custom-select-input input:focus{border:none!important;box-shadow:none!important}\n"] }]
4663
+ args: [{ selector: 'ng-dhis2-ui-line-list', template: '<ng-content></ng-content>', standalone: false, styles: ["::ng-deep .custom-input{display:flex!important;gap:4px!important;align-items:center!important;border:1px solid #9fadba!important;border-radius:4px!important;margin:0;padding:0 0 0 8px;background-color:#fff!important}::ng-deep .custom-input div{margin:0!important}::ng-deep .custom-input label{font-size:12px;padding-right:0}::ng-deep .custom-input input{border:none!important;font-size:12px!important;display:flex;align-items:center;padding-left:4px;height:40px;outline:none!important;box-shadow:none!important}::ng-deep .custom-input input:focus{border:none!important;box-shadow:none!important}::ng-deep .custom-input [data-test=calendar-clear-button]{background-color:#f2f2f2!important;color:#870808!important;border-radius:6px!important;padding:4px 10px!important;font-size:14px!important}::ng-deep .custom-input [data-test=calendar-clear-button]:hover{background-color:#ddd}::ng-deep .custom-input label{color:gray!important;opacity:1}::ng-deep .table-top-toolbar{background-color:var(--colors-grey100)!important;color:var(--colors-grey900)!important}::ng-deep .custom-select-input{display:flex!important;gap:4px!important;align-items:center!important;border:1px solid #9fadba!important;border-radius:4px!important;margin:0;padding:0 0 0 8px;background-color:#fff!important}::ng-deep .custom-select-input div{margin:0!important}::ng-deep .custom-select-input [data-test=dhis2-uiwidgets-singleselectfield-label]{font-size:12px;color:gray!important}::ng-deep .custom-select-input [data-test=dhis2-uicore-select-input]{border:none!important;font-size:12px!important;display:flex;align-items:center;padding-left:4px;height:40px;outline:none!important;box-shadow:none!important}::ng-deep .custom-select-input [data-test=dhis2-uicore-select-input]:focus-within{box-shadow:none!important}::ng-deep .custom-select-input input:focus{border:none!important;box-shadow:none!important}\n"] }]
4546
4664
  }], propDecorators: { programId: [{
4547
4665
  type: Input
4548
4666
  }], orgUnit: [{