@iapps/ng-dhis2-ui 1.1.65 → 1.1.67

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.
@@ -3300,7 +3300,9 @@ class LineListService {
3300
3300
  this.httpClient = httpClient;
3301
3301
  }
3302
3302
  getProgramMetadata(programId) {
3303
- return this.httpClient.get(`programs/${programId}.json?fields=programType,programStages[id,name,programStageDataElements[dataElement[id,name]]],programTrackedEntityAttributes[*]`);
3303
+ return this.httpClient.get(`programs/${programId}.json?fields=programType,programStages[id,name,programStageDataElements[dataElement[id,name,shortName,formName,code,optionSetValue,valueType,
3304
+ optionSet[id,name,options[id,name,code]]]]],programTrackedEntityAttributes[*,trackedEntityAttribute[id,name,unique,generated,formName,code,optionSetValue
3305
+ ,valueType,optionSet[id,name,options[id,name,code]]]]`);
3304
3306
  }
3305
3307
  // private getTrackedEntityInstances(
3306
3308
  // programId: string,
@@ -3353,7 +3355,6 @@ class LineListService {
3353
3355
  // **Step 1:** Extract unique orgUnits from enrollments
3354
3356
  const uniqueOrgUnitIds = new Set();
3355
3357
  if (response && response.trackedEntities) {
3356
- console.log('THIS IS HERE', JSON.stringify(response));
3357
3358
  response.trackedEntities.forEach((tei) => {
3358
3359
  tei.enrollments?.forEach((enrollment) => {
3359
3360
  if (enrollment.program === programId) {
@@ -3470,25 +3471,151 @@ const getProgramStageData = (response, programStageId, pager) => {
3470
3471
  });
3471
3472
  return { columns: entityColumns, data: dataElementsData };
3472
3473
  };
3473
- const getTrackedEntityData = (response, programId, pager, filters) => {
3474
+ // export const getTrackedEntityData = (
3475
+ // response: LineListResponse,
3476
+ // programId: string,
3477
+ // pager: any,
3478
+ // isOptionSetNameVisible: boolean,
3479
+ // filters?: FilterConfig[]
3480
+ // ): {
3481
+ // columns: ColumnDefinition[];
3482
+ // data: TableRow[];
3483
+ // filteredEntityColumns: ColumnDefinition[];
3484
+ // } => {
3485
+ // let teis =
3486
+ // (response.data as TrackedEntityResponse)?.trackedEntities ??
3487
+ // (response.data as TrackedEntityResponse)?.instances ??
3488
+ // [];
3489
+ // const programMetaData = response.metadata.programTrackedEntityAttributes;
3490
+ // // //organisation units from metadata
3491
+ // // let orgUnitsFromMetaData = response.metadata.organisationUnits;
3492
+ // // //a Map to efficiently look up orgUnit names by ID
3493
+ // // const orgUnitMap = new Map<string, string>(
3494
+ // // orgUnitsFromMetaData.map((ou: { id: string; name: string }) => [
3495
+ // // ou.id,
3496
+ // // ou.name,
3497
+ // // ])
3498
+ // // );
3499
+ // const orgUnitMap = (response.data as TrackedEntityResponse).orgUnitsMap;
3500
+ // const mappedProgramMetadataAttributes = programMetaData.map((attr) => ({
3501
+ // displayInList: attr.displayInList,
3502
+ // searchable: attr.searchable,
3503
+ // id: attr.trackedEntityAttribute.id,
3504
+ // }));
3505
+ // const programAttributesMap = programMetaData.reduce(
3506
+ // (acc: { [key: string]: string }, attribute: any) => {
3507
+ // if (attribute.displayInList) {
3508
+ // acc[attribute.id] = attribute.displayName;
3509
+ // }
3510
+ // return acc;
3511
+ // },
3512
+ // {}
3513
+ // );
3514
+ // if (filters) {
3515
+ // teis = getFilteredTrackedEntites(teis, filters);
3516
+ // }
3517
+ // const allAttributes = new Set<string>();
3518
+ // teis.forEach((tei: any) => {
3519
+ // const matchingEnrollment = tei.enrollments.find(
3520
+ // (enrollment: any) => enrollment.program === programId
3521
+ // );
3522
+ // const attributes = matchingEnrollment
3523
+ // ? matchingEnrollment.attributes
3524
+ // : tei.attributes;
3525
+ // attributes.forEach((attr: any) => allAttributes.add(attr.attribute));
3526
+ // });
3527
+ // let entityColumns = Array.from(allAttributes).map((attrId: string) => {
3528
+ // const foundAttribute = teis
3529
+ // .flatMap((tei: any) => {
3530
+ // const matchingEnrollment = tei.enrollments.find(
3531
+ // (enrollment: any) => enrollment.program === programId
3532
+ // );
3533
+ // return matchingEnrollment
3534
+ // ? matchingEnrollment.attributes
3535
+ // : tei.attributes;
3536
+ // })
3537
+ // .find((attr: any) => attr.attribute === attrId);
3538
+ // return {
3539
+ // label: foundAttribute?.displayName || attrId,
3540
+ // key: attrId,
3541
+ // };
3542
+ // });
3543
+ // entityColumns = entityColumns.filter((column) => {
3544
+ // // Check if the column label is part of any value in programAttributesMap
3545
+ // return Object.values(programAttributesMap).some((value: string) =>
3546
+ // value.includes(column.label)
3547
+ // );
3548
+ // });
3549
+ // // Add orgUnit as the first column
3550
+ // entityColumns.unshift({
3551
+ // label: 'Location',
3552
+ // key: 'orgUnit',
3553
+ // });
3554
+ // const searchableAttributes = mappedProgramMetadataAttributes
3555
+ // .filter((attr) => attr.searchable && attr.displayInList)
3556
+ // .map((attr) => ({
3557
+ // // label: attr.trackedEntityAttribute.displayName,
3558
+ // key: attr.id,
3559
+ // }));
3560
+ // // Extract keys from searchableAttributes for quick lookup
3561
+ // const searchableKeys = new Set(searchableAttributes.map((attr) => attr.key));
3562
+ // // Filter entityColumns to keep only those whose key exists in searchableAttributes
3563
+ // const filteredEntityColumns = entityColumns.filter((column) =>
3564
+ // searchableKeys.has(column.key)
3565
+ // );
3566
+ // const attributesData = teis.map((tei: any, idx: number) => {
3567
+ // const row: TableRow = {
3568
+ // trackedEntityInstance: tei.trackedEntity,
3569
+ // index: (pager.page - 1) * pager.pageSize + idx + 1,
3570
+ // };
3571
+ // allAttributes.forEach((attrId: string) => (row[attrId] = ''));
3572
+ // const matchingEnrollment = tei.enrollments.find(
3573
+ // (enrollment: any) => enrollment.program === programId
3574
+ // );
3575
+ // const attributesToUse = matchingEnrollment
3576
+ // ? matchingEnrollment.attributes
3577
+ // : tei.attributes;
3578
+ // console.log('RESPONSE::: ', JSON.stringify(attributesToUse));
3579
+ // console.log('HERE WEARE', JSON.stringify(response.metadata));
3580
+ // if (isOptionSetNameVisible) {
3581
+ // attributesToUse.forEach(
3582
+ // (attr: any) => (row[attr.attribute] = attr.value)
3583
+ // );
3584
+ // } else {
3585
+ // attributesToUse.forEach(
3586
+ // (attr: any) => (row[attr.attribute] = attr.value)
3587
+ // );
3588
+ // }
3589
+ // //include orgUnit in the row for id access
3590
+ // row['orgUnitId'] = matchingEnrollment.orgUnit;
3591
+ // // Access the name of the orgUnit using the Map
3592
+ // // row['orgUnit'] = matchingEnrollment.orgUnitName;
3593
+ // row['orgUnit'] = orgUnitMap?.get(matchingEnrollment.orgUnit) || 'N/A';
3594
+ // // row['orgUnit'] =
3595
+ // // orgUnitMap && orgUnitMap[matchingEnrollment.orgUnit]
3596
+ // // ? orgUnitMap[matchingEnrollment.orgUnit]
3597
+ // // : 'N/A';
3598
+ // return row;
3599
+ // });
3600
+ // return {
3601
+ // columns: entityColumns,
3602
+ // data: attributesData,
3603
+ // filteredEntityColumns: filteredEntityColumns,
3604
+ // };
3605
+ // };
3606
+ const getTrackedEntityData = (response, programId, pager, isOptionSetNameVisible, filters) => {
3474
3607
  let teis = response.data?.trackedEntities ??
3475
3608
  response.data?.instances ??
3476
3609
  [];
3477
3610
  const programMetaData = response.metadata.programTrackedEntityAttributes;
3478
- // //organisation units from metadata
3479
- // let orgUnitsFromMetaData = response.metadata.organisationUnits;
3480
- // //a Map to efficiently look up orgUnit names by ID
3481
- // const orgUnitMap = new Map<string, string>(
3482
- // orgUnitsFromMetaData.map((ou: { id: string; name: string }) => [
3483
- // ou.id,
3484
- // ou.name,
3485
- // ])
3486
- // );
3487
3611
  const orgUnitMap = response.data.orgUnitsMap;
3488
3612
  const mappedProgramMetadataAttributes = programMetaData.map((attr) => ({
3489
3613
  displayInList: attr.displayInList,
3490
3614
  searchable: attr.searchable,
3491
3615
  id: attr.trackedEntityAttribute.id,
3616
+ optionSet: attr.trackedEntityAttribute.optionSetValue
3617
+ ? attr.trackedEntityAttribute.optionSet
3618
+ : null,
3492
3619
  }));
3493
3620
  const programAttributesMap = programMetaData.reduce((acc, attribute) => {
3494
3621
  if (attribute.displayInList) {
@@ -3522,7 +3649,6 @@ const getTrackedEntityData = (response, programId, pager, filters) => {
3522
3649
  };
3523
3650
  });
3524
3651
  entityColumns = entityColumns.filter((column) => {
3525
- // Check if the column label is part of any value in programAttributesMap
3526
3652
  return Object.values(programAttributesMap).some((value) => value.includes(column.label));
3527
3653
  });
3528
3654
  // Add orgUnit as the first column
@@ -3533,12 +3659,9 @@ const getTrackedEntityData = (response, programId, pager, filters) => {
3533
3659
  const searchableAttributes = mappedProgramMetadataAttributes
3534
3660
  .filter((attr) => attr.searchable && attr.displayInList)
3535
3661
  .map((attr) => ({
3536
- // label: attr.trackedEntityAttribute.displayName,
3537
3662
  key: attr.id,
3538
3663
  }));
3539
- // Extract keys from searchableAttributes for quick lookup
3540
3664
  const searchableKeys = new Set(searchableAttributes.map((attr) => attr.key));
3541
- // Filter entityColumns to keep only those whose key exists in searchableAttributes
3542
3665
  const filteredEntityColumns = entityColumns.filter((column) => searchableKeys.has(column.key));
3543
3666
  const attributesData = teis.map((tei, idx) => {
3544
3667
  const row = {
@@ -3550,16 +3673,27 @@ const getTrackedEntityData = (response, programId, pager, filters) => {
3550
3673
  const attributesToUse = matchingEnrollment
3551
3674
  ? matchingEnrollment.attributes
3552
3675
  : tei.attributes;
3553
- attributesToUse.forEach((attr) => (row[attr.attribute] = attr.value));
3554
- //include orgUnit in the row for id access
3676
+ // If option set names are visible, transform the attribute values
3677
+ if (isOptionSetNameVisible) {
3678
+ attributesToUse.forEach((attr) => {
3679
+ const attributeMeta = programMetaData.find((metadata) => metadata.trackedEntityAttribute.id === attr.attribute);
3680
+ // Check if the attribute has an option set and map value to option name
3681
+ if (attributeMeta?.trackedEntityAttribute.optionSetValue) {
3682
+ const optionSet = attributeMeta?.trackedEntityAttribute?.optionSet;
3683
+ const option = optionSet?.options?.find((option) => option.code === attr.value);
3684
+ row[attr.attribute] = option ? option.name : attr.value;
3685
+ }
3686
+ else {
3687
+ row[attr.attribute] = attr.value;
3688
+ }
3689
+ });
3690
+ }
3691
+ else {
3692
+ attributesToUse.forEach((attr) => (row[attr.attribute] = attr.value));
3693
+ }
3694
+ // Include orgUnit in the row for id access
3555
3695
  row['orgUnitId'] = matchingEnrollment.orgUnit;
3556
- // Access the name of the orgUnit using the Map
3557
- // row['orgUnit'] = matchingEnrollment.orgUnitName;
3558
3696
  row['orgUnit'] = orgUnitMap?.get(matchingEnrollment.orgUnit) || 'N/A';
3559
- // row['orgUnit'] =
3560
- // orgUnitMap && orgUnitMap[matchingEnrollment.orgUnit]
3561
- // ? orgUnitMap[matchingEnrollment.orgUnit]
3562
- // : 'N/A';
3563
3697
  return row;
3564
3698
  });
3565
3699
  return {
@@ -3568,7 +3702,47 @@ const getTrackedEntityData = (response, programId, pager, filters) => {
3568
3702
  filteredEntityColumns: filteredEntityColumns,
3569
3703
  };
3570
3704
  };
3571
- const getEventData = (response, pager) => {
3705
+ // export const getEventData = (
3706
+ // response: LineListResponse,
3707
+ // pager: any,
3708
+ // isOptionSetNameVisible: boolean
3709
+ // ): { columns: ColumnDefinition[]; data: TableRow[] } => {
3710
+ // const events = (response.data as EventsResponse).events;
3711
+ // const uniqueDataElements = new Set<string>();
3712
+ // events?.forEach((event: any) => {
3713
+ // event?.dataValues.forEach((dv: any) =>
3714
+ // uniqueDataElements.add(dv.dataElement)
3715
+ // );
3716
+ // });
3717
+ // const entityColumns = Array.from(uniqueDataElements).map(
3718
+ // (dataElement: string) => ({
3719
+ // label:
3720
+ // response.metadata.programStages[0].programStageDataElements.find(
3721
+ // (psde: any) => psde.dataElement.id === dataElement
3722
+ // )?.dataElement.name || dataElement,
3723
+ // key: dataElement,
3724
+ // })
3725
+ // );
3726
+ // const dataElementsData = events.map((event: any, idx: number) => {
3727
+ // const row: TableRow = {
3728
+ // event: event.event,
3729
+ // index: (pager.page - 1) * pager.pageSize + idx + 1,
3730
+ // };
3731
+ // uniqueDataElements.forEach(
3732
+ // (dataElement: string) => (row[dataElement] = '')
3733
+ // );
3734
+ // event.dataValues.forEach((dv: any) => {
3735
+ // if (isOptionSetNameVisible) {
3736
+ // return (row[dv.dataElement] = dv.value)
3737
+ // } else {
3738
+ // return (row[dv.dataElement] = dv.value)
3739
+ // }
3740
+ // });
3741
+ // return row;
3742
+ // });
3743
+ // return { columns: entityColumns, data: dataElementsData };
3744
+ // };
3745
+ const getEventData = (response, pager, isOptionSetNameVisible) => {
3572
3746
  const events = response.data.events;
3573
3747
  const uniqueDataElements = new Set();
3574
3748
  events?.forEach((event) => {
@@ -3584,7 +3758,28 @@ const getEventData = (response, pager) => {
3584
3758
  index: (pager.page - 1) * pager.pageSize + idx + 1,
3585
3759
  };
3586
3760
  uniqueDataElements.forEach((dataElement) => (row[dataElement] = ''));
3587
- event.dataValues.forEach((dv) => (row[dv.dataElement] = dv.value));
3761
+ event.dataValues.forEach((dv) => {
3762
+ if (isOptionSetNameVisible && dv.optionSetValue) {
3763
+ const dataElementMetadata = response.metadata.programStages
3764
+ .flatMap((programStage) => programStage.programStageDataElements)
3765
+ .find((psde) => psde.dataElement.id === dv.dataElement)?.dataElement.optionSet;
3766
+ if (dataElementMetadata && dataElementMetadata.options) {
3767
+ const matchingOption = dataElementMetadata.options.find((option) => option.code === dv.value);
3768
+ if (matchingOption) {
3769
+ row[dv.dataElement] = matchingOption.name;
3770
+ }
3771
+ else {
3772
+ row[dv.dataElement] = dv.value;
3773
+ }
3774
+ }
3775
+ else {
3776
+ row[dv.dataElement] = dv.value;
3777
+ }
3778
+ }
3779
+ else {
3780
+ row[dv.dataElement] = dv.value;
3781
+ }
3782
+ });
3588
3783
  return row;
3589
3784
  });
3590
3785
  return { columns: entityColumns, data: dataElementsData };
@@ -3795,6 +3990,7 @@ class LineListTableComponent extends ReactWrapperModule {
3795
3990
  this.firstValue = new EventEmitter();
3796
3991
  this.filterRootOrgUnit = false;
3797
3992
  this.showFilters = false;
3993
+ this.isOptionSetNameVisible = false;
3798
3994
  this.setReactStateUpdaters = (updaters) => {
3799
3995
  this.reactStateUpdaters = updaters;
3800
3996
  };
@@ -3810,6 +4006,7 @@ class LineListTableComponent extends ReactWrapperModule {
3810
4006
  });
3811
4007
  const paginationRef = useRef(null);
3812
4008
  const [programIdState, setProgramIdState] = useState(this.programId);
4009
+ const [isOptionSetNameVisibleState, setOptionSetNameVisible] = useState(this.isOptionSetNameVisible);
3813
4010
  const [orgUnitState, setOrgUnitState] = useState(this.orgUnit);
3814
4011
  const [programStageIdState, setProgramStageIdState] = useState(this.programStageId);
3815
4012
  const [attributeFiltersState, setAttributeFiltersState] = useState(this.attributeFilters);
@@ -3838,6 +4035,7 @@ class LineListTableComponent extends ReactWrapperModule {
3838
4035
  setStartDateState,
3839
4036
  setEndDateState,
3840
4037
  setIsButtonLoading,
4038
+ setOptionSetNameVisible,
3841
4039
  });
3842
4040
  useEffect(() => {
3843
4041
  this.setReactStateUpdaters?.(updateRefs.current);
@@ -3866,7 +4064,7 @@ class LineListTableComponent extends ReactWrapperModule {
3866
4064
  total: responseData.total,
3867
4065
  pageCount: responseData.pageCount,
3868
4066
  };
3869
- const { columns, data, filteredEntityColumns } = getTrackedEntityData(response, this.programId, pager, this.filters);
4067
+ const { columns, data, filteredEntityColumns } = getTrackedEntityData(response, this.programId, pager, this.isOptionSetNameVisible, this.filters);
3870
4068
  entityColumns = columns;
3871
4069
  entityData = data;
3872
4070
  //TODO: Should be done on the parent
@@ -3891,7 +4089,7 @@ class LineListTableComponent extends ReactWrapperModule {
3891
4089
  }
3892
4090
  else {
3893
4091
  responsePager = response.data.pager;
3894
- const { columns, data } = getEventData(response, pager);
4092
+ const { columns, data } = getEventData(response, pager, this.isOptionSetNameVisible);
3895
4093
  entityColumns = columns;
3896
4094
  entityData = data;
3897
4095
  }
@@ -3910,6 +4108,7 @@ class LineListTableComponent extends ReactWrapperModule {
3910
4108
  endDateState,
3911
4109
  pager.page,
3912
4110
  pager.pageSize,
4111
+ isOptionSetNameVisibleState,
3913
4112
  ]);
3914
4113
  const getDropdownOptions = (row) => {
3915
4114
  return (this.actionOptions || []).map((option) => ({
@@ -4076,6 +4275,9 @@ class LineListTableComponent extends ReactWrapperModule {
4076
4275
  if (changes['programId']) {
4077
4276
  this.reactStateUpdaters.setProgramIdState(this.programId);
4078
4277
  }
4278
+ if (changes['isOptionSetNameVisible']) {
4279
+ this.reactStateUpdaters.setOptionSetNameVisible(this.isOptionSetNameVisible);
4280
+ }
4079
4281
  if (changes['orgUnit']) {
4080
4282
  this.reactStateUpdaters.setOrgUnitState(this.orgUnit);
4081
4283
  }
@@ -4104,7 +4306,7 @@ class LineListTableComponent extends ReactWrapperModule {
4104
4306
  this.render();
4105
4307
  }
4106
4308
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.1.8", ngImport: i0, type: LineListTableComponent, deps: null, target: i0.ɵɵFactoryTarget.Component }); }
4107
- 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", attributeFilters: "attributeFilters", useOuModeWithOlderDHIS2Instance: "useOuModeWithOlderDHIS2Instance", startDate: "startDate", endDate: "endDate", filters: "filters", ouMode: "ouMode", dispatchTeis: "dispatchTeis", isButtonLoading: "isButtonLoading", buttonLabel: "buttonLabel", buttonFilter: "buttonFilter", filterRootOrgUnit: "filterRootOrgUnit", showFilters: "showFilters" }, 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;padding-left:16px}::ng-deep .custom-input input{border:none!important;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}\n"] }); }
4309
+ 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", 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;padding-left:16px}::ng-deep .custom-input input{border:none!important;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}\n"] }); }
4108
4310
  }
4109
4311
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.1.8", ngImport: i0, type: LineListTableComponent, decorators: [{
4110
4312
  type: Component,
@@ -4147,6 +4349,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.1.8", ngImpor
4147
4349
  type: Input
4148
4350
  }], showFilters: [{
4149
4351
  type: Input
4352
+ }], isOptionSetNameVisible: [{
4353
+ type: Input
4150
4354
  }] } });
4151
4355
 
4152
4356
  class LineListModule {