@iapps/ng-dhis2-ui 1.2.166 → 1.2.167

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.
@@ -4300,6 +4300,29 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.1.3", ngImpor
4300
4300
  type: Injectable
4301
4301
  }] });
4302
4302
 
4303
+ const getOptionCode = (option) => option.code ?? option.value ?? option.id;
4304
+ const getMultiOptionCodes = (value) => {
4305
+ if (Array.isArray(value)) {
4306
+ return value
4307
+ .map((item) => String(item).trim())
4308
+ .filter((item) => item.length > 0);
4309
+ }
4310
+ if (typeof value !== 'string') {
4311
+ return value == null ? [] : [String(value)];
4312
+ }
4313
+ return value
4314
+ .split(/[;,]/)
4315
+ .map((item) => item.trim())
4316
+ .filter((item) => item.length > 0);
4317
+ };
4318
+ const formatMultiTextOptionValue = (value, options = []) => {
4319
+ const optionByCode = new Map(options
4320
+ .map((option) => [getOptionCode(option), option])
4321
+ .filter(([code]) => !!code));
4322
+ const codes = getMultiOptionCodes(value);
4323
+ return codes.map((code) => optionByCode.get(code)?.name || code).join(', ');
4324
+ };
4325
+
4303
4326
  const getTrackedEntityTableData = (response, programId, pager, metaData, searcheableDataElements, customDisplayInReportsIds, columnNameSource = 'NAME') => {
4304
4327
  const getColumnLabel = (item) => columnNameSource === 'FORM_NAME'
4305
4328
  ? item?.formName || item?.name || 'Default'
@@ -4359,6 +4382,7 @@ const getTrackedEntityTableData = (response, programId, pager, metaData, searche
4359
4382
  .filter((psde) => psde.dataElement && shouldIncludeDataElement(psde))
4360
4383
  .map(({ dataElement }) => ({
4361
4384
  id: dataElement.id,
4385
+ valueType: dataElement.valueType,
4362
4386
  options: dataElement.optionSet?.options?.map((option) => ({
4363
4387
  name: option.name,
4364
4388
  code: option.code,
@@ -4446,13 +4470,20 @@ const getTrackedEntityTableData = (response, programId, pager, metaData, searche
4446
4470
  }
4447
4471
  else if (attributeMeta?.optionSetValue &&
4448
4472
  attributeMeta?.optionSet?.options) {
4449
- const matchedOption = attributeMeta.optionSet.options.find((opt) => opt.code === value);
4450
- row[attributeId] = {
4451
- value: matchedOption?.name || value,
4452
- ...(getOptionColor(matchedOption) && {
4453
- style: getOptionColor(matchedOption),
4454
- }),
4455
- };
4473
+ if (valueType === 'MULTI_TEXT') {
4474
+ row[attributeId] = {
4475
+ value: formatMultiTextOptionValue(value, attributeMeta.optionSet.options),
4476
+ };
4477
+ }
4478
+ else {
4479
+ const matchedOption = attributeMeta.optionSet.options.find((opt) => opt.code === value);
4480
+ row[attributeId] = {
4481
+ value: matchedOption?.name || value,
4482
+ ...(getOptionColor(matchedOption) && {
4483
+ style: getOptionColor(matchedOption),
4484
+ }),
4485
+ };
4486
+ }
4456
4487
  }
4457
4488
  else {
4458
4489
  row[attributeId] = { value };
@@ -4465,13 +4496,20 @@ const getTrackedEntityTableData = (response, programId, pager, metaData, searche
4465
4496
  if (!dataElementId || value == null)
4466
4497
  return;
4467
4498
  const dataElementOption = dataElementOptionMap.get(dataElementId);
4468
- const matchedOption = dataElementOption?.options?.find((opt) => opt.code === value);
4469
- row[dataElementId] = {
4470
- value: matchedOption?.name || value,
4471
- ...(getOptionColor(matchedOption) && {
4472
- style: getOptionColor(matchedOption),
4473
- }),
4474
- };
4499
+ if (dataElementOption?.valueType === 'MULTI_TEXT') {
4500
+ row[dataElementId] = {
4501
+ value: formatMultiTextOptionValue(value, dataElementOption.options),
4502
+ };
4503
+ }
4504
+ else {
4505
+ const matchedOption = dataElementOption?.options?.find((opt) => opt.code === value);
4506
+ row[dataElementId] = {
4507
+ value: matchedOption?.name || value,
4508
+ ...(getOptionColor(matchedOption) && {
4509
+ style: getOptionColor(matchedOption),
4510
+ }),
4511
+ };
4512
+ }
4475
4513
  });
4476
4514
  const orgUnitId = enrollment.orgUnit;
4477
4515
  const orgUnitName = orgUnitMap?.get(orgUnitId) || '-';
@@ -4615,7 +4653,6 @@ const getEvents = (response, programStageId, pager, metaData, columnNameSource =
4615
4653
  ? item?.formName || item?.name || 'Default'
4616
4654
  : item?.name || item?.formName || 'Default';
4617
4655
  const events = response.data.events;
4618
- const eventsiiii = response.data;
4619
4656
  const allDataElements = new Set();
4620
4657
  events.forEach((event) => {
4621
4658
  event.dataValues.forEach((dv) => allDataElements.add(dv.dataElement));
@@ -4656,10 +4693,17 @@ const getEvents = (response, programStageId, pager, metaData, columnNameSource =
4656
4693
  const dataElementMeta = stageFromMetaData.programStageDataElements.find((psde) => psde.dataElement.id === dv.dataElement);
4657
4694
  if (dataElementMeta?.dataElement.optionSet) {
4658
4695
  const optionSet = dataElementMeta.dataElement.optionSet;
4659
- const matchingOption = optionSet.options.find((option) => option.code === dv.value);
4660
- row[dv.dataElement] = matchingOption
4661
- ? { value: matchingOption.name }
4662
- : { value: dv.value };
4696
+ if (dataElementMeta.dataElement.valueType === 'MULTI_TEXT') {
4697
+ row[dv.dataElement] = {
4698
+ value: formatMultiTextOptionValue(dv.value, optionSet.options),
4699
+ };
4700
+ }
4701
+ else {
4702
+ const matchingOption = optionSet.options.find((option) => option.code === dv.value);
4703
+ row[dv.dataElement] = matchingOption
4704
+ ? { value: matchingOption.name }
4705
+ : { value: dv.value };
4706
+ }
4663
4707
  }
4664
4708
  else {
4665
4709
  row[dv.dataElement] = { value: dv.value };
@@ -10381,6 +10425,9 @@ class FieldUtil {
10381
10425
  }
10382
10426
  static getFieldControlType(valueType, hasOptions) {
10383
10427
  if (hasOptions) {
10428
+ if (valueType === FieldType.MULTI_TEXT) {
10429
+ return 'multi-dropdown';
10430
+ }
10384
10431
  return 'dropdown';
10385
10432
  }
10386
10433
  switch (valueType) {