@iapps/ng-dhis2-ui 1.3.3 → 1.3.4

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.
@@ -13094,8 +13094,14 @@ class ProgramEntryFormModule {
13094
13094
  if (!this.instance()) {
13095
13095
  return {};
13096
13096
  }
13097
+ const trackedEntity = this.trackedEntityInstance();
13098
+ const attributeValues = Object.keys(trackedEntity?.attributeEntities ?? {}).reduce((acc, key) => {
13099
+ acc[key] = trackedEntity?.attributeEntities?.[key]?.value;
13100
+ return acc;
13101
+ }, {});
13097
13102
  return {
13098
- ...(this.trackedEntityInstance() || {}),
13103
+ ...attributeValues,
13104
+ ...(trackedEntity?.reportEntities ?? {}),
13099
13105
  ...(this.instance() || {}),
13100
13106
  };
13101
13107
  }, /* @ts-ignore */
@@ -13197,44 +13203,6 @@ class ProgramEntryFormModule {
13197
13203
  }
13198
13204
  return configuredKey;
13199
13205
  }
13200
- // #updateInstanceWithAutoAssignedValues(
13201
- // autoAssignedValues: AutoAssignedValues[]
13202
- // ) {
13203
- // const assignedDataValues = autoAssignedValues.reduce(
13204
- // (entities, assignedValue) => {
13205
- // return {
13206
- // ...entities,
13207
- // [assignedValue.field]: assignedValue.value,
13208
- // };
13209
- // },
13210
- // {}
13211
- // );
13212
- // this.#updateInstance(assignedDataValues);
13213
- // }
13214
- // #updateInstanceWithAutoAssignedValues(
13215
- // autoAssignedValues: AutoAssignedValues[]
13216
- // ) {
13217
- // const valueCount = autoAssignedValues?.length ?? 0;
13218
- // if (valueCount === 0) {
13219
- // return;
13220
- // }
13221
- // const metaData = this.metaData();
13222
- // const aggregatedValues: Record<string, unknown> = {};
13223
- // for (let index = 0; index < valueCount; index++) {
13224
- // const { field: configuredKey, value } = autoAssignedValues[index];
13225
- // const semanticKey = metaData
13226
- // ? this.#resolveFieldRuntimeId(configuredKey, metaData)
13227
- // : configuredKey;
13228
- // aggregatedValues[semanticKey] = value;
13229
- // if (configuredKey !== semanticKey) {
13230
- // aggregatedValues[configuredKey] = value;
13231
- // }
13232
- // }
13233
- // if (Object.keys(aggregatedValues).length === 0) {
13234
- // return;
13235
- // }
13236
- // this.#updateInstance(aggregatedValues);
13237
- // }
13238
13206
  #updateInstanceWithAutoAssignedValues(autoAssignedValues) {
13239
13207
  const trackedEntityId = this.trackedEntity?.();
13240
13208
  if (typeof trackedEntityId === 'string' &&
@@ -13262,21 +13230,6 @@ class ProgramEntryFormModule {
13262
13230
  }
13263
13231
  this.#updateInstance(aggregatedValues);
13264
13232
  }
13265
- // #updateInstance(dataValues: Record<string, unknown>) {
13266
- // this.instance.update((instance) => {
13267
- // instance?.updateDataValues(dataValues, this.config().updateTeiOrgUnit);
13268
- // return instance;
13269
- // });
13270
- // }
13271
- // #updateInstance(dataValues: Record<string, unknown>) {
13272
- // this.instance.update((instance) => {
13273
- // if (!instance) {
13274
- // return instance;
13275
- // }
13276
- // instance.updateDataValues(dataValues, this.config().updateTeiOrgUnit);
13277
- // return instance;
13278
- // });
13279
- // }
13280
13233
  #updateInstance(dataValues) {
13281
13234
  if (!dataValues || Object.keys(dataValues).length === 0) {
13282
13235
  return;
@@ -13307,7 +13260,8 @@ class ProgramEntryFormModule {
13307
13260
  if (this.config().autoComplete) {
13308
13261
  this.instance().complete();
13309
13262
  }
13310
- return this.instanceQuery
13263
+ const instanceQuery = this.#getQuery('TRACKER');
13264
+ return instanceQuery
13311
13265
  .setData(this.instance())
13312
13266
  .save();
13313
13267
  }
@@ -13315,9 +13269,8 @@ class ProgramEntryFormModule {
13315
13269
  if (this.config().autoComplete) {
13316
13270
  this.instance().complete();
13317
13271
  }
13318
- return this.instanceQuery
13319
- .setData(this.instance())
13320
- .save();
13272
+ const instanceQuery = this.#getQuery('EVENT');
13273
+ return instanceQuery.setData(this.instance()).save();
13321
13274
  }
13322
13275
  default:
13323
13276
  return firstValueFrom(of(null));
@@ -13335,43 +13288,51 @@ class ProgramEntryFormModule {
13335
13288
  });
13336
13289
  return instance;
13337
13290
  }
13338
- async #getTrackerInstance() {
13291
+ #getQuery(instanceType) {
13339
13292
  const d2 = window.d2Web;
13340
- this.instanceQuery = d2?.trackerModule?.trackedEntity
13341
- ?.setProgram(this.config().program)
13342
- ?.setOrgUnit(this.orgUnit());
13343
- if (!this.instanceQuery) {
13293
+ switch (instanceType) {
13294
+ case 'TRACKER':
13295
+ return d2.trackerModule.trackedEntity
13296
+ .setProgram(this.config().program)
13297
+ .setOrgUnit(this.orgUnit());
13298
+ case 'EVENT':
13299
+ return d2.eventModule.event
13300
+ .setProgram(this.config().program)
13301
+ .setProgramStage(this.config().programStage)
13302
+ .setEnrollment(this.enrollment())
13303
+ .setTrackedEntity(this.trackedEntity())
13304
+ .setOrgUnit(this.orgUnit());
13305
+ default:
13306
+ throw new Error('Invalid form type');
13307
+ }
13308
+ }
13309
+ async #getTrackerInstance() {
13310
+ const instanceQuery = this.#getQuery('TRACKER');
13311
+ if (!instanceQuery) {
13344
13312
  throw new Error('Could not initialize tracker query');
13345
13313
  }
13346
13314
  if (!this.trackedEntity()) {
13347
- return await this.instanceQuery.create();
13315
+ return await instanceQuery.create();
13348
13316
  }
13349
- const instanceResult = (await this.instanceQuery
13350
- .setTrackedEntity(this.trackedEntity())
13351
- .get()).data;
13317
+ const instanceResult = (await instanceQuery.setTrackedEntity(this.trackedEntity()).get()).data;
13352
13318
  if (!instanceResult) {
13353
- return await this.instanceQuery.create();
13319
+ return await instanceQuery.create();
13354
13320
  }
13355
- this.instanceQuery.setInstanceFields(this.metaData()?.program);
13356
- const instance = await this.instanceQuery.setReservedValues();
13321
+ instanceQuery.setInstanceFields(this.metaData()?.program);
13322
+ const instance = await instanceQuery.setReservedValues();
13357
13323
  if (this.orgUnit()) {
13358
13324
  instance.setOrgUnit(this.orgUnit());
13359
13325
  }
13360
13326
  return instance;
13361
13327
  }
13362
13328
  async #getEventInstance() {
13363
- this.instanceQuery = this.d2.eventModule.event
13364
- .setProgram(this.config().program)
13365
- .setProgramStage(this.config().programStage)
13366
- .setEnrollment(this.enrollment())
13367
- .setTrackedEntity(this.trackedEntity())
13368
- .setOrgUnit(this.orgUnit());
13329
+ const instanceQuery = this.#getQuery('EVENT');
13369
13330
  if (!this.event()) {
13370
- return await this.instanceQuery.create();
13331
+ return await instanceQuery.create();
13371
13332
  }
13372
- const instance = (await this.instanceQuery.setEvent(this.event()).get()).data;
13333
+ const instance = (await instanceQuery.setEvent(this.event()).get()).data;
13373
13334
  if (!instance) {
13374
- return await this.instanceQuery.create();
13335
+ return await instanceQuery.create();
13375
13336
  }
13376
13337
  if (this.metaData()?.program) {
13377
13338
  instance.setFields(this.metaData().program);