@iapps/ng-dhis2-ui 1.1.79 → 1.2.0
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.
- package/fesm2022/iapps-ng-dhis2-ui.mjs +431 -1114
- package/fesm2022/iapps-ng-dhis2-ui.mjs.map +1 -1
- package/lib/modules/form/utils/field-type.util.d.ts +1 -1
- package/lib/modules/form/utils/field.util.d.ts +1 -1
- package/lib/modules/line-list/components/orgUnitSelector.d.ts +2 -0
- package/lib/modules/line-list/components/table/TableBody.d.ts +2 -0
- package/lib/modules/line-list/components/table/filterToolbar.d.ts +2 -0
- package/lib/modules/line-list/components/table/lineListTable.d.ts +2 -0
- package/lib/modules/line-list/components/table/pagination.d.ts +8 -0
- package/lib/modules/line-list/components/table/tableCell.d.ts +5 -0
- package/lib/modules/line-list/components/table/tableFooter.d.ts +2 -0
- package/lib/modules/line-list/components/table/tableHeader.d.ts +4 -0
- package/lib/modules/line-list/components/table/tableRow.d.ts +2 -0
- package/lib/modules/line-list/containers/line-list.component.d.ts +3 -6
- package/lib/modules/line-list/models/line-list.models.d.ts +15 -23
- package/lib/modules/line-list/services/line-list.service.d.ts +3 -11
- package/lib/modules/line-list/utils/event-table-table-util.d.ts +10 -0
- package/lib/modules/line-list/utils/tei-table-data-utils.d.ts +9 -0
- package/lib/modules/program-entry-form/models/program-entry-form-metadata.d.ts +2 -1
- package/package.json +1 -1
- package/lib/modules/line-list/utils/filter-builder.d.ts +0 -7
- package/lib/modules/line-list/utils/line-list-utils.d.ts +0 -17
|
@@ -8,7 +8,7 @@ import { NgxDhis2HttpClientService } from '@iapps/ngx-dhis2-http-client';
|
|
|
8
8
|
import * as React from 'react';
|
|
9
9
|
import React__default, { useState, useCallback, useRef, useEffect, createContext, useContext, useMemo } from 'react';
|
|
10
10
|
import * as ReactDOM from 'react-dom/client';
|
|
11
|
-
import { catchError, of, map, zip, firstValueFrom,
|
|
11
|
+
import { catchError, of, map, zip, firstValueFrom, filter, take, Subject, takeUntil } from 'rxjs';
|
|
12
12
|
import i18n from '@dhis2/d2-i18n';
|
|
13
13
|
import { colors, theme, spacers } from '@dhis2/ui-constants';
|
|
14
14
|
import PropTypes from 'prop-types';
|
|
@@ -25,16 +25,16 @@ import { Layer } from '@dhis2-ui/layer';
|
|
|
25
25
|
import { CircularLoader } from '@dhis2-ui/loader';
|
|
26
26
|
import { MenuItem, MenuDivider } from '@dhis2-ui/menu';
|
|
27
27
|
import parse from 'html-react-parser';
|
|
28
|
-
import { Button as Button$1, IconDimensionData16, IconClock16, IconDimensionOrgUnit16, spacers as spacers$1, colors as colors$1, IconEdit16, theme as theme$1, Tooltip, IconChevronRight16, SingleSelectField, SingleSelectOption, InputField as InputField$1, TabBar, Tab, Transfer, Modal as Modal$1, ModalTitle as ModalTitle$1, ModalContent as ModalContent$1, ModalActions as ModalActions$1, ButtonStrip as ButtonStrip$1, Checkbox, OrganisationUnitTree, MultiSelect, MultiSelectOption, IconWarningFilled16, Layer as Layer$1, Popper, FlyoutMenu, MenuItem as MenuItem$1, IconMore24,
|
|
28
|
+
import { Button as Button$1, IconDimensionData16, IconClock16, IconDimensionOrgUnit16, spacers as spacers$1, colors as colors$1, IconEdit16, theme as theme$1, Tooltip, IconChevronRight16, SingleSelectField, SingleSelectOption, InputField as InputField$1, TabBar, Tab, Transfer, Modal as Modal$1, ModalTitle as ModalTitle$1, ModalContent as ModalContent$1, ModalActions as ModalActions$1, ButtonStrip as ButtonStrip$1, Checkbox, OrganisationUnitTree, MultiSelect, MultiSelectOption, IconWarningFilled16, DataTableToolbar, CalendarInput, TableHead, DataTableRow, DataTableColumnHeader, Layer as Layer$1, Popper, FlyoutMenu, MenuItem as MenuItem$1, IconMore24, DataTableCell, TableBody as TableBody$1, Pagination as Pagination$1, TableFoot, DataTable, CircularLoader as CircularLoader$1, Chip, FileInputField, FileListItem, MultiSelectField, TextAreaField } from '@dhis2/ui';
|
|
29
29
|
import { isObject, isString, debounce, sortBy, isArray, find, camelCase, flatten, isUndefined, head, isEmpty } from 'lodash';
|
|
30
30
|
import cx from 'classnames';
|
|
31
31
|
import { getNowInCalendar, generateFixedPeriods } from '@dhis2/multi-calendar-dates';
|
|
32
|
-
import {
|
|
33
|
-
import { parse as parse$1
|
|
32
|
+
import { map as map$1 } from 'rxjs/operators';
|
|
33
|
+
import { format, parse as parse$1 } from 'date-fns';
|
|
34
|
+
import { Pager, DataOrderCriteria, DataQueryFilter, DataFilterCondition, ProgramRuleEngine } from '@iapps/d2-web-sdk';
|
|
34
35
|
import * as i2 from '@angular/forms';
|
|
35
36
|
import { Validators, UntypedFormControl, UntypedFormGroup, FormControl, FormGroup, ReactiveFormsModule } from '@angular/forms';
|
|
36
37
|
import { toObservable } from '@angular/core/rxjs-interop';
|
|
37
|
-
import { DataQueryFilter, DataFilterCondition, ProgramRuleEngine } from '@iapps/d2-web-sdk';
|
|
38
38
|
import moment from 'moment';
|
|
39
39
|
|
|
40
40
|
class SharedDhis2UiModule {
|
|
@@ -3106,6 +3106,196 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.1.8", ngImpor
|
|
|
3106
3106
|
// Use of this source code is governed by a BSD-style
|
|
3107
3107
|
// license that can be found in the LICENSE file.
|
|
3108
3108
|
|
|
3109
|
+
class LineListService {
|
|
3110
|
+
constructor(httpClient) {
|
|
3111
|
+
this.httpClient = httpClient;
|
|
3112
|
+
}
|
|
3113
|
+
/**
|
|
3114
|
+
* Fetch orgUnit names for given orgUnit IDs
|
|
3115
|
+
*/
|
|
3116
|
+
fetchOrgUnits(orgUnitIds) {
|
|
3117
|
+
const idsQuery = `filter=id:in:[${orgUnitIds}]`;
|
|
3118
|
+
return this.httpClient
|
|
3119
|
+
.get(`organisationUnits.json?fields=id,name&paging=false&${idsQuery}`)
|
|
3120
|
+
.pipe(map$1((response) => {
|
|
3121
|
+
const orgUnitsMap = new Map();
|
|
3122
|
+
response.organisationUnits.forEach((orgUnit) => {
|
|
3123
|
+
orgUnitsMap.set(orgUnit.id, orgUnit.name);
|
|
3124
|
+
});
|
|
3125
|
+
return orgUnitsMap;
|
|
3126
|
+
}));
|
|
3127
|
+
}
|
|
3128
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.1.8", ngImport: i0, type: LineListService, deps: [{ token: i1.NgxDhis2HttpClientService }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
3129
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.1.8", ngImport: i0, type: LineListService }); }
|
|
3130
|
+
}
|
|
3131
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.1.8", ngImport: i0, type: LineListService, decorators: [{
|
|
3132
|
+
type: Injectable
|
|
3133
|
+
}], ctorParameters: () => [{ type: i1.NgxDhis2HttpClientService }] });
|
|
3134
|
+
|
|
3135
|
+
const getTrackedEntityTableData = (response, programId, pager, metaData) => {
|
|
3136
|
+
let teisRaw = response.data
|
|
3137
|
+
.trackedEntityInstances;
|
|
3138
|
+
const teis = Array.isArray(teisRaw)
|
|
3139
|
+
? teisRaw
|
|
3140
|
+
: [teisRaw];
|
|
3141
|
+
const programTrackedEntityAttributes = metaData.programTrackedEntityAttributes;
|
|
3142
|
+
const orgUnitLabel = metaData.orgUnitLabel;
|
|
3143
|
+
const orgUnitMap = response.data
|
|
3144
|
+
.orgUnitsMap;
|
|
3145
|
+
const attributeColumns = metaData.displayInListTrackedEntityAttributes
|
|
3146
|
+
.sort((a, b) => a.sortOrder - b.sortOrder)
|
|
3147
|
+
.map((attr) => ({
|
|
3148
|
+
label: attr.name,
|
|
3149
|
+
key: attr.id,
|
|
3150
|
+
}));
|
|
3151
|
+
const dataElementColumns = metaData.displayInListDataElements
|
|
3152
|
+
.sort((a, b) => a.sortOrder - b.sortOrder)
|
|
3153
|
+
.map((element) => ({
|
|
3154
|
+
label: element.name,
|
|
3155
|
+
key: element.id,
|
|
3156
|
+
}));
|
|
3157
|
+
const dataElementOptions = metaData.displayInListDataElements.map((element) => ({
|
|
3158
|
+
id: element.id,
|
|
3159
|
+
options: element.optionSet?.options.map((opt) => ({
|
|
3160
|
+
name: opt.name,
|
|
3161
|
+
color: opt.style?.color,
|
|
3162
|
+
})),
|
|
3163
|
+
}));
|
|
3164
|
+
const tableColumns = [
|
|
3165
|
+
{
|
|
3166
|
+
label: orgUnitLabel || 'registering unit',
|
|
3167
|
+
key: 'orgUnit',
|
|
3168
|
+
},
|
|
3169
|
+
...attributeColumns,
|
|
3170
|
+
...dataElementColumns,
|
|
3171
|
+
];
|
|
3172
|
+
const tableFilters = metaData.searchableTrackedEntityAttributes
|
|
3173
|
+
.sort((a, b) => a.sortOrder - b.sortOrder)
|
|
3174
|
+
.map((attr) => ({
|
|
3175
|
+
label: attr.name,
|
|
3176
|
+
key: attr.id,
|
|
3177
|
+
valueType: attr.valueType,
|
|
3178
|
+
options: attr.optionSet ?? undefined,
|
|
3179
|
+
}));
|
|
3180
|
+
const tableData = teis.map((tei, idx) => {
|
|
3181
|
+
const row = {
|
|
3182
|
+
trackedEntityInstance: { value: tei.trackedEntity },
|
|
3183
|
+
index: { value: (pager.page - 1) * pager.pageSize + idx + 1 },
|
|
3184
|
+
};
|
|
3185
|
+
const matchingEnrollment = tei.latestEnrollment;
|
|
3186
|
+
//let disaplayInListAttributes = metaData.displayInListTrackedEntityAttributes;
|
|
3187
|
+
let attributesData = matchingEnrollment.attributes;
|
|
3188
|
+
let dataElementsData = matchingEnrollment.events.flatMap((event) => event.dataValues);
|
|
3189
|
+
attributesData = attributesData.map((attr) => {
|
|
3190
|
+
if (attr?.valueType?.toLowerCase() === 'date') {
|
|
3191
|
+
try {
|
|
3192
|
+
return {
|
|
3193
|
+
...attr,
|
|
3194
|
+
value: format(parse$1(attr.value, 'yyyy-MM-dd', new Date()), 'dd-MM-yyyy'),
|
|
3195
|
+
};
|
|
3196
|
+
}
|
|
3197
|
+
catch {
|
|
3198
|
+
return { ...attr }; // Leave value as is on parse failure
|
|
3199
|
+
}
|
|
3200
|
+
}
|
|
3201
|
+
return attr;
|
|
3202
|
+
});
|
|
3203
|
+
attributesData.forEach((attr) => {
|
|
3204
|
+
row[attr.attribute] = { value: attr.value };
|
|
3205
|
+
});
|
|
3206
|
+
dataElementsData.forEach((element) => {
|
|
3207
|
+
// Find the matching data element in dataElementOptions by ID
|
|
3208
|
+
const dataElementOption = dataElementOptions.find((deo) => deo.id === element.dataElement);
|
|
3209
|
+
// find a matching option within that data element's options
|
|
3210
|
+
const matchingOption = dataElementOption?.options?.find((opt) => opt.name === element.value);
|
|
3211
|
+
// Build the row entry with value and optionally style
|
|
3212
|
+
if (matchingOption) {
|
|
3213
|
+
row[element.dataElement] = {
|
|
3214
|
+
value: element.value,
|
|
3215
|
+
style: matchingOption.color,
|
|
3216
|
+
};
|
|
3217
|
+
}
|
|
3218
|
+
else {
|
|
3219
|
+
row[element.dataElement] = {
|
|
3220
|
+
value: element.value,
|
|
3221
|
+
};
|
|
3222
|
+
}
|
|
3223
|
+
});
|
|
3224
|
+
// Include orgUnit in the row for id access with style
|
|
3225
|
+
row['orgUnitId'] = { value: matchingEnrollment.orgUnit };
|
|
3226
|
+
row['orgUnit'] = {
|
|
3227
|
+
value: orgUnitMap?.get(matchingEnrollment.orgUnit) || '-',
|
|
3228
|
+
};
|
|
3229
|
+
return row;
|
|
3230
|
+
});
|
|
3231
|
+
return {
|
|
3232
|
+
columns: tableColumns,
|
|
3233
|
+
data: tableData,
|
|
3234
|
+
filteredEntityColumns: tableFilters,
|
|
3235
|
+
orgUnitLabel: orgUnitLabel,
|
|
3236
|
+
};
|
|
3237
|
+
};
|
|
3238
|
+
const addActionsColumn = (columns, actionOptions) => {
|
|
3239
|
+
return [
|
|
3240
|
+
...columns,
|
|
3241
|
+
...(actionOptions && actionOptions.length > 0
|
|
3242
|
+
? [{ label: 'Actions', key: 'actions' }]
|
|
3243
|
+
: []),
|
|
3244
|
+
];
|
|
3245
|
+
};
|
|
3246
|
+
|
|
3247
|
+
const FilterToolbar = ({ orgUnitLabel, selectedOrgUnit, setSelectedOrgUnit, setOrgUnitState, defaultOrgUnit, setHide, startDateState, setStartDateState, endDateState, setEndDateState, visibleFilters, dateStates, inputValues, setInputValues, handleInputChange, handleInputChangeForSelectField, handleDateSelect, prevValue, setPrevValue, showAllFilters, setShowAllFilters, }) => (React__default.createElement(DataTableToolbar, { className: "table-top-toolbar" },
|
|
3248
|
+
React__default.createElement("div", { style: {
|
|
3249
|
+
display: 'flex',
|
|
3250
|
+
alignItems: 'center',
|
|
3251
|
+
gap: '10px',
|
|
3252
|
+
flexWrap: 'wrap',
|
|
3253
|
+
} },
|
|
3254
|
+
React__default.createElement(InputField$1, { key: "location", label: orgUnitLabel ? orgUnitLabel : 'registering unit:', value: selectedOrgUnit, onFocus: () => setHide(false), className: "custom-input", clearable: true, onChange: (event) => {
|
|
3255
|
+
setSelectedOrgUnit(event.value);
|
|
3256
|
+
setOrgUnitState(defaultOrgUnit);
|
|
3257
|
+
} }),
|
|
3258
|
+
React__default.createElement(CalendarInput, { label: "Start date:", calendar: "gregory", locale: "en-GB", timeZone: "Africa/Dar_es_Salaam", className: "custom-input", date: startDateState, onDateSelect: (selectedDate) => {
|
|
3259
|
+
setStartDateState(selectedDate.calendarDateString);
|
|
3260
|
+
} }),
|
|
3261
|
+
React__default.createElement(CalendarInput, { label: "End date:", calendar: "gregory", locale: "en-GB", timeZone: "Africa/Dar_es_Salaam", className: "custom-input", date: endDateState, onDateSelect: (selectedDate) => {
|
|
3262
|
+
setEndDateState(selectedDate.calendarDateString);
|
|
3263
|
+
} }),
|
|
3264
|
+
(visibleFilters ?? []).map(({ label, key, valueType, options }) => {
|
|
3265
|
+
if (valueType === 'DATE') {
|
|
3266
|
+
return (React__default.createElement(CalendarInput, { key: key, label: `${label}:`, calendar: "gregory", locale: "en-GB", timeZone: "Africa/Dar_es_Salaam", className: "custom-input", date: dateStates[key] || '', onDateSelect: (selectedDate) => handleDateSelect(key, selectedDate) }));
|
|
3267
|
+
}
|
|
3268
|
+
if (options && options.options.length > 0) {
|
|
3269
|
+
return (React__default.createElement(SingleSelectField, { key: key, label: `${label}:`, selected: inputValues[key] || '', className: "custom-select-input", clearable: true, onChange: ({ selected }) => {
|
|
3270
|
+
setInputValues((prevValues) => ({
|
|
3271
|
+
...prevValues,
|
|
3272
|
+
[key]: selected ?? '',
|
|
3273
|
+
}));
|
|
3274
|
+
handleInputChangeForSelectField(key, selected ?? '');
|
|
3275
|
+
} }, (options.options ?? []).map((opt) => (React__default.createElement(SingleSelectOption, { key: opt.id, label: opt.name, value: opt.code })))));
|
|
3276
|
+
}
|
|
3277
|
+
return (React__default.createElement(InputField$1, { key: key, label: `${label}:`, className: "custom-input", value: inputValues[key] || '', clearable: true, onChange: (e) => {
|
|
3278
|
+
const currentValue = 'target' in e ? e.target.value : e.value ?? '';
|
|
3279
|
+
setInputValues((prevValues) => ({
|
|
3280
|
+
...prevValues,
|
|
3281
|
+
[key]: currentValue,
|
|
3282
|
+
}));
|
|
3283
|
+
if (currentValue === '') {
|
|
3284
|
+
handleInputChange(key, '');
|
|
3285
|
+
}
|
|
3286
|
+
}, onBlur: (e) => {
|
|
3287
|
+
const currentValue = 'target' in e ? e.target.value : e.value ?? '';
|
|
3288
|
+
if (currentValue !== '' && currentValue !== prevValue) {
|
|
3289
|
+
handleInputChange(key, currentValue);
|
|
3290
|
+
setPrevValue(currentValue);
|
|
3291
|
+
}
|
|
3292
|
+
} }));
|
|
3293
|
+
}),
|
|
3294
|
+
React__default.createElement(Button$1, { onClick: () => setShowAllFilters(!showAllFilters) }, showAllFilters ? 'Less Filters' : 'More Filters'))));
|
|
3295
|
+
|
|
3296
|
+
const TableHeader = ({ columns }) => (React__default.createElement(TableHead, null,
|
|
3297
|
+
React__default.createElement(DataTableRow, null, columns.map((col) => (React__default.createElement(DataTableColumnHeader, { key: col.key }, col.label))))));
|
|
3298
|
+
|
|
3109
3299
|
const dropdownStyles$1 = {
|
|
3110
3300
|
layer: {
|
|
3111
3301
|
zIndex: '1 !important',
|
|
@@ -3242,6 +3432,68 @@ const DataTableActions = (props) => {
|
|
|
3242
3432
|
// Use of this source code is governed by a BSD-style
|
|
3243
3433
|
// license that can be found in the LICENSE file.
|
|
3244
3434
|
|
|
3435
|
+
const TableCell = ({ cell, getTextColorFromBackGround, }) => {
|
|
3436
|
+
if (cell?.style && cell?.style !== 'default-value') {
|
|
3437
|
+
return (React__default.createElement(DataTableCell, null,
|
|
3438
|
+
React__default.createElement("div", { style: { display: 'flex', justifyContent: 'center' } },
|
|
3439
|
+
React__default.createElement("span", { style: {
|
|
3440
|
+
backgroundColor: cell.style,
|
|
3441
|
+
display: 'inline-flex',
|
|
3442
|
+
alignItems: 'center',
|
|
3443
|
+
padding: 4,
|
|
3444
|
+
borderRadius: 3,
|
|
3445
|
+
fontSize: 12,
|
|
3446
|
+
color: getTextColorFromBackGround(cell.style),
|
|
3447
|
+
} }, cell.value))));
|
|
3448
|
+
}
|
|
3449
|
+
return (React__default.createElement(DataTableCell, null,
|
|
3450
|
+
React__default.createElement("div", { className: "text-sm text-gray-800" }, cell?.value || '-')));
|
|
3451
|
+
};
|
|
3452
|
+
|
|
3453
|
+
const TableRow = ({ row, columns, getTextColorFromBackGround, actionOptions, actionOptionOrientation, actionSelected, }) => (React__default.createElement(DataTableRow, { key: row.index.value }, columns.map((col) => {
|
|
3454
|
+
if (col.key === 'actions') {
|
|
3455
|
+
return (React__default.createElement(DataTableCell, { key: col.key }, actionOptions && (React__default.createElement(DataTableActions, { actionOptions: actionOptions, actionOptionOrientation: actionOptionOrientation, onClick: (option) => {
|
|
3456
|
+
if (option.onClick)
|
|
3457
|
+
option.onClick(row);
|
|
3458
|
+
actionSelected.emit({ action: option.label, row });
|
|
3459
|
+
} }))));
|
|
3460
|
+
}
|
|
3461
|
+
return (React__default.createElement(TableCell, { key: col.key, cell: row[col.key], getTextColorFromBackGround: getTextColorFromBackGround }));
|
|
3462
|
+
})));
|
|
3463
|
+
|
|
3464
|
+
const TableBody = ({ data, columns, getTextColorFromBackGround, actionOptions, actionOptionOrientation, actionSelected, }) => (React__default.createElement(TableBody$1, null, data.length > 0 ? (data.map((row) => (React__default.createElement(TableRow, { key: row.index.value, row: row, columns: columns, getTextColorFromBackGround: getTextColorFromBackGround, actionOptions: actionOptions, actionOptionOrientation: actionOptionOrientation, actionSelected: actionSelected })))) : (React__default.createElement(DataTableRow, null,
|
|
3465
|
+
React__default.createElement(DataTableCell, { colSpan: columns.length.toString(), style: {
|
|
3466
|
+
textAlign: 'center',
|
|
3467
|
+
fontWeight: 'bold',
|
|
3468
|
+
color: 'grey',
|
|
3469
|
+
padding: '20px',
|
|
3470
|
+
} }, "No data found")))));
|
|
3471
|
+
|
|
3472
|
+
const Pagination = ({ pager, setPager }) => {
|
|
3473
|
+
if (!pager || pager.page === undefined || pager.pageSize === undefined) {
|
|
3474
|
+
return null; //skip rendering until valid
|
|
3475
|
+
}
|
|
3476
|
+
return (React__default.createElement(Pagination$1, { page: pager.page, pageCount: pager.pageCount, pageSize: pager.pageSize, total: pager.total, onPageChange: (page) => setPager((prev) => new Pager({ ...prev, page })), onPageSizeChange: (pageSize) => setPager((prev) => new Pager({
|
|
3477
|
+
...prev,
|
|
3478
|
+
pageSize: Number(pageSize),
|
|
3479
|
+
page: 1,
|
|
3480
|
+
})), pageSizes: ['10', '20', '50', '100', '500'] }));
|
|
3481
|
+
};
|
|
3482
|
+
|
|
3483
|
+
const TableFooter = ({ pager, setPager, columns }) => {
|
|
3484
|
+
return (React__default.createElement(TableFoot, null,
|
|
3485
|
+
React__default.createElement(DataTableRow, null,
|
|
3486
|
+
React__default.createElement(DataTableCell, { colSpan: columns.length.toString() },
|
|
3487
|
+
React__default.createElement(Pagination, { pager: pager, setPager: setPager })))));
|
|
3488
|
+
};
|
|
3489
|
+
|
|
3490
|
+
const LineListTable = ({ columns, data, pager, setPager, getTextColorFromBackGround, actionOptions, actionOptionOrientation, actionSelected, }) => {
|
|
3491
|
+
return (React__default.createElement(DataTable, null,
|
|
3492
|
+
React__default.createElement(TableHeader, { columns: columns }),
|
|
3493
|
+
React__default.createElement(TableBody, { data: data, columns: columns, getTextColorFromBackGround: getTextColorFromBackGround, actionOptions: actionOptions, actionOptionOrientation: actionOptionOrientation, actionSelected: actionSelected }),
|
|
3494
|
+
React__default.createElement(TableFooter, { columns: columns, pager: pager, setPager: setPager })));
|
|
3495
|
+
};
|
|
3496
|
+
|
|
3245
3497
|
// Copyright 2025 UDSM DHIS2 Lab. All rights reserved.
|
|
3246
3498
|
// Use of this source code is governed by a BSD-style
|
|
3247
3499
|
// license that can be found in the LICENSE file.
|
|
@@ -3426,850 +3678,27 @@ const OrgUnitFormField$1 = (props) => {
|
|
|
3426
3678
|
React__default.createElement(CircularLoader$1, { small: true }))) : (React__default.createElement("div", { className: classes.orgUnitTreeContainer, style: { maxHeight: '200px', overflowY: 'auto' } }, renderOrgUnitTree()))))))));
|
|
3427
3679
|
};
|
|
3428
3680
|
|
|
3429
|
-
|
|
3430
|
-
|
|
3431
|
-
|
|
3432
|
-
|
|
3433
|
-
|
|
3434
|
-
|
|
3435
|
-
|
|
3436
|
-
|
|
3437
|
-
|
|
3438
|
-
|
|
3439
|
-
|
|
3440
|
-
})
|
|
3441
|
-
.filter(Boolean) // Remove any empty strings
|
|
3442
|
-
.join('&');
|
|
3443
|
-
}
|
|
3444
|
-
function buildFiltersFromEvents(filters) {
|
|
3445
|
-
return filters
|
|
3446
|
-
.map((filter) => `filter=${filter.programStage}.${filter.dataElement}:${filter.operator}:${filter.value}`)
|
|
3447
|
-
.join('&');
|
|
3448
|
-
}
|
|
3449
|
-
const matchesCondition = (eventValue, operator, filterValue) => {
|
|
3450
|
-
if (typeof eventValue === 'number' && typeof filterValue === 'number') {
|
|
3451
|
-
switch (operator) {
|
|
3452
|
-
case '=':
|
|
3453
|
-
return eventValue === filterValue;
|
|
3454
|
-
case '!=':
|
|
3455
|
-
return eventValue !== filterValue;
|
|
3456
|
-
case '>':
|
|
3457
|
-
return eventValue > filterValue;
|
|
3458
|
-
case '<':
|
|
3459
|
-
return eventValue < filterValue;
|
|
3460
|
-
case '>=':
|
|
3461
|
-
return eventValue >= filterValue;
|
|
3462
|
-
case '<=':
|
|
3463
|
-
return eventValue <= filterValue;
|
|
3464
|
-
default:
|
|
3465
|
-
return false;
|
|
3466
|
-
}
|
|
3467
|
-
}
|
|
3468
|
-
const strEventValue = String(eventValue);
|
|
3469
|
-
const strFilterValue = String(filterValue);
|
|
3470
|
-
switch (operator) {
|
|
3471
|
-
case '=':
|
|
3472
|
-
return strEventValue === strFilterValue;
|
|
3473
|
-
case '!=':
|
|
3474
|
-
return strEventValue !== strFilterValue;
|
|
3475
|
-
case 'contains':
|
|
3476
|
-
return strEventValue.includes(strFilterValue);
|
|
3477
|
-
case 'startsWith':
|
|
3478
|
-
return strEventValue.startsWith(strFilterValue);
|
|
3479
|
-
case 'endsWith':
|
|
3480
|
-
return strEventValue.endsWith(strFilterValue);
|
|
3481
|
-
case 'regex':
|
|
3482
|
-
return new RegExp(strFilterValue).test(strEventValue);
|
|
3483
|
-
default:
|
|
3484
|
-
return false;
|
|
3485
|
-
}
|
|
3486
|
-
};
|
|
3487
|
-
// export const getFilteredTrackedEntityInstances = (
|
|
3488
|
-
// trackedEntityInstance: TrackedEntityInstance[],
|
|
3489
|
-
// filters: FilterConfig[]
|
|
3490
|
-
// ): TrackedEntityInstance[] => {
|
|
3491
|
-
// return trackedEntityInstance.filter(
|
|
3492
|
-
// (trackedEntityInstance: TrackedEntityInstance) =>
|
|
3493
|
-
// trackedEntityInstance.enrollments.some((enrollment) =>
|
|
3494
|
-
// enrollment.events.some((event) =>
|
|
3495
|
-
// filters.every(
|
|
3496
|
-
// (filter) =>
|
|
3497
|
-
// event.programStage === filter.programStage &&
|
|
3498
|
-
// event.dataValues.some(
|
|
3499
|
-
// (dataValue) =>
|
|
3500
|
-
// dataValue.dataElement === filter.dataElement &&
|
|
3501
|
-
// matchesCondition(
|
|
3502
|
-
// dataValue.value,
|
|
3503
|
-
// filter.operator,
|
|
3504
|
-
// filter.value
|
|
3505
|
-
// )
|
|
3506
|
-
// )
|
|
3507
|
-
// )
|
|
3508
|
-
// )
|
|
3509
|
-
// )
|
|
3510
|
-
// );
|
|
3511
|
-
// };
|
|
3512
|
-
const getFilteredTrackedEntityInstances = (trackedEntityInstances, filters) => {
|
|
3513
|
-
if (!filters.length)
|
|
3514
|
-
return trackedEntityInstances;
|
|
3515
|
-
return trackedEntityInstances.filter((tei) => filters.every((filter) => tei.enrollments?.some((enrollment) => enrollment.events?.some((event) => event.programStage === filter.programStage &&
|
|
3516
|
-
event.dataValues?.some((dataValue) => dataValue.dataElement === filter.dataElement &&
|
|
3517
|
-
matchesCondition(dataValue.value, filter.operator, filter.value))))));
|
|
3518
|
-
};
|
|
3519
|
-
const getFilteredTrackedEntites = (trackedEntities, filters) => {
|
|
3520
|
-
if (!filters.length)
|
|
3521
|
-
return trackedEntities;
|
|
3522
|
-
return trackedEntities.filter((tei) => filters.every((filter) => tei.enrollments?.some((enrollment) => enrollment.events?.some((event) => event.programStage === filter.programStage &&
|
|
3523
|
-
event.dataValues?.some((dataValue) => dataValue.dataElement === filter.dataElement &&
|
|
3524
|
-
matchesCondition(dataValue.value, filter.operator, filter.value))))));
|
|
3525
|
-
};
|
|
3526
|
-
|
|
3527
|
-
class LineListService {
|
|
3528
|
-
constructor(httpClient) {
|
|
3529
|
-
this.httpClient = httpClient;
|
|
3530
|
-
}
|
|
3531
|
-
getProgramMetadata(programId) {
|
|
3532
|
-
return this.httpClient.get(`programs/${programId}.json?fields=programType,programStages[id,name,programStageDataElements[dataElement[id,name,shortName,formName,code,optionSetValue,valueType,
|
|
3533
|
-
optionSet[id,name,options[id,name,code]]]]],programTrackedEntityAttributes[*,trackedEntityAttribute[id,name,unique,generated,formName,code,optionSetValue
|
|
3534
|
-
,valueType,optionSet[id,name,options[id,name,code]]]],orgUnitLabel`);
|
|
3535
|
-
}
|
|
3536
|
-
// private getTrackedEntityInstances(
|
|
3537
|
-
// programId: string,
|
|
3538
|
-
// orgUnit: string,
|
|
3539
|
-
// page: number,
|
|
3540
|
-
// pageSize: number,
|
|
3541
|
-
// filters: AttributeFilter[] = [],
|
|
3542
|
-
// startDate?: string,
|
|
3543
|
-
// endDate?: string,
|
|
3544
|
-
// ouMode?: string,
|
|
3545
|
-
// filterRootOrgUnit?: boolean
|
|
3546
|
-
// ): Observable<TrackedEntityResponse> {
|
|
3547
|
-
// const filterParams = buildFilters(filters);
|
|
3548
|
-
// // const dateFilter = startDate || endDate ? `enrollmentEnrolledAfter=${startDate}&enrollmentEnrolledBefore=${endDate}` : '';
|
|
3549
|
-
// const dateFilter = [
|
|
3550
|
-
// startDate ? `enrollmentEnrolledAfter=${startDate}` : '',
|
|
3551
|
-
// endDate ? `enrollmentEnrolledBefore=${endDate}` : '',
|
|
3552
|
-
// ].filter(Boolean).join('&');
|
|
3553
|
-
// const ouModeIdentifier = ouMode ? `&orgUnitMode=${ouMode}`: ``;
|
|
3554
|
-
// return this.httpClient.get(
|
|
3555
|
-
// `tracker/trackedEntities.json?program=${programId}&orgUnit=${orgUnit}${ouModeIdentifier}&page=${page}&pageSize=${pageSize}&fields=trackedEntity,orgUnit,attributes[*],enrollments[*]&totalPages=true&${filterParams}${dateFilter}&order=createdAt:desc`
|
|
3556
|
-
// ).pipe(
|
|
3557
|
-
// map((response: any) => {
|
|
3558
|
-
// if (filterRootOrgUnit) {
|
|
3559
|
-
// response.trackedEntities = response.trackedEntities.filter(
|
|
3560
|
-
// (tei: any) => tei.orgUnit !== orgUnit // Exclude TEIs with the root orgUnit
|
|
3561
|
-
// );
|
|
3562
|
-
// }
|
|
3563
|
-
// return response;
|
|
3564
|
-
// })
|
|
3565
|
-
// );
|
|
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
|
-
// }
|
|
3639
|
-
getTrackedEntityInstances(programId, orgUnit, page, pageSize, filters = [], startDate, endDate, ouMode, filterRootOrgUnit, useOuModeWithOlderDHIS2Instance, filtersFromEvents = []) {
|
|
3640
|
-
const filterParams = buildFilters(filters);
|
|
3641
|
-
const filterParamsFromEvents = buildFiltersFromEvents(filtersFromEvents);
|
|
3642
|
-
const dateFilter = [
|
|
3643
|
-
startDate ? `enrollmentEnrolledAfter=${startDate}` : '',
|
|
3644
|
-
endDate ? `enrollmentEnrolledBefore=${endDate}` : '',
|
|
3645
|
-
]
|
|
3646
|
-
.filter(Boolean)
|
|
3647
|
-
.join('&');
|
|
3648
|
-
const ouModeIdentifier = ouMode && useOuModeWithOlderDHIS2Instance
|
|
3649
|
-
? `&ouMode=${ouMode}`
|
|
3650
|
-
: `&orgUnitMode=${ouMode}`;
|
|
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) => {
|
|
3659
|
-
if (filterRootOrgUnit) {
|
|
3660
|
-
response.trackedEntities = response.trackedEntities.filter((tei) => tei.orgUnit !== orgUnit);
|
|
3661
|
-
}
|
|
3662
|
-
const uniqueOrgUnitIds = new Set();
|
|
3663
|
-
if (response && response.trackedEntities) {
|
|
3664
|
-
response.trackedEntities.forEach((tei) => {
|
|
3665
|
-
tei.enrollments?.forEach((enrollment) => {
|
|
3666
|
-
if (enrollment.program === programId) {
|
|
3667
|
-
uniqueOrgUnitIds.add(enrollment.orgUnit);
|
|
3668
|
-
}
|
|
3669
|
-
});
|
|
3670
|
-
});
|
|
3671
|
-
}
|
|
3672
|
-
else {
|
|
3673
|
-
response?.instances?.forEach((tei) => {
|
|
3674
|
-
tei.enrollments?.forEach((enrollment) => {
|
|
3675
|
-
if (enrollment.program === programId) {
|
|
3676
|
-
uniqueOrgUnitIds.add(enrollment.orgUnit);
|
|
3677
|
-
}
|
|
3678
|
-
});
|
|
3679
|
-
});
|
|
3680
|
-
}
|
|
3681
|
-
if (filtersFromEvents.length === 0) {
|
|
3682
|
-
if (uniqueOrgUnitIds.size === 0) {
|
|
3683
|
-
return of({ ...response, orgUnitsMap: new Map() });
|
|
3684
|
-
}
|
|
3685
|
-
return this.fetchOrgUnits(Array.from(uniqueOrgUnitIds)).pipe(map$1((orgUnitsMap) => ({
|
|
3686
|
-
...response,
|
|
3687
|
-
orgUnitsMap,
|
|
3688
|
-
})));
|
|
3689
|
-
}
|
|
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
|
-
});
|
|
3700
|
-
}
|
|
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
|
-
}));
|
|
3716
|
-
}));
|
|
3717
|
-
}
|
|
3718
|
-
/**
|
|
3719
|
-
* Fetch orgUnit names for given orgUnit IDs
|
|
3720
|
-
*/
|
|
3721
|
-
fetchOrgUnits(orgUnitIds) {
|
|
3722
|
-
const idsQuery = `filter=id:in:[${orgUnitIds}]`;
|
|
3723
|
-
return this.httpClient
|
|
3724
|
-
.get(`organisationUnits.json?fields=id,name&paging=false&${idsQuery}`)
|
|
3725
|
-
.pipe(map$1((response) => {
|
|
3726
|
-
const orgUnitsMap = new Map();
|
|
3727
|
-
response.organisationUnits.forEach((orgUnit) => {
|
|
3728
|
-
orgUnitsMap.set(orgUnit.id, orgUnit.name);
|
|
3729
|
-
});
|
|
3730
|
-
return orgUnitsMap;
|
|
3731
|
-
}));
|
|
3732
|
-
}
|
|
3733
|
-
getEvents(programId, orgUnit, page, pageSize, filters = [], startDate, endDate, ouMode, useOuModeWithOlderDHIS2Instance) {
|
|
3734
|
-
const filterParams = buildFilters(filters);
|
|
3735
|
-
const dateFilter = startDate && endDate ? `&startDate=${startDate}&endDate=${endDate}` : '';
|
|
3736
|
-
const ouModeIdentifier = ouMode && useOuModeWithOlderDHIS2Instance
|
|
3737
|
-
? `&ouMode=${ouMode}`
|
|
3738
|
-
: `&ouMode=${ouMode}`;
|
|
3739
|
-
// const ouModeIdentifier = ouMode ? `&ouMode=${ouMode}`: ``;
|
|
3740
|
-
return this.httpClient.get(`events.json?program=${programId}&orgUnit=${orgUnit}${ouModeIdentifier}&page=${page}&pageSize=${pageSize}&fields=*&totalPages=true&${filterParams}${dateFilter}`);
|
|
3741
|
-
}
|
|
3742
|
-
getEventsByProgramStage(programStageId, orgUnit, page, pageSize, filters = [], startDate, endDate, ouMode) {
|
|
3743
|
-
const filterParams = buildFilters(filters);
|
|
3744
|
-
const dateFilter = startDate && endDate ? `&startDate=${startDate}&endDate=${endDate}` : '';
|
|
3745
|
-
const ouModeIdentifier = ouMode ? `&ouMode=${ouMode}` : ``;
|
|
3746
|
-
return this.httpClient.get(`events.json?programStage=${programStageId}&orgUnit=${orgUnit}${ouModeIdentifier}&page=${page}&pageSize=${pageSize}&fields=*&totalPages=true&${filterParams}${dateFilter}`);
|
|
3747
|
-
}
|
|
3748
|
-
getLineListData(programId, orgUnit = '', programStageId, page = 1, pageSize = 10, filters = [], startDate, endDate, ouMode, filterRootOrgUnit, useOuModeWithOlderDHIS2Instance, filtersFromEvents = []) {
|
|
3749
|
-
return this.getProgramMetadata(programId).pipe(switchMap((programMetadata) => {
|
|
3750
|
-
if (programStageId) {
|
|
3751
|
-
return this.getEventsByProgramStage(programStageId, orgUnit, page, pageSize, filters, startDate, endDate, ouMode).pipe(map$1((events) => ({
|
|
3752
|
-
metadata: programMetadata,
|
|
3753
|
-
data: events,
|
|
3754
|
-
})));
|
|
3755
|
-
}
|
|
3756
|
-
if (programMetadata.programType === 'WITH_REGISTRATION') {
|
|
3757
|
-
return this.getTrackedEntityInstances(programId, orgUnit, page, pageSize, filters, startDate, endDate, ouMode, filterRootOrgUnit, useOuModeWithOlderDHIS2Instance, filtersFromEvents).pipe(map$1((teis) => ({
|
|
3758
|
-
metadata: programMetadata,
|
|
3759
|
-
data: teis,
|
|
3760
|
-
orgUnits: teis.orgUnitsMap,
|
|
3761
|
-
})));
|
|
3762
|
-
}
|
|
3763
|
-
else {
|
|
3764
|
-
return this.getEvents(programId, orgUnit, page, pageSize, filters, startDate, endDate, ouMode, useOuModeWithOlderDHIS2Instance).pipe(map$1((events) => ({
|
|
3765
|
-
metadata: programMetadata,
|
|
3766
|
-
data: events,
|
|
3767
|
-
})));
|
|
3768
|
-
}
|
|
3769
|
-
}));
|
|
3770
|
-
}
|
|
3771
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.1.8", ngImport: i0, type: LineListService, deps: [{ token: i1.NgxDhis2HttpClientService }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
3772
|
-
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.1.8", ngImport: i0, type: LineListService }); }
|
|
3773
|
-
}
|
|
3774
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.1.8", ngImport: i0, type: LineListService, decorators: [{
|
|
3775
|
-
type: Injectable
|
|
3776
|
-
}], ctorParameters: () => [{ type: i1.NgxDhis2HttpClientService }] });
|
|
3777
|
-
|
|
3778
|
-
// export const getProgramStageData = (
|
|
3779
|
-
// response: LineListResponse,
|
|
3780
|
-
// programStageId: string,
|
|
3781
|
-
// pager: any,
|
|
3782
|
-
// isOptionSetNameVisible: boolean
|
|
3783
|
-
// ): { columns: ColumnDefinition[]; data: TableRow[] } => {
|
|
3784
|
-
// const events = (response.data as EventsResponse).events;
|
|
3785
|
-
// const allDataElements = new Set<string>();
|
|
3786
|
-
// events.forEach((event: any) => {
|
|
3787
|
-
// event.dataValues.forEach((dv: any) => allDataElements.add(dv.dataElement));
|
|
3788
|
-
// });
|
|
3789
|
-
// const stageFromMetaData = response.metadata.programStages.find(
|
|
3790
|
-
// (stage: any) => stage.id === programStageId
|
|
3791
|
-
// );
|
|
3792
|
-
// if (!stageFromMetaData) {
|
|
3793
|
-
// throw new Error(`Program stage with ID ${programStageId} not found`);
|
|
3794
|
-
// }
|
|
3795
|
-
// const entityColumns = Array.from(allDataElements).map(
|
|
3796
|
-
// (dataElementId: string) => ({
|
|
3797
|
-
// label:
|
|
3798
|
-
// stageFromMetaData.programStageDataElements.find(
|
|
3799
|
-
// (psde: any) => psde.dataElement.id === dataElementId
|
|
3800
|
-
// )?.dataElement.name || dataElementId,
|
|
3801
|
-
// key: dataElementId,
|
|
3802
|
-
// })
|
|
3803
|
-
// );
|
|
3804
|
-
// const dataElementsData: TableRow[] = events.map((event: any, idx: number) => {
|
|
3805
|
-
// const row: TableRow = {
|
|
3806
|
-
// event: event.event,
|
|
3807
|
-
// index: (pager.page - 1) * pager.pageSize + idx + 1,
|
|
3808
|
-
// };
|
|
3809
|
-
// allDataElements.forEach(
|
|
3810
|
-
// (dataElementId: string) => (row[dataElementId] = '')
|
|
3811
|
-
// );
|
|
3812
|
-
// if (isOptionSetNameVisible) {
|
|
3813
|
-
// event.dataValues.forEach((dv: any) => (row[dv.dataElement] = dv.value));
|
|
3814
|
-
// } else {
|
|
3815
|
-
// event.dataValues.forEach((dv: any) => (row[dv.dataElement] = dv.value));
|
|
3816
|
-
// }
|
|
3817
|
-
// return row;
|
|
3818
|
-
// });
|
|
3819
|
-
// return { columns: entityColumns, data: dataElementsData };
|
|
3820
|
-
// };
|
|
3821
|
-
// export const getTrackedEntityData = (
|
|
3822
|
-
// response: LineListResponse,
|
|
3823
|
-
// programId: string,
|
|
3824
|
-
// pager: any,
|
|
3825
|
-
// isOptionSetNameVisible: boolean,
|
|
3826
|
-
// filters?: FilterConfig[]
|
|
3827
|
-
// ): {
|
|
3828
|
-
// columns: ColumnDefinition[];
|
|
3829
|
-
// data: TableRow[];
|
|
3830
|
-
// filteredEntityColumns: ColumnDefinition[];
|
|
3831
|
-
// } => {
|
|
3832
|
-
// let teis =
|
|
3833
|
-
// (response.data as TrackedEntityResponse)?.trackedEntities ??
|
|
3834
|
-
// (response.data as TrackedEntityResponse)?.instances ??
|
|
3835
|
-
// [];
|
|
3836
|
-
// const programMetaData = response.metadata.programTrackedEntityAttributes;
|
|
3837
|
-
// // //organisation units from metadata
|
|
3838
|
-
// // let orgUnitsFromMetaData = response.metadata.organisationUnits;
|
|
3839
|
-
// // //a Map to efficiently look up orgUnit names by ID
|
|
3840
|
-
// // const orgUnitMap = new Map<string, string>(
|
|
3841
|
-
// // orgUnitsFromMetaData.map((ou: { id: string; name: string }) => [
|
|
3842
|
-
// // ou.id,
|
|
3843
|
-
// // ou.name,
|
|
3844
|
-
// // ])
|
|
3845
|
-
// // );
|
|
3846
|
-
// const orgUnitMap = (response.data as TrackedEntityResponse).orgUnitsMap;
|
|
3847
|
-
// const mappedProgramMetadataAttributes = programMetaData.map((attr) => ({
|
|
3848
|
-
// displayInList: attr.displayInList,
|
|
3849
|
-
// searchable: attr.searchable,
|
|
3850
|
-
// id: attr.trackedEntityAttribute.id,
|
|
3851
|
-
// }));
|
|
3852
|
-
// const programAttributesMap = programMetaData.reduce(
|
|
3853
|
-
// (acc: { [key: string]: string }, attribute: any) => {
|
|
3854
|
-
// if (attribute.displayInList) {
|
|
3855
|
-
// acc[attribute.id] = attribute.displayName;
|
|
3856
|
-
// }
|
|
3857
|
-
// return acc;
|
|
3858
|
-
// },
|
|
3859
|
-
// {}
|
|
3860
|
-
// );
|
|
3861
|
-
// if (filters) {
|
|
3862
|
-
// teis = getFilteredTrackedEntites(teis, filters);
|
|
3863
|
-
// }
|
|
3864
|
-
// const allAttributes = new Set<string>();
|
|
3865
|
-
// teis.forEach((tei: any) => {
|
|
3866
|
-
// const matchingEnrollment = tei.enrollments.find(
|
|
3867
|
-
// (enrollment: any) => enrollment.program === programId
|
|
3868
|
-
// );
|
|
3869
|
-
// const attributes = matchingEnrollment
|
|
3870
|
-
// ? matchingEnrollment.attributes
|
|
3871
|
-
// : tei.attributes;
|
|
3872
|
-
// attributes.forEach((attr: any) => allAttributes.add(attr.attribute));
|
|
3873
|
-
// });
|
|
3874
|
-
// let entityColumns = Array.from(allAttributes).map((attrId: string) => {
|
|
3875
|
-
// const foundAttribute = teis
|
|
3876
|
-
// .flatMap((tei: any) => {
|
|
3877
|
-
// const matchingEnrollment = tei.enrollments.find(
|
|
3878
|
-
// (enrollment: any) => enrollment.program === programId
|
|
3879
|
-
// );
|
|
3880
|
-
// return matchingEnrollment
|
|
3881
|
-
// ? matchingEnrollment.attributes
|
|
3882
|
-
// : tei.attributes;
|
|
3883
|
-
// })
|
|
3884
|
-
// .find((attr: any) => attr.attribute === attrId);
|
|
3885
|
-
// return {
|
|
3886
|
-
// label: foundAttribute?.displayName || attrId,
|
|
3887
|
-
// key: attrId,
|
|
3888
|
-
// };
|
|
3889
|
-
// });
|
|
3890
|
-
// entityColumns = entityColumns.filter((column) => {
|
|
3891
|
-
// // Check if the column label is part of any value in programAttributesMap
|
|
3892
|
-
// return Object.values(programAttributesMap).some((value: string) =>
|
|
3893
|
-
// value.includes(column.label)
|
|
3894
|
-
// );
|
|
3895
|
-
// });
|
|
3896
|
-
// // Add orgUnit as the first column
|
|
3897
|
-
// entityColumns.unshift({
|
|
3898
|
-
// label: 'Location',
|
|
3899
|
-
// key: 'orgUnit',
|
|
3900
|
-
// });
|
|
3901
|
-
// const searchableAttributes = mappedProgramMetadataAttributes
|
|
3902
|
-
// .filter((attr) => attr.searchable && attr.displayInList)
|
|
3903
|
-
// .map((attr) => ({
|
|
3904
|
-
// // label: attr.trackedEntityAttribute.displayName,
|
|
3905
|
-
// key: attr.id,
|
|
3906
|
-
// }));
|
|
3907
|
-
// // Extract keys from searchableAttributes for quick lookup
|
|
3908
|
-
// const searchableKeys = new Set(searchableAttributes.map((attr) => attr.key));
|
|
3909
|
-
// // Filter entityColumns to keep only those whose key exists in searchableAttributes
|
|
3910
|
-
// const filteredEntityColumns = entityColumns.filter((column) =>
|
|
3911
|
-
// searchableKeys.has(column.key)
|
|
3912
|
-
// );
|
|
3913
|
-
// const attributesData = teis.map((tei: any, idx: number) => {
|
|
3914
|
-
// const row: TableRow = {
|
|
3915
|
-
// trackedEntityInstance: tei.trackedEntity,
|
|
3916
|
-
// index: (pager.page - 1) * pager.pageSize + idx + 1,
|
|
3917
|
-
// };
|
|
3918
|
-
// allAttributes.forEach((attrId: string) => (row[attrId] = ''));
|
|
3919
|
-
// const matchingEnrollment = tei.enrollments.find(
|
|
3920
|
-
// (enrollment: any) => enrollment.program === programId
|
|
3921
|
-
// );
|
|
3922
|
-
// const attributesToUse = matchingEnrollment
|
|
3923
|
-
// ? matchingEnrollment.attributes
|
|
3924
|
-
// : tei.attributes;
|
|
3925
|
-
// console.log('RESPONSE::: ', JSON.stringify(attributesToUse));
|
|
3926
|
-
// console.log('HERE WEARE', JSON.stringify(response.metadata));
|
|
3927
|
-
// if (isOptionSetNameVisible) {
|
|
3928
|
-
// attributesToUse.forEach(
|
|
3929
|
-
// (attr: any) => (row[attr.attribute] = attr.value)
|
|
3930
|
-
// );
|
|
3931
|
-
// } else {
|
|
3932
|
-
// attributesToUse.forEach(
|
|
3933
|
-
// (attr: any) => (row[attr.attribute] = attr.value)
|
|
3934
|
-
// );
|
|
3935
|
-
// }
|
|
3936
|
-
// //include orgUnit in the row for id access
|
|
3937
|
-
// row['orgUnitId'] = matchingEnrollment.orgUnit;
|
|
3938
|
-
// // Access the name of the orgUnit using the Map
|
|
3939
|
-
// // row['orgUnit'] = matchingEnrollment.orgUnitName;
|
|
3940
|
-
// row['orgUnit'] = orgUnitMap?.get(matchingEnrollment.orgUnit) || 'N/A';
|
|
3941
|
-
// // row['orgUnit'] =
|
|
3942
|
-
// // orgUnitMap && orgUnitMap[matchingEnrollment.orgUnit]
|
|
3943
|
-
// // ? orgUnitMap[matchingEnrollment.orgUnit]
|
|
3944
|
-
// // : 'N/A';
|
|
3945
|
-
// return row;
|
|
3946
|
-
// });
|
|
3947
|
-
// return {
|
|
3948
|
-
// columns: entityColumns,
|
|
3949
|
-
// data: attributesData,
|
|
3950
|
-
// filteredEntityColumns: filteredEntityColumns,
|
|
3951
|
-
// };
|
|
3952
|
-
// };
|
|
3953
|
-
const getProgramStageData = (response, programStageId, pager, isOptionSetNameVisible) => {
|
|
3954
|
-
const events = response.data.events;
|
|
3955
|
-
const allDataElements = new Set();
|
|
3956
|
-
events.forEach((event) => {
|
|
3957
|
-
event.dataValues.forEach((dv) => allDataElements.add(dv.dataElement));
|
|
3958
|
-
});
|
|
3959
|
-
const stageFromMetaData = response.metadata.programStages.find((stage) => stage.id === programStageId);
|
|
3960
|
-
if (!stageFromMetaData) {
|
|
3961
|
-
throw new Error(`Program stage with ID ${programStageId} not found`);
|
|
3962
|
-
}
|
|
3963
|
-
const entityColumns = Array.from(allDataElements).map((dataElementId) => {
|
|
3964
|
-
const dataElementMeta = stageFromMetaData.programStageDataElements.find((psde) => psde.dataElement.id === dataElementId);
|
|
3965
|
-
return {
|
|
3966
|
-
label: dataElementMeta?.dataElement.name || dataElementId,
|
|
3967
|
-
key: dataElementId,
|
|
3968
|
-
};
|
|
3969
|
-
});
|
|
3970
|
-
const dataElementsData = events.map((event, idx) => {
|
|
3971
|
-
const row = {
|
|
3972
|
-
event: event.event,
|
|
3973
|
-
index: (pager.page - 1) * pager.pageSize + idx + 1,
|
|
3974
|
-
};
|
|
3975
|
-
allDataElements.forEach((dataElementId) => (row[dataElementId] = ''));
|
|
3976
|
-
event.dataValues.forEach((dv) => {
|
|
3977
|
-
const dataElementMeta = stageFromMetaData.programStageDataElements.find((psde) => psde.dataElement.id === dv.dataElement);
|
|
3978
|
-
if (isOptionSetNameVisible && dataElementMeta?.dataElement.optionSet) {
|
|
3979
|
-
const optionSet = dataElementMeta.dataElement.optionSet;
|
|
3980
|
-
const matchingOption = optionSet.options.find((option) => option.code === dv.value);
|
|
3981
|
-
row[dv.dataElement] = matchingOption ? matchingOption.name : dv.value;
|
|
3982
|
-
}
|
|
3983
|
-
else {
|
|
3984
|
-
row[dv.dataElement] = dv.value;
|
|
3985
|
-
}
|
|
3986
|
-
});
|
|
3987
|
-
return row;
|
|
3988
|
-
});
|
|
3989
|
-
return { columns: entityColumns, data: dataElementsData };
|
|
3990
|
-
};
|
|
3991
|
-
const getTrackedEntityData = (response, programId, pager, isOptionSetNameVisible, filters) => {
|
|
3992
|
-
let teis = response.data?.trackedEntities ??
|
|
3993
|
-
response.data?.instances ??
|
|
3994
|
-
[];
|
|
3995
|
-
const programMetaData = response.metadata.programTrackedEntityAttributes;
|
|
3996
|
-
const orgUnitLabel = response.metadata.orgUnitLabel;
|
|
3997
|
-
const orgUnitMap = response.data.orgUnitsMap;
|
|
3998
|
-
const mappedProgramMetadataAttributes = programMetaData.map((attr) => ({
|
|
3999
|
-
displayInList: attr.displayInList,
|
|
4000
|
-
searchable: attr.searchable,
|
|
4001
|
-
id: attr.trackedEntityAttribute.id,
|
|
4002
|
-
name: attr.trackedEntityAttribute.name,
|
|
4003
|
-
optionSet: attr.trackedEntityAttribute.optionSetValue
|
|
4004
|
-
? attr.trackedEntityAttribute.optionSet
|
|
4005
|
-
: null,
|
|
4006
|
-
sortOrder: attr.sortOrder,
|
|
4007
|
-
}));
|
|
4008
|
-
// if (filters) {
|
|
4009
|
-
// teis = getFilteredTrackedEntites(teis, filters);
|
|
4010
|
-
// }
|
|
4011
|
-
const allAttributes = new Set();
|
|
4012
|
-
teis.forEach((tei) => {
|
|
4013
|
-
const matchingEnrollment = tei.enrollments.find((enrollment) => enrollment.program === programId);
|
|
4014
|
-
const attributes = matchingEnrollment
|
|
4015
|
-
? matchingEnrollment.attributes
|
|
4016
|
-
: tei.attributes;
|
|
4017
|
-
attributes.forEach((attr) => allAttributes.add(attr.attribute));
|
|
4018
|
-
});
|
|
4019
|
-
let entityColumns = Array.from(allAttributes).map((attrId) => {
|
|
4020
|
-
const foundAttribute = teis
|
|
4021
|
-
.flatMap((tei) => {
|
|
4022
|
-
const matchingEnrollment = tei.enrollments.find((enrollment) => enrollment.program === programId);
|
|
4023
|
-
return matchingEnrollment
|
|
4024
|
-
? matchingEnrollment.attributes
|
|
4025
|
-
: tei.attributes;
|
|
4026
|
-
})
|
|
4027
|
-
.find((attr) => attr.attribute === attrId);
|
|
4028
|
-
return {
|
|
4029
|
-
label: foundAttribute?.displayName || attrId,
|
|
4030
|
-
key: attrId,
|
|
4031
|
-
};
|
|
4032
|
-
});
|
|
4033
|
-
entityColumns = entityColumns
|
|
4034
|
-
.filter((column) => {
|
|
4035
|
-
return mappedProgramMetadataAttributes
|
|
4036
|
-
.filter((attr) => attr.displayInList)
|
|
4037
|
-
.some((attr) => attr.id === column.key); // Ensure the column's key matches an id in the filtered list
|
|
4038
|
-
})
|
|
4039
|
-
.sort((a, b) => {
|
|
4040
|
-
// Ensures sortOrder values are treated as numbers
|
|
4041
|
-
const sortOrderA = Number(mappedProgramMetadataAttributes.find((attr) => attr.id === a.key)
|
|
4042
|
-
?.sortOrder ?? 0); // Default to 0 if undefined, explicitly cast to number
|
|
4043
|
-
const sortOrderB = Number(mappedProgramMetadataAttributes.find((attr) => attr.id === b.key)
|
|
4044
|
-
?.sortOrder ?? 0); // Default to 0 if undefined, explicitly cast to number
|
|
4045
|
-
return sortOrderA - sortOrderB; // Ascending order based on sortOrder
|
|
4046
|
-
});
|
|
4047
|
-
entityColumns.unshift({
|
|
4048
|
-
label: orgUnitLabel || 'registering unit',
|
|
4049
|
-
key: 'orgUnit',
|
|
4050
|
-
});
|
|
4051
|
-
const searchableAttributes = mappedProgramMetadataAttributes
|
|
4052
|
-
.filter((attr) => attr.searchable && attr.displayInList)
|
|
4053
|
-
.map((attr) => ({
|
|
4054
|
-
key: attr.id,
|
|
4055
|
-
}));
|
|
4056
|
-
const searchableKeys = new Set(searchableAttributes.map((attr) => attr.key));
|
|
4057
|
-
const filteredEntityColumns = Array.from(allAttributes)
|
|
4058
|
-
.map((attrId) => {
|
|
4059
|
-
const foundAttribute = teis
|
|
4060
|
-
.flatMap((tei) => {
|
|
4061
|
-
const matchingEnrollment = tei.enrollments.find((enrollment) => enrollment.program === programId);
|
|
4062
|
-
return matchingEnrollment
|
|
4063
|
-
? matchingEnrollment.attributes
|
|
4064
|
-
: tei.attributes;
|
|
4065
|
-
})
|
|
4066
|
-
.find((attr) => attr.attribute === attrId);
|
|
4067
|
-
// Find the corresponding attribute in mappedProgramMetadataAttributes
|
|
4068
|
-
const mappedAttr = mappedProgramMetadataAttributes.find((attr) => attr.id === attrId);
|
|
4069
|
-
return {
|
|
4070
|
-
label: foundAttribute?.displayName || attrId,
|
|
4071
|
-
key: attrId,
|
|
4072
|
-
valueType: foundAttribute?.valueType,
|
|
4073
|
-
options: mappedAttr?.optionSet ?? undefined,
|
|
4074
|
-
};
|
|
4075
|
-
})
|
|
4076
|
-
.filter((column) => {
|
|
4077
|
-
return mappedProgramMetadataAttributes
|
|
4078
|
-
.filter((attr) => attr.displayInList)
|
|
4079
|
-
.some((attr) => attr.id === column.key);
|
|
4080
|
-
})
|
|
4081
|
-
.sort((a, b) => {
|
|
4082
|
-
const sortOrderA = Number(mappedProgramMetadataAttributes.find((attr) => attr.id === a.key)
|
|
4083
|
-
?.sortOrder ?? 0);
|
|
4084
|
-
const sortOrderB = Number(mappedProgramMetadataAttributes.find((attr) => attr.id === b.key)
|
|
4085
|
-
?.sortOrder ?? 0);
|
|
4086
|
-
return sortOrderA - sortOrderB;
|
|
4087
|
-
})
|
|
4088
|
-
.filter((column) => searchableKeys.has(column.key));
|
|
4089
|
-
const attributesData = teis.map((tei, idx) => {
|
|
4090
|
-
const row = {
|
|
4091
|
-
trackedEntityInstance: tei.trackedEntity,
|
|
4092
|
-
index: (pager.page - 1) * pager.pageSize + idx + 1,
|
|
4093
|
-
};
|
|
4094
|
-
allAttributes.forEach((attrId) => (row[attrId] = ''));
|
|
4095
|
-
const matchingEnrollment = tei.enrollments.find((enrollment) => enrollment.program === programId);
|
|
4096
|
-
let attributesToUse = matchingEnrollment
|
|
4097
|
-
? matchingEnrollment.attributes
|
|
4098
|
-
: tei.attributes;
|
|
4099
|
-
//TODO: find a better way to do optimize this date parsing
|
|
4100
|
-
//map any date that occur in the attributes to dd-mm-yyyy
|
|
4101
|
-
attributesToUse = attributesToUse.map((attr) => {
|
|
4102
|
-
// Check if the attribute is of type DATE
|
|
4103
|
-
if (attr?.valueType === 'DATE' || attr?.valueType === 'date') {
|
|
4104
|
-
try {
|
|
4105
|
-
// Parse the date and format it as dd-MM-yyyy
|
|
4106
|
-
const parsedDate = parse$1(attr.value, 'yyyy-MM-dd', new Date());
|
|
4107
|
-
const formattedDate = format(parsedDate, 'dd-MM-yyyy');
|
|
4108
|
-
// Update the value to the formatted date
|
|
4109
|
-
return {
|
|
4110
|
-
...attr,
|
|
4111
|
-
value: formattedDate,
|
|
4112
|
-
};
|
|
4113
|
-
}
|
|
4114
|
-
catch {
|
|
4115
|
-
// If parsing fails, keep the original value
|
|
4116
|
-
return {
|
|
4117
|
-
...attr,
|
|
4118
|
-
value: attr.value,
|
|
4119
|
-
};
|
|
4120
|
-
}
|
|
4121
|
-
}
|
|
4122
|
-
// If not a date, just return the attribute as is
|
|
4123
|
-
return attr;
|
|
4124
|
-
});
|
|
4125
|
-
// If option set names are visible, transform the attribute values
|
|
4126
|
-
if (isOptionSetNameVisible) {
|
|
4127
|
-
attributesToUse.forEach((attr) => {
|
|
4128
|
-
const attributeMeta = programMetaData.find((metadata) => metadata.trackedEntityAttribute.id === attr.attribute);
|
|
4129
|
-
// Check if the attribute has an option set and map value to option name
|
|
4130
|
-
if (attributeMeta?.trackedEntityAttribute.optionSetValue) {
|
|
4131
|
-
const optionSet = attributeMeta?.trackedEntityAttribute?.optionSet;
|
|
4132
|
-
const option = optionSet?.options?.find((option) => option.code === attr.value);
|
|
4133
|
-
row[attr.attribute] = option ? option.name : attr.value;
|
|
4134
|
-
}
|
|
4135
|
-
else {
|
|
4136
|
-
row[attr.attribute] = attr.value;
|
|
4137
|
-
}
|
|
4138
|
-
});
|
|
4139
|
-
}
|
|
4140
|
-
else {
|
|
4141
|
-
attributesToUse.forEach((attr) => (row[attr.attribute] = attr.value));
|
|
4142
|
-
}
|
|
4143
|
-
// Include orgUnit in the row for id access
|
|
4144
|
-
row['orgUnitId'] = matchingEnrollment.orgUnit;
|
|
4145
|
-
row['orgUnit'] = orgUnitMap?.get(matchingEnrollment.orgUnit) || 'N/A';
|
|
4146
|
-
return row;
|
|
4147
|
-
});
|
|
4148
|
-
if (teis.length === 0) {
|
|
4149
|
-
entityColumns = [
|
|
4150
|
-
{ label: orgUnitLabel || 'registering unit', key: 'orgUnit' },
|
|
4151
|
-
...mappedProgramMetadataAttributes
|
|
4152
|
-
.filter((attr) => attr.displayInList === true)
|
|
4153
|
-
.sort((a, b) => {
|
|
4154
|
-
return Number(a.sortOrder) - Number(b.sortOrder);
|
|
4155
|
-
})
|
|
4156
|
-
.map((attr) => ({
|
|
4157
|
-
key: attr.id,
|
|
4158
|
-
label: attr.name,
|
|
4159
|
-
})),
|
|
4160
|
-
];
|
|
4161
|
-
}
|
|
4162
|
-
return {
|
|
4163
|
-
columns: entityColumns,
|
|
4164
|
-
data: attributesData,
|
|
4165
|
-
filteredEntityColumns: filteredEntityColumns,
|
|
4166
|
-
orgUnitLabel: orgUnitLabel,
|
|
4167
|
-
};
|
|
4168
|
-
};
|
|
4169
|
-
// export const getEventData = (
|
|
4170
|
-
// response: LineListResponse,
|
|
4171
|
-
// pager: any,
|
|
4172
|
-
// isOptionSetNameVisible: boolean
|
|
4173
|
-
// ): { columns: ColumnDefinition[]; data: TableRow[] } => {
|
|
4174
|
-
// const events = (response.data as EventsResponse).events;
|
|
4175
|
-
// const uniqueDataElements = new Set<string>();
|
|
4176
|
-
// events?.forEach((event: any) => {
|
|
4177
|
-
// event?.dataValues.forEach((dv: any) =>
|
|
4178
|
-
// uniqueDataElements.add(dv.dataElement)
|
|
4179
|
-
// );
|
|
4180
|
-
// });
|
|
4181
|
-
// const entityColumns = Array.from(uniqueDataElements).map(
|
|
4182
|
-
// (dataElement: string) => ({
|
|
4183
|
-
// label:
|
|
4184
|
-
// response.metadata.programStages[0].programStageDataElements.find(
|
|
4185
|
-
// (psde: any) => psde.dataElement.id === dataElement
|
|
4186
|
-
// )?.dataElement.name || dataElement,
|
|
4187
|
-
// key: dataElement,
|
|
4188
|
-
// })
|
|
4189
|
-
// );
|
|
4190
|
-
// const dataElementsData = events.map((event: any, idx: number) => {
|
|
4191
|
-
// const row: TableRow = {
|
|
4192
|
-
// event: event.event,
|
|
4193
|
-
// index: (pager.page - 1) * pager.pageSize + idx + 1,
|
|
4194
|
-
// };
|
|
4195
|
-
// uniqueDataElements.forEach(
|
|
4196
|
-
// (dataElement: string) => (row[dataElement] = '')
|
|
4197
|
-
// );
|
|
4198
|
-
// event.dataValues.forEach((dv: any) => {
|
|
4199
|
-
// if (isOptionSetNameVisible) {
|
|
4200
|
-
// return (row[dv.dataElement] = dv.value)
|
|
4201
|
-
// } else {
|
|
4202
|
-
// return (row[dv.dataElement] = dv.value)
|
|
4203
|
-
// }
|
|
4204
|
-
// });
|
|
4205
|
-
// return row;
|
|
4206
|
-
// });
|
|
4207
|
-
// return { columns: entityColumns, data: dataElementsData };
|
|
4208
|
-
// };
|
|
4209
|
-
const getEventData = (response, pager, isOptionSetNameVisible) => {
|
|
4210
|
-
const events = response.data.events;
|
|
4211
|
-
const uniqueDataElements = new Set();
|
|
4212
|
-
events?.forEach((event) => {
|
|
4213
|
-
event?.dataValues.forEach((dv) => uniqueDataElements.add(dv.dataElement));
|
|
4214
|
-
});
|
|
4215
|
-
const entityColumns = Array.from(uniqueDataElements).map((dataElement) => ({
|
|
4216
|
-
label: response.metadata.programStages[0].programStageDataElements.find((psde) => psde.dataElement.id === dataElement)?.dataElement.name || dataElement,
|
|
4217
|
-
key: dataElement,
|
|
4218
|
-
}));
|
|
4219
|
-
const dataElementsData = events.map((event, idx) => {
|
|
4220
|
-
const row = {
|
|
4221
|
-
event: event.event,
|
|
4222
|
-
index: (pager.page - 1) * pager.pageSize + idx + 1,
|
|
4223
|
-
};
|
|
4224
|
-
uniqueDataElements.forEach((dataElement) => (row[dataElement] = ''));
|
|
4225
|
-
event.dataValues.forEach((dv) => {
|
|
4226
|
-
if (isOptionSetNameVisible && dv.optionSetValue) {
|
|
4227
|
-
const dataElementMetadata = response.metadata.programStages
|
|
4228
|
-
.flatMap((programStage) => programStage.programStageDataElements)
|
|
4229
|
-
.find((psde) => psde.dataElement.id === dv.dataElement)
|
|
4230
|
-
?.dataElement.optionSet;
|
|
4231
|
-
if (dataElementMetadata && dataElementMetadata.options) {
|
|
4232
|
-
const matchingOption = dataElementMetadata.options.find((option) => option.code === dv.value);
|
|
4233
|
-
if (matchingOption) {
|
|
4234
|
-
row[dv.dataElement] = matchingOption.name;
|
|
4235
|
-
}
|
|
4236
|
-
else {
|
|
4237
|
-
row[dv.dataElement] = dv.value;
|
|
4238
|
-
}
|
|
4239
|
-
}
|
|
4240
|
-
else {
|
|
4241
|
-
row[dv.dataElement] = dv.value;
|
|
4242
|
-
}
|
|
4243
|
-
}
|
|
4244
|
-
else {
|
|
4245
|
-
row[dv.dataElement] = dv.value;
|
|
4246
|
-
}
|
|
4247
|
-
});
|
|
4248
|
-
return row;
|
|
4249
|
-
});
|
|
4250
|
-
return { columns: entityColumns, data: dataElementsData };
|
|
4251
|
-
};
|
|
4252
|
-
const addActionsColumn = (columns, actionOptions) => {
|
|
4253
|
-
return [
|
|
4254
|
-
...columns,
|
|
4255
|
-
...(actionOptions && actionOptions.length > 0
|
|
4256
|
-
? [{ label: 'Actions', key: 'actions' }]
|
|
4257
|
-
: []),
|
|
4258
|
-
];
|
|
4259
|
-
};
|
|
3681
|
+
const OrgUnitSelector = ({ hide, setHide, selectedOrgUnit, setSelectedOrgUnit, setOrgUnitState, }) => (React__default.createElement(Modal$1, { hide: hide, position: "middle" },
|
|
3682
|
+
React__default.createElement(ModalTitle$1, null, "Select organization unit"),
|
|
3683
|
+
React__default.createElement(ModalContent$1, null,
|
|
3684
|
+
React__default.createElement(OrgUnitFormField$1, { key: selectedOrgUnit, onSelectOrgUnit: (selectedOrgUnit) => {
|
|
3685
|
+
setSelectedOrgUnit(selectedOrgUnit.displayName);
|
|
3686
|
+
setOrgUnitState(selectedOrgUnit.id);
|
|
3687
|
+
setHide(true);
|
|
3688
|
+
} })),
|
|
3689
|
+
React__default.createElement(ModalActions$1, null,
|
|
3690
|
+
React__default.createElement(ButtonStrip$1, { end: true },
|
|
3691
|
+
React__default.createElement(Button$1, { onClick: () => setHide(true), secondary: true }, "Close")))));
|
|
4260
3692
|
|
|
4261
3693
|
// src/app/line-list-table.component.ts
|
|
4262
3694
|
class LineListTableComponent extends ReactWrapperModule {
|
|
4263
3695
|
constructor() {
|
|
4264
3696
|
super(...arguments);
|
|
4265
3697
|
this.actionOptionOrientation = 'DROPDOWN';
|
|
4266
|
-
this.dispatchTeis = false;
|
|
4267
3698
|
this.actionSelected = new EventEmitter();
|
|
4268
3699
|
this.reactStateUpdaters = null;
|
|
4269
3700
|
this.approvalSelected = new EventEmitter();
|
|
4270
3701
|
this.isButtonLoading = false;
|
|
4271
|
-
this.buttonLabel = '';
|
|
4272
|
-
this.firstValue = new EventEmitter();
|
|
4273
3702
|
this.filterRootOrgUnit = false;
|
|
4274
3703
|
this.showFilters = false;
|
|
4275
3704
|
this.isOptionSetNameVisible = false;
|
|
@@ -4280,29 +3709,25 @@ class LineListTableComponent extends ReactWrapperModule {
|
|
|
4280
3709
|
this.LineList = () => {
|
|
4281
3710
|
const [columns, setColumns] = useState([]);
|
|
4282
3711
|
const [data, setData] = useState([]);
|
|
4283
|
-
const [pager, setPager] = useState({
|
|
3712
|
+
const [pager, setPager] = useState(new Pager({
|
|
4284
3713
|
page: 1,
|
|
4285
3714
|
pageSize: 10,
|
|
4286
3715
|
total: 0,
|
|
4287
3716
|
pageCount: 1,
|
|
4288
|
-
});
|
|
4289
|
-
const paginationRef = useRef(null);
|
|
3717
|
+
}));
|
|
4290
3718
|
const [programIdState, setProgramIdState] = useState(this.programId);
|
|
4291
3719
|
const [isOptionSetNameVisibleState, setOptionSetNameVisible] = useState(this.isOptionSetNameVisible);
|
|
4292
3720
|
const [orgUnitState, setOrgUnitState] = useState(this.orgUnit);
|
|
4293
3721
|
const [programStageIdState, setProgramStageIdState] = useState(this.programStageId);
|
|
4294
3722
|
const [attributeFiltersState, setAttributeFiltersState] = useState(this.attributeFilters);
|
|
3723
|
+
const [dataQueryFiltersState, setDataQueryFiltersState] = useState(this.dataQueryFilters);
|
|
4295
3724
|
const [startDateState, setStartDateState] = useState(this.startDate);
|
|
4296
3725
|
const [endDateState, setEndDateState] = useState(this.endDate);
|
|
4297
3726
|
const [loading, setLoading] = useState(false);
|
|
4298
|
-
const [
|
|
3727
|
+
const [metaDataLoadng, setMetaDataLoading] = useState(false);
|
|
4299
3728
|
const [filteredColumns, setFilteredColumns] = useState();
|
|
4300
3729
|
const [inputValues, setInputValues] = useState({});
|
|
4301
|
-
const [filters, setFilters] = useState(false);
|
|
4302
3730
|
const [orgUnitLabel, setOrgUnitLabel] = useState('');
|
|
4303
|
-
//TODO: this will be migrated on the parent component
|
|
4304
|
-
const [checkValue, setCheckValue] = useState([]);
|
|
4305
|
-
const [valueMatch, setValuesMatch] = useState(false);
|
|
4306
3731
|
const [selectedOrgUnit, setSelectedOrgUnit] = useState('');
|
|
4307
3732
|
const [hide, setHide] = useState(true);
|
|
4308
3733
|
const [showAllFilters, setShowAllFilters] = useState(false);
|
|
@@ -4312,6 +3737,8 @@ class LineListTableComponent extends ReactWrapperModule {
|
|
|
4312
3737
|
const defaultOrgUnit = this.orgUnit;
|
|
4313
3738
|
const [prevValue, setPrevValue] = useState();
|
|
4314
3739
|
const [dateStates, setDateStates] = useState({});
|
|
3740
|
+
const [metaData, setMetaData] = useState(null);
|
|
3741
|
+
const d2 = window.d2Web;
|
|
4315
3742
|
// Store updaters in refs for Angular to access
|
|
4316
3743
|
const updateRefs = useRef({
|
|
4317
3744
|
setProgramIdState,
|
|
@@ -4320,7 +3747,6 @@ class LineListTableComponent extends ReactWrapperModule {
|
|
|
4320
3747
|
setAttributeFiltersState,
|
|
4321
3748
|
setStartDateState,
|
|
4322
3749
|
setEndDateState,
|
|
4323
|
-
setIsButtonLoading,
|
|
4324
3750
|
setOptionSetNameVisible,
|
|
4325
3751
|
});
|
|
4326
3752
|
useEffect(() => {
|
|
@@ -4328,64 +3754,83 @@ class LineListTableComponent extends ReactWrapperModule {
|
|
|
4328
3754
|
}, []);
|
|
4329
3755
|
useEffect(() => {
|
|
4330
3756
|
setLoading(true);
|
|
4331
|
-
const
|
|
4332
|
-
|
|
4333
|
-
|
|
4334
|
-
|
|
4335
|
-
|
|
4336
|
-
|
|
4337
|
-
|
|
4338
|
-
let filteredDataColumns = [];
|
|
4339
|
-
if (this.programStageId) {
|
|
4340
|
-
responsePager = response.data.pager;
|
|
4341
|
-
const { columns, data } = getProgramStageData(response, this.programStageId, pager, this.isOptionSetNameVisible);
|
|
4342
|
-
entityColumns = columns;
|
|
4343
|
-
entityData = data;
|
|
4344
|
-
}
|
|
4345
|
-
else if ('trackedEntities' in response.data ||
|
|
4346
|
-
'instances' in response.data) {
|
|
4347
|
-
const responseData = response.data;
|
|
4348
|
-
responsePager = responseData.pager || {
|
|
4349
|
-
page: responseData.page,
|
|
4350
|
-
pageSize: responseData.pageSize,
|
|
4351
|
-
total: responseData.total,
|
|
4352
|
-
pageCount: responseData.pageCount,
|
|
4353
|
-
};
|
|
4354
|
-
const { columns, data, filteredEntityColumns, orgUnitLabel } = getTrackedEntityData(response, this.programId, pager, this.isOptionSetNameVisible, this.filters);
|
|
4355
|
-
entityColumns = columns;
|
|
4356
|
-
entityData = data;
|
|
4357
|
-
setOrgUnitLabel(orgUnitLabel);
|
|
4358
|
-
const checkValues = [
|
|
4359
|
-
...new Set(responseData?.trackedEntities?.[0]?.enrollments?.[0]?.events?.flatMap((event) => event.dataValues
|
|
4360
|
-
.filter((dataValue) => /^[A-Za-z]{3}$/.test(dataValue.value))
|
|
4361
|
-
.map((dataValue) => dataValue.value)) ??
|
|
4362
|
-
responseData?.instances?.[0]?.enrollments?.[0]?.events?.flatMap((event) => event.dataValues
|
|
4363
|
-
.filter((dataValue) => /^[A-Za-z]{3}$/.test(dataValue.value))
|
|
4364
|
-
.map((dataValue) => dataValue.value))),
|
|
4365
|
-
];
|
|
4366
|
-
if (checkValues.length > 0) {
|
|
4367
|
-
setCheckValue(checkValues);
|
|
4368
|
-
setValuesMatch(!checkValues.includes(this.buttonFilter));
|
|
4369
|
-
}
|
|
4370
|
-
setFilteredColumns((prev) => filteredEntityColumns.length > 0 ? filteredEntityColumns : prev);
|
|
4371
|
-
filteredDataColumns = filteredEntityColumns;
|
|
3757
|
+
const fetchmetaData = async () => {
|
|
3758
|
+
try {
|
|
3759
|
+
const trackerResponse = (await d2.trackerModule.trackedEntity
|
|
3760
|
+
.setProgram(this.programId)
|
|
3761
|
+
.getMetaData());
|
|
3762
|
+
const data = trackerResponse;
|
|
3763
|
+
setMetaData(data);
|
|
4372
3764
|
}
|
|
4373
|
-
|
|
4374
|
-
|
|
4375
|
-
const { columns, data } = getEventData(response, pager, this.isOptionSetNameVisible);
|
|
4376
|
-
entityColumns = columns;
|
|
4377
|
-
entityData = data;
|
|
3765
|
+
catch (error) {
|
|
3766
|
+
console.error('Failed to metadata:', error);
|
|
4378
3767
|
}
|
|
4379
|
-
const finalColumns = addActionsColumn([{ label: '#', key: 'index' }, ...entityColumns], this.actionOptions);
|
|
4380
|
-
setLoading(false);
|
|
4381
|
-
setColumns(finalColumns);
|
|
4382
|
-
setData(entityData);
|
|
4383
|
-
setPager(responsePager);
|
|
4384
|
-
});
|
|
4385
|
-
return () => {
|
|
4386
|
-
subscription.unsubscribe(); // Ensure cleanup on unmount
|
|
4387
3768
|
};
|
|
3769
|
+
if (this.programId) {
|
|
3770
|
+
fetchmetaData();
|
|
3771
|
+
}
|
|
3772
|
+
}, []);
|
|
3773
|
+
useEffect(() => {
|
|
3774
|
+
if (!metaData) {
|
|
3775
|
+
return undefined;
|
|
3776
|
+
}
|
|
3777
|
+
setLoading(true);
|
|
3778
|
+
const isTracker = metaData.programType === 'WITH_REGISTRATION';
|
|
3779
|
+
const endDate = endDateState ?? new Date().toISOString().split('T')[0];
|
|
3780
|
+
if (isTracker) {
|
|
3781
|
+
d2.trackerModule.trackedEntity
|
|
3782
|
+
.setEndDate(endDate)
|
|
3783
|
+
.setStartDate(startDateState)
|
|
3784
|
+
.setProgram(this.programId)
|
|
3785
|
+
.setOrgUnit(orgUnitState)
|
|
3786
|
+
.setOuMode(this.ouMode)
|
|
3787
|
+
.setFilters(dataQueryFiltersState)
|
|
3788
|
+
.setPagination(new Pager({
|
|
3789
|
+
pageSize: pager.pageSize,
|
|
3790
|
+
page: pager.page,
|
|
3791
|
+
}))
|
|
3792
|
+
.setOrderCriterias([
|
|
3793
|
+
new DataOrderCriteria().setField('createdAt').setOrder('desc'),
|
|
3794
|
+
])
|
|
3795
|
+
.get()
|
|
3796
|
+
.then((response) => {
|
|
3797
|
+
const trackedEntityInstances = Array.isArray(response.data)
|
|
3798
|
+
? response.data
|
|
3799
|
+
: [response.data];
|
|
3800
|
+
const orgUnitIdsFromEnrollments = new Set(trackedEntityInstances.map((tei) => tei.latestEnrollment.orgUnit));
|
|
3801
|
+
const uniqueOrgUnitIds = [...orgUnitIdsFromEnrollments];
|
|
3802
|
+
this.lineListService.fetchOrgUnits(uniqueOrgUnitIds).subscribe({
|
|
3803
|
+
next: (fetchedOrgUnits) => {
|
|
3804
|
+
const trackedEntityResponse = {
|
|
3805
|
+
trackedEntityInstances: response.data,
|
|
3806
|
+
pager: pager,
|
|
3807
|
+
orgUnitsMap: fetchedOrgUnits,
|
|
3808
|
+
};
|
|
3809
|
+
const { columns, data, filteredEntityColumns, orgUnitLabel } = getTrackedEntityTableData({ data: trackedEntityResponse }, this.programId, pager, metaData);
|
|
3810
|
+
setFilteredColumns((prev) => filteredEntityColumns.length > 0
|
|
3811
|
+
? filteredEntityColumns
|
|
3812
|
+
: prev);
|
|
3813
|
+
const finalColumns = addActionsColumn([{ label: '#', key: 'index' }, ...columns], this.actionOptions);
|
|
3814
|
+
const pagerResponse = response.pagination;
|
|
3815
|
+
setLoading(false);
|
|
3816
|
+
setColumns(finalColumns);
|
|
3817
|
+
setData(data);
|
|
3818
|
+
setPager(new Pager(pagerResponse || {}));
|
|
3819
|
+
setOrgUnitLabel(orgUnitLabel);
|
|
3820
|
+
},
|
|
3821
|
+
error: (err) => {
|
|
3822
|
+
console.error('Error fetching org units:', err);
|
|
3823
|
+
setLoading(false);
|
|
3824
|
+
},
|
|
3825
|
+
});
|
|
3826
|
+
});
|
|
3827
|
+
}
|
|
3828
|
+
else {
|
|
3829
|
+
//TODO: TO IMPLEMEMNT EVENT QUERY FOR FILTERING EVENTS WHEN PROGRAM STAGE IS PASSED OR DEALING WITH EVENT PROGRAM USING TRACKER SDK QUERY
|
|
3830
|
+
}
|
|
3831
|
+
;
|
|
4388
3832
|
}, [
|
|
3833
|
+
metaData,
|
|
4389
3834
|
programIdState,
|
|
4390
3835
|
orgUnitState,
|
|
4391
3836
|
programStageIdState,
|
|
@@ -4395,50 +3840,25 @@ class LineListTableComponent extends ReactWrapperModule {
|
|
|
4395
3840
|
pager.page,
|
|
4396
3841
|
pager.pageSize,
|
|
4397
3842
|
isOptionSetNameVisibleState,
|
|
3843
|
+
dataQueryFiltersState,
|
|
4398
3844
|
]);
|
|
4399
|
-
const handleApprovalClick = () => {
|
|
4400
|
-
setIsButtonLoading(true);
|
|
4401
|
-
const subscription = this.lineListService
|
|
4402
|
-
.getLineListData(this.programId, this.orgUnit, this.programStageId, pager.page, 1000, this.attributeFilters, this.startDate, this.endDate, this.ouMode)
|
|
4403
|
-
.pipe(take(1))
|
|
4404
|
-
.subscribe((response) => {
|
|
4405
|
-
if ('trackedEntities' in response.data ||
|
|
4406
|
-
'instances' in response.data) {
|
|
4407
|
-
const trackedEntityInstances = response.data.trackedEntities;
|
|
4408
|
-
// Map TEIs to objects with teiId and enrollmentId
|
|
4409
|
-
const teiEnrollmentList = trackedEntityInstances
|
|
4410
|
-
.map((tei) => {
|
|
4411
|
-
const matchingEnrollment = tei.enrollments?.find((enrollment) => enrollment.program === this.programId);
|
|
4412
|
-
return matchingEnrollment
|
|
4413
|
-
? {
|
|
4414
|
-
teiId: tei.trackedEntity,
|
|
4415
|
-
enrollmentId: matchingEnrollment.enrollment,
|
|
4416
|
-
}
|
|
4417
|
-
: null;
|
|
4418
|
-
})
|
|
4419
|
-
.filter(Boolean);
|
|
4420
|
-
this.approvalSelected.emit(teiEnrollmentList);
|
|
4421
|
-
}
|
|
4422
|
-
else {
|
|
4423
|
-
this.approvalSelected.emit([]);
|
|
4424
|
-
}
|
|
4425
|
-
setIsButtonLoading(false);
|
|
4426
|
-
});
|
|
4427
|
-
return () => {
|
|
4428
|
-
subscription.unsubscribe();
|
|
4429
|
-
};
|
|
4430
|
-
};
|
|
4431
3845
|
const handleInputChange = (key, value) => {
|
|
4432
3846
|
setInputValues((prevValues) => ({
|
|
4433
3847
|
...prevValues,
|
|
4434
3848
|
[key]: value ?? '',
|
|
4435
3849
|
}));
|
|
4436
|
-
|
|
3850
|
+
setDataQueryFiltersState((prevFilters) => {
|
|
4437
3851
|
// Remove old filter for this key
|
|
4438
3852
|
const filteredFilters = prevFilters.filter((f) => f.attribute !== key);
|
|
4439
3853
|
// Only add new filter if value is not empty
|
|
4440
3854
|
const updatedFilters = value.trim()
|
|
4441
|
-
? [
|
|
3855
|
+
? [
|
|
3856
|
+
...filteredFilters,
|
|
3857
|
+
new DataQueryFilter()
|
|
3858
|
+
.setAttribute(key)
|
|
3859
|
+
.setCondition(DataFilterCondition.Like)
|
|
3860
|
+
.setValue(value),
|
|
3861
|
+
]
|
|
4442
3862
|
: filteredFilters;
|
|
4443
3863
|
return updatedFilters;
|
|
4444
3864
|
});
|
|
@@ -4449,175 +3869,69 @@ class LineListTableComponent extends ReactWrapperModule {
|
|
|
4449
3869
|
...prevValues,
|
|
4450
3870
|
[key]: value ?? '',
|
|
4451
3871
|
}));
|
|
4452
|
-
|
|
4453
|
-
// Remove
|
|
3872
|
+
setDataQueryFiltersState((prevFilters = []) => {
|
|
3873
|
+
// Remove existing filter for the same key (attribute)
|
|
4454
3874
|
const filteredFilters = prevFilters.filter((f) => f.attribute !== key);
|
|
4455
3875
|
// Only add new filter if value is not empty
|
|
4456
3876
|
const updatedFilters = value.trim()
|
|
4457
|
-
? [
|
|
3877
|
+
? [
|
|
3878
|
+
...filteredFilters,
|
|
3879
|
+
new DataQueryFilter()
|
|
3880
|
+
.setAttribute(key)
|
|
3881
|
+
.setCondition(DataFilterCondition.Equal)
|
|
3882
|
+
.setValue(value),
|
|
3883
|
+
]
|
|
4458
3884
|
: filteredFilters;
|
|
4459
3885
|
return updatedFilters;
|
|
4460
3886
|
});
|
|
4461
3887
|
};
|
|
4462
3888
|
const handleDateSelect = (key, selectedDate) => {
|
|
4463
|
-
const selectedDateString = selectedDate?.calendarDateString ?? '';
|
|
3889
|
+
const selectedDateString = selectedDate?.calendarDateString ?? '';
|
|
4464
3890
|
// Update dateStates
|
|
4465
3891
|
setDateStates((prevDateStates) => ({
|
|
4466
3892
|
...prevDateStates,
|
|
4467
|
-
[key]: selectedDateString,
|
|
3893
|
+
[key]: selectedDateString,
|
|
4468
3894
|
}));
|
|
4469
|
-
// Update
|
|
4470
|
-
|
|
4471
|
-
|
|
4472
|
-
const filteredFilters = prevFilters.filter((f) => f.attribute !== key);
|
|
4473
|
-
// Only add a filter if the date is not empty
|
|
3895
|
+
// Update dataQueryFilters
|
|
3896
|
+
setDataQueryFiltersState((prevFilters) => {
|
|
3897
|
+
const filteredFilters = (prevFilters || []).filter((f) => f.attribute !== key);
|
|
4474
3898
|
const updatedFilters = selectedDateString.trim()
|
|
4475
3899
|
? [
|
|
4476
3900
|
...filteredFilters,
|
|
4477
|
-
|
|
3901
|
+
new DataQueryFilter()
|
|
3902
|
+
.setAttribute(key)
|
|
3903
|
+
.setCondition(DataFilterCondition.Equal)
|
|
3904
|
+
.setValue(selectedDateString),
|
|
4478
3905
|
]
|
|
4479
|
-
: filteredFilters;
|
|
3906
|
+
: filteredFilters;
|
|
4480
3907
|
return updatedFilters;
|
|
4481
3908
|
});
|
|
4482
3909
|
};
|
|
4483
|
-
|
|
4484
|
-
|
|
4485
|
-
|
|
4486
|
-
|
|
4487
|
-
|
|
4488
|
-
|
|
4489
|
-
|
|
4490
|
-
|
|
4491
|
-
|
|
4492
|
-
|
|
4493
|
-
|
|
4494
|
-
|
|
4495
|
-
|
|
4496
|
-
|
|
4497
|
-
|
|
4498
|
-
|
|
4499
|
-
|
|
4500
|
-
|
|
4501
|
-
|
|
4502
|
-
|
|
4503
|
-
|
|
4504
|
-
|
|
4505
|
-
|
|
4506
|
-
|
|
4507
|
-
React__default.createElement(
|
|
4508
|
-
React__default.createElement(Modal$1, { hide: hide, position: "middle" },
|
|
4509
|
-
React__default.createElement(ModalTitle$1, null, "Select organization unit"),
|
|
4510
|
-
React__default.createElement(ModalContent$1, null,
|
|
4511
|
-
React__default.createElement(OrgUnitFormField$1, { key: selectedOrgUnit, onSelectOrgUnit: (selectedOrgUnit) => {
|
|
4512
|
-
setSelectedOrgUnit(selectedOrgUnit.displayName);
|
|
4513
|
-
setOrgUnitState(selectedOrgUnit.id);
|
|
4514
|
-
setHide(true);
|
|
4515
|
-
} })),
|
|
4516
|
-
React__default.createElement(ModalActions$1, null,
|
|
4517
|
-
React__default.createElement(ButtonStrip$1, { end: true },
|
|
4518
|
-
React__default.createElement(Button$1, { onClick: () => setHide(true), secondary: true }, "Close")))),
|
|
4519
|
-
this.showFilters && (React__default.createElement(DataTableToolbar, { className: "table-top-toolbar" },
|
|
4520
|
-
React__default.createElement("div", { style: {
|
|
4521
|
-
display: 'flex',
|
|
4522
|
-
alignItems: 'center',
|
|
4523
|
-
gap: '10px',
|
|
4524
|
-
flexWrap: 'wrap',
|
|
4525
|
-
} },
|
|
4526
|
-
React__default.createElement(InputField$1, { key: "location",
|
|
4527
|
-
//label={orgUnitLabel}
|
|
4528
|
-
label: orgUnitLabel ? orgUnitLabel : 'registering unit', value: selectedOrgUnit, onFocus: () => setHide(false), className: "custom-input", onChange: (event) => {
|
|
4529
|
-
setSelectedOrgUnit(event.value);
|
|
4530
|
-
setOrgUnitState(defaultOrgUnit);
|
|
4531
|
-
} }),
|
|
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) => {
|
|
4533
|
-
if (selectedDate?.calendarDateString) {
|
|
4534
|
-
setStartDateState(selectedDate.calendarDateString);
|
|
4535
|
-
}
|
|
4536
|
-
// setStartDateState(selectedDate.calendarDateString);
|
|
4537
|
-
} }),
|
|
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) => {
|
|
4539
|
-
setEndDateState(selectedDate.calendarDateString);
|
|
4540
|
-
} }),
|
|
4541
|
-
(visibleFilters ?? []).map(({ label, key, valueType, options }) => {
|
|
4542
|
-
// Render CalendarInput for DATE fields
|
|
4543
|
-
if (valueType === 'DATE') {
|
|
4544
|
-
return (React__default.createElement(CalendarInput, { key: key, label: `${label}:`, calendar: "gregory", locale: "en-GB", timeZone: "Africa/Dar_es_Salaam", className: "custom-input", date: dateStates[key] || '', onDateSelect: (selectedDate) => handleDateSelect(key, selectedDate) }));
|
|
4545
|
-
}
|
|
4546
|
-
// Render SingleSelectField if options exist
|
|
4547
|
-
if (options && options.options.length > 0) {
|
|
4548
|
-
return (React__default.createElement(SingleSelectField, { key: key, label: `${label}:`, selected: inputValues[key] || '', className: "custom-select-input", clearable: true, onChange: ({ selected }) => {
|
|
4549
|
-
setInputValues((prevValues) => ({
|
|
4550
|
-
...prevValues,
|
|
4551
|
-
[key]: selected ?? '',
|
|
4552
|
-
}));
|
|
4553
|
-
handleInputChangeForSelectField(key, selected ?? '');
|
|
4554
|
-
} }, (options.options ?? []).map((opt) => (React__default.createElement(SingleSelectOption, { key: opt.id, label: opt.name, value: opt.code })))));
|
|
4555
|
-
}
|
|
4556
|
-
// Fallback: default InputField
|
|
4557
|
-
return (React__default.createElement(InputField$1, { key: key, label: `${label}:`, className: "custom-input", value: inputValues[key] || '', clearable: true, onChange: (e) => {
|
|
4558
|
-
let currentValue = '';
|
|
4559
|
-
if ('target' in e && e.target) {
|
|
4560
|
-
currentValue = e.target.value;
|
|
4561
|
-
}
|
|
4562
|
-
else if ('value' in e) {
|
|
4563
|
-
currentValue = e.value ?? '';
|
|
4564
|
-
}
|
|
4565
|
-
setInputValues((prevValues) => ({
|
|
4566
|
-
...prevValues,
|
|
4567
|
-
[key]: currentValue,
|
|
4568
|
-
}));
|
|
4569
|
-
if (currentValue === '') {
|
|
4570
|
-
handleInputChange(key, '');
|
|
4571
|
-
}
|
|
4572
|
-
}, onBlur: (e) => {
|
|
4573
|
-
let currentValue = '';
|
|
4574
|
-
if ('target' in e && e.target) {
|
|
4575
|
-
currentValue = e.target.value;
|
|
4576
|
-
}
|
|
4577
|
-
else if ('value' in e) {
|
|
4578
|
-
currentValue = e.value ?? '';
|
|
4579
|
-
}
|
|
4580
|
-
if (currentValue !== '' &&
|
|
4581
|
-
currentValue !== prevValue) {
|
|
4582
|
-
handleInputChange(key, currentValue);
|
|
4583
|
-
setPrevValue(currentValue);
|
|
4584
|
-
}
|
|
4585
|
-
} }));
|
|
4586
|
-
}),
|
|
4587
|
-
React__default.createElement(Button$1, { onClick: () => setShowAllFilters(!showAllFilters) }, showAllFilters ? 'Less Filters' : 'More Filters')))),
|
|
4588
|
-
React__default.createElement(DataTable, null,
|
|
4589
|
-
React__default.createElement(TableHead, null,
|
|
4590
|
-
React__default.createElement(DataTableRow, null, columns.map((col) => (React__default.createElement(DataTableColumnHeader, { key: col.key }, col.label))))),
|
|
4591
|
-
React__default.createElement(TableBody, null, data.length > 0 ? (data.map((row) => (React__default.createElement(DataTableRow, { key: row.index }, columns.map((col) => (React__default.createElement(DataTableCell, { key: col.key }, col.key === 'actions'
|
|
4592
|
-
? this.actionOptions && (React__default.createElement(DataTableActions, { actionOptions: this.actionOptions, actionOptionOrientation: this.actionOptionOrientation, onClick: (option) => {
|
|
4593
|
-
if (option.onClick) {
|
|
4594
|
-
option.onClick(row);
|
|
4595
|
-
}
|
|
4596
|
-
this.actionSelected.emit({
|
|
4597
|
-
action: option.label,
|
|
4598
|
-
row,
|
|
4599
|
-
});
|
|
4600
|
-
} }))
|
|
4601
|
-
: row[col.key] || '--' // Display '--' if value is undefined or null
|
|
4602
|
-
))))))) : (React__default.createElement(DataTableRow, null,
|
|
4603
|
-
React__default.createElement(DataTableCell, { colSpan: columns.length?.toString(), style: {
|
|
4604
|
-
textAlign: 'center',
|
|
4605
|
-
fontWeight: 'bold',
|
|
4606
|
-
color: 'grey',
|
|
4607
|
-
padding: '20px',
|
|
4608
|
-
} }, "No data found")))),
|
|
4609
|
-
React__default.createElement(TableFoot, null,
|
|
4610
|
-
React__default.createElement(DataTableRow, null,
|
|
4611
|
-
React__default.createElement(DataTableCell, { colSpan: columns.length.toString() },
|
|
4612
|
-
React__default.createElement("div", null,
|
|
4613
|
-
React__default.createElement(Pagination, { page: pager.page, pageCount: pager.pageCount, pageSize: pager.pageSize, total: pager.total, onPageChange: (page) => setPager((prev) => ({ ...prev, page })), onPageSizeChange: (pageSize) => {
|
|
4614
|
-
const newPageSize = Number(pageSize);
|
|
4615
|
-
setPager((prev) => ({
|
|
4616
|
-
...prev,
|
|
4617
|
-
page: 1,
|
|
4618
|
-
pageSize: newPageSize,
|
|
4619
|
-
}));
|
|
4620
|
-
}, pageSizes: ['10', '20', '50', '100', '500'] }))))))))));
|
|
3910
|
+
function getTextColorFromBackGround(hex) {
|
|
3911
|
+
// Remove the hash if present
|
|
3912
|
+
hex = hex.replace('#', '');
|
|
3913
|
+
// Convert to RGB
|
|
3914
|
+
const r = parseInt(hex.substr(0, 2), 16);
|
|
3915
|
+
const g = parseInt(hex.substr(2, 2), 16);
|
|
3916
|
+
const b = parseInt(hex.substr(4, 2), 16);
|
|
3917
|
+
// YIQ formula to calculate brightness
|
|
3918
|
+
const yiq = (r * 299 + g * 587 + b * 114) / 1000;
|
|
3919
|
+
// Return black for light backgrounds, white for dark backgrounds
|
|
3920
|
+
return yiq >= 128 ? colors$1.grey700 : '#FFFFFF';
|
|
3921
|
+
}
|
|
3922
|
+
return (React__default.createElement("div", null, loading ? (React__default.createElement("div", { style: {
|
|
3923
|
+
display: 'flex',
|
|
3924
|
+
alignItems: 'center',
|
|
3925
|
+
gap: 8,
|
|
3926
|
+
padding: 8,
|
|
3927
|
+
} },
|
|
3928
|
+
React__default.createElement(CircularLoader$1, { small: true }),
|
|
3929
|
+
React__default.createElement("div", { style: {
|
|
3930
|
+
fontSize: 14,
|
|
3931
|
+
} }, "Loading"))) : (React__default.createElement("div", null,
|
|
3932
|
+
React__default.createElement(OrgUnitSelector, { hide: hide, setHide: setHide, selectedOrgUnit: selectedOrgUnit, setSelectedOrgUnit: setSelectedOrgUnit, setOrgUnitState: setOrgUnitState }),
|
|
3933
|
+
this.showFilters && (React__default.createElement(FilterToolbar, { orgUnitLabel: orgUnitLabel, selectedOrgUnit: selectedOrgUnit, setSelectedOrgUnit: setSelectedOrgUnit, setOrgUnitState: setOrgUnitState, defaultOrgUnit: defaultOrgUnit, setHide: setHide, startDateState: startDateState, setStartDateState: setStartDateState, endDateState: endDateState, setEndDateState: setEndDateState, visibleFilters: visibleFilters, dateStates: dateStates, inputValues: inputValues, setInputValues: setInputValues, handleInputChange: handleInputChange, handleInputChangeForSelectField: handleInputChangeForSelectField, handleDateSelect: handleDateSelect, prevValue: prevValue, setPrevValue: setPrevValue, showAllFilters: showAllFilters, setShowAllFilters: setShowAllFilters })),
|
|
3934
|
+
React__default.createElement(LineListTable, { columns: columns, data: data, pager: pager, setPager: setPager, getTextColorFromBackGround: getTextColorFromBackGround, actionOptions: this.actionOptions, actionOptionOrientation: this.actionOptionOrientation, actionSelected: this.actionSelected })))));
|
|
4621
3935
|
};
|
|
4622
3936
|
}
|
|
4623
3937
|
ngOnChanges(changes) {
|
|
@@ -4656,7 +3970,7 @@ class LineListTableComponent extends ReactWrapperModule {
|
|
|
4656
3970
|
this.render();
|
|
4657
3971
|
}
|
|
4658
3972
|
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.1.8", ngImport: i0, type: LineListTableComponent, deps: null, target: i0.ɵɵFactoryTarget.Component }); }
|
|
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",
|
|
3973
|
+
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", dataQueryFilters: "dataQueryFilters", ouMode: "ouMode", isButtonLoading: "isButtonLoading", buttonFilter: "buttonFilter", filterRootOrgUnit: "filterRootOrgUnit", showFilters: "showFilters", isOptionSetNameVisible: "isOptionSetNameVisible" }, outputs: { actionSelected: "actionSelected", approvalSelected: "approvalSelected" }, 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"] }); }
|
|
4660
3974
|
}
|
|
4661
3975
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.1.8", ngImport: i0, type: LineListTableComponent, decorators: [{
|
|
4662
3976
|
type: Component,
|
|
@@ -4679,22 +3993,16 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.1.8", ngImpor
|
|
|
4679
3993
|
type: Input
|
|
4680
3994
|
}], endDate: [{
|
|
4681
3995
|
type: Input
|
|
4682
|
-
}],
|
|
3996
|
+
}], dataQueryFilters: [{
|
|
4683
3997
|
type: Input
|
|
4684
3998
|
}], ouMode: [{
|
|
4685
3999
|
type: Input
|
|
4686
|
-
}], dispatchTeis: [{
|
|
4687
|
-
type: Input
|
|
4688
4000
|
}], actionSelected: [{
|
|
4689
4001
|
type: Output
|
|
4690
4002
|
}], approvalSelected: [{
|
|
4691
4003
|
type: Output
|
|
4692
4004
|
}], isButtonLoading: [{
|
|
4693
4005
|
type: Input
|
|
4694
|
-
}], buttonLabel: [{
|
|
4695
|
-
type: Input
|
|
4696
|
-
}], firstValue: [{
|
|
4697
|
-
type: Output
|
|
4698
4006
|
}], buttonFilter: [{
|
|
4699
4007
|
type: Input
|
|
4700
4008
|
}], filterRootOrgUnit: [{
|
|
@@ -4874,7 +4182,7 @@ class DataTableUIComponent extends ReactWrapperModule {
|
|
|
4874
4182
|
React__default.createElement(DataTableRow, null,
|
|
4875
4183
|
columns.map((col) => (React__default.createElement(DataTableColumnHeader, { key: col.column }, col.display))),
|
|
4876
4184
|
this.actionOptions && this.actionOptions.length > 0 && (React__default.createElement(DataTableColumnHeader, null, "Actions")))),
|
|
4877
|
-
React__default.createElement(TableBody, null, tableData.map((row, rowIndex) => (React__default.createElement(DataTableRow, { key: rowIndex },
|
|
4185
|
+
React__default.createElement(TableBody$1, null, tableData.map((row, rowIndex) => (React__default.createElement(DataTableRow, { key: rowIndex },
|
|
4878
4186
|
columns.map((col) => (React__default.createElement(DataTableCell, { key: col.column }, row[col.column] || '-'))),
|
|
4879
4187
|
this.actionOptions && this.actionOptions.length > 0 && (React__default.createElement(DataTableCell, null,
|
|
4880
4188
|
React__default.createElement(DropdownMenu, { dropdownOptions: getDropdownOptions(row), onClick: (option) => option.onClick?.(row) }))))))),
|
|
@@ -7905,28 +7213,29 @@ class ProgramEntryFormMetaData {
|
|
|
7905
7213
|
return metaData;
|
|
7906
7214
|
}
|
|
7907
7215
|
get formFields() {
|
|
7908
|
-
if (!this.
|
|
7216
|
+
if (!this.program) {
|
|
7909
7217
|
return [];
|
|
7910
7218
|
}
|
|
7911
|
-
return new ProgramEntryFormFieldUtil(this.
|
|
7219
|
+
return new ProgramEntryFormFieldUtil(this.program, this.config).fields;
|
|
7912
7220
|
}
|
|
7913
7221
|
get sections() {
|
|
7914
|
-
if (!this.
|
|
7222
|
+
if (!this.program || this.config.displayType !== 'SECTION') {
|
|
7915
7223
|
return [];
|
|
7916
7224
|
}
|
|
7917
|
-
return new ProgramEntryFormSectionUtil(this.
|
|
7225
|
+
return new ProgramEntryFormSectionUtil(this.program, this.config).sections;
|
|
7918
7226
|
}
|
|
7919
7227
|
get rules() {
|
|
7920
|
-
if (!this.
|
|
7228
|
+
if (!this.program || !this.program.programRules) {
|
|
7921
7229
|
return [];
|
|
7922
7230
|
}
|
|
7923
|
-
return this.
|
|
7231
|
+
return this.program.programRules.map((programRule) => new MetadataRule(programRule, this.program.programRuleVariables || []).toJson());
|
|
7924
7232
|
}
|
|
7925
7233
|
toJson() {
|
|
7926
7234
|
return {
|
|
7927
|
-
id: this.
|
|
7928
|
-
name: this.
|
|
7929
|
-
description: this.
|
|
7235
|
+
id: this.program?.id,
|
|
7236
|
+
name: this.program?.name,
|
|
7237
|
+
description: this.program?.description,
|
|
7238
|
+
program: this.program,
|
|
7930
7239
|
formFields: this.formFields,
|
|
7931
7240
|
sections: this.sections,
|
|
7932
7241
|
rules: this.rules,
|
|
@@ -7934,9 +7243,9 @@ class ProgramEntryFormMetaData {
|
|
|
7934
7243
|
}
|
|
7935
7244
|
async get() {
|
|
7936
7245
|
try {
|
|
7937
|
-
const
|
|
7938
|
-
if (
|
|
7939
|
-
this.
|
|
7246
|
+
const program = await this.#getProgramMetaData();
|
|
7247
|
+
if (program) {
|
|
7248
|
+
this.program = program;
|
|
7940
7249
|
return this.toJson();
|
|
7941
7250
|
}
|
|
7942
7251
|
return null;
|
|
@@ -8084,11 +7393,19 @@ class ProgramEntryFormModule {
|
|
|
8084
7393
|
this.instanceQuery = this.d2.trackerModule.trackedEntity
|
|
8085
7394
|
.setProgram(this.config().program)
|
|
8086
7395
|
.setOrgUnit(this.orgUnit());
|
|
8087
|
-
|
|
8088
|
-
|
|
8089
|
-
|
|
8090
|
-
|
|
8091
|
-
|
|
7396
|
+
if (!this.trackedEntity) {
|
|
7397
|
+
return await this.instanceQuery.create();
|
|
7398
|
+
}
|
|
7399
|
+
const instance = (await this.instanceQuery
|
|
7400
|
+
.setTrackedEntity(this.trackedEntity())
|
|
7401
|
+
.get()).data;
|
|
7402
|
+
if (!instance) {
|
|
7403
|
+
return await this.instanceQuery.create();
|
|
7404
|
+
}
|
|
7405
|
+
if (this.metaData()?.program) {
|
|
7406
|
+
instance.setFields(this.metaData().program);
|
|
7407
|
+
}
|
|
7408
|
+
return instance;
|
|
8092
7409
|
}
|
|
8093
7410
|
async #getEventInstance() {
|
|
8094
7411
|
this.instanceQuery = this.d2.eventModule.event
|
|
@@ -8113,11 +7430,11 @@ class ProgramEntryFormModule {
|
|
|
8113
7430
|
}
|
|
8114
7431
|
}
|
|
8115
7432
|
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.1.8", ngImport: i0, type: ProgramEntryFormModule, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
|
|
8116
|
-
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "19.1.8", type: ProgramEntryFormModule, isStandalone: true, selector: "ng-dhis2-ui-program-entry-form", inputs: { config: { classPropertyName: "config", publicName: "config", isSignal: true, isRequired: true, transformFunction: null }, trackedEntity: { classPropertyName: "trackedEntity", publicName: "trackedEntity", isSignal: true, isRequired: false, transformFunction: null }, event: { classPropertyName: "event", publicName: "event", isSignal: true, isRequired: false, transformFunction: null }, enrollment: { classPropertyName: "enrollment", publicName: "enrollment", isSignal: true, isRequired: false, transformFunction: null }, orgUnit: { classPropertyName: "orgUnit", publicName: "orgUnit", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { instanceSave: "instanceSave", instanceSaveCompleted: "instanceSaveCompleted", instanceUpdate: "instanceUpdate", formValidityUpdate: "formValidityUpdate", formCancel: "formCancel" }, ngImport: i0, template: "@if (loading()) {\n<div className=\"program-entry__form-loader\">\n <ng-dhis2-ui-wrapper [component]=\"FormLoader\" />\n</div>\n} @else if(metaData()) {\n\n<div>\n <!-- Form content -->\n @switch (config().displayType) {\n\n <!-- Flat display -->\n @case ('FLAT') {\n <ng-dhis2-ui-flat-form\n [name]=\"metaData()!.name\"\n [dataValues]=\"instance()!\"\n [rules]=\"metaData()!.rules\"\n [fields]=\"metaData()!.formFields\"\n (formUpdate)=\"onFormUpdate($event)\"\n (formValidityUpdate)=\"onValidityUpdate($event)\"\n />\n }\n\n <!-- SECTION display -->\n @case ('SECTION') { Section form }\n\n <!-- CUSTOM FORM -->\n @case ('CUSTOM') { } }\n\n <!-- Action buttons -->\n\n @if(!config().hideActionButtons) {\n <ng-dhis2-ui-wrapper [component]=\"FormActionButtons()\" />\n }\n</div>\n}\n", styles: ["::ng-deep .program-entry__form-loader{padding:8px}\n"], dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "ngmodule", type: D2FormModule }, { kind: "component", type: FlatFormComponent, selector: "ng-dhis2-ui-flat-form" }, { kind: "directive", type: ReactWrapperModule, selector: "ng-dhis2-ui-wrapper", inputs: ["props", "component"] }] }); }
|
|
7433
|
+
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "19.1.8", type: ProgramEntryFormModule, isStandalone: true, selector: "ng-dhis2-ui-program-entry-form", inputs: { config: { classPropertyName: "config", publicName: "config", isSignal: true, isRequired: true, transformFunction: null }, trackedEntity: { classPropertyName: "trackedEntity", publicName: "trackedEntity", isSignal: true, isRequired: false, transformFunction: null }, event: { classPropertyName: "event", publicName: "event", isSignal: true, isRequired: false, transformFunction: null }, enrollment: { classPropertyName: "enrollment", publicName: "enrollment", isSignal: true, isRequired: false, transformFunction: null }, orgUnit: { classPropertyName: "orgUnit", publicName: "orgUnit", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { instanceSave: "instanceSave", instanceSaveCompleted: "instanceSaveCompleted", instanceUpdate: "instanceUpdate", formValidityUpdate: "formValidityUpdate", formCancel: "formCancel" }, ngImport: i0, template: "@if (loading()) {\n<div className=\"program-entry__form-loader\">\n <ng-dhis2-ui-wrapper [component]=\"FormLoader\" />\n</div>\n} @else if(metaData()) {\n\n<div>\n <!-- Form content -->\n @switch (config().displayType) {\n\n <!-- Flat display -->\n @case ('FLAT') {\n\n <ng-dhis2-ui-flat-form\n [name]=\"metaData()!.name\"\n [dataValues]=\"instance()!\"\n [rules]=\"metaData()!.rules\"\n [fields]=\"metaData()!.formFields\"\n (formUpdate)=\"onFormUpdate($event)\"\n (formValidityUpdate)=\"onValidityUpdate($event)\"\n />\n }\n\n <!-- SECTION display -->\n @case ('SECTION') { Section form }\n\n <!-- CUSTOM FORM -->\n @case ('CUSTOM') { } }\n\n <!-- Action buttons -->\n\n @if(!config().hideActionButtons) {\n <ng-dhis2-ui-wrapper [component]=\"FormActionButtons()\" />\n }\n</div>\n}\n", styles: ["::ng-deep .program-entry__form-loader{padding:8px}\n"], dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "ngmodule", type: D2FormModule }, { kind: "component", type: FlatFormComponent, selector: "ng-dhis2-ui-flat-form" }, { kind: "directive", type: ReactWrapperModule, selector: "ng-dhis2-ui-wrapper", inputs: ["props", "component"] }] }); }
|
|
8117
7434
|
}
|
|
8118
7435
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.1.8", ngImport: i0, type: ProgramEntryFormModule, decorators: [{
|
|
8119
7436
|
type: Component,
|
|
8120
|
-
args: [{ selector: 'ng-dhis2-ui-program-entry-form', imports: [CommonModule, D2FormModule, ReactWrapperModule], template: "@if (loading()) {\n<div className=\"program-entry__form-loader\">\n <ng-dhis2-ui-wrapper [component]=\"FormLoader\" />\n</div>\n} @else if(metaData()) {\n\n<div>\n <!-- Form content -->\n @switch (config().displayType) {\n\n <!-- Flat display -->\n @case ('FLAT') {\n <ng-dhis2-ui-flat-form\n [name]=\"metaData()!.name\"\n [dataValues]=\"instance()!\"\n [rules]=\"metaData()!.rules\"\n [fields]=\"metaData()!.formFields\"\n (formUpdate)=\"onFormUpdate($event)\"\n (formValidityUpdate)=\"onValidityUpdate($event)\"\n />\n }\n\n <!-- SECTION display -->\n @case ('SECTION') { Section form }\n\n <!-- CUSTOM FORM -->\n @case ('CUSTOM') { } }\n\n <!-- Action buttons -->\n\n @if(!config().hideActionButtons) {\n <ng-dhis2-ui-wrapper [component]=\"FormActionButtons()\" />\n }\n</div>\n}\n", styles: ["::ng-deep .program-entry__form-loader{padding:8px}\n"] }]
|
|
7437
|
+
args: [{ selector: 'ng-dhis2-ui-program-entry-form', imports: [CommonModule, D2FormModule, ReactWrapperModule], template: "@if (loading()) {\n<div className=\"program-entry__form-loader\">\n <ng-dhis2-ui-wrapper [component]=\"FormLoader\" />\n</div>\n} @else if(metaData()) {\n\n<div>\n <!-- Form content -->\n @switch (config().displayType) {\n\n <!-- Flat display -->\n @case ('FLAT') {\n\n <ng-dhis2-ui-flat-form\n [name]=\"metaData()!.name\"\n [dataValues]=\"instance()!\"\n [rules]=\"metaData()!.rules\"\n [fields]=\"metaData()!.formFields\"\n (formUpdate)=\"onFormUpdate($event)\"\n (formValidityUpdate)=\"onValidityUpdate($event)\"\n />\n }\n\n <!-- SECTION display -->\n @case ('SECTION') { Section form }\n\n <!-- CUSTOM FORM -->\n @case ('CUSTOM') { } }\n\n <!-- Action buttons -->\n\n @if(!config().hideActionButtons) {\n <ng-dhis2-ui-wrapper [component]=\"FormActionButtons()\" />\n }\n</div>\n}\n", styles: ["::ng-deep .program-entry__form-loader{padding:8px}\n"] }]
|
|
8121
7438
|
}], propDecorators: { instanceSave: [{
|
|
8122
7439
|
type: Output
|
|
8123
7440
|
}], instanceSaveCompleted: [{
|