@openmrs/ngx-formentry 3.1.2-pre.186 → 3.1.2-pre.200

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.
Files changed (25) hide show
  1. package/bundles/openmrs-ngx-formentry.umd.js +111 -7
  2. package/bundles/openmrs-ngx-formentry.umd.js.map +1 -1
  3. package/esm2015/abstract-controls-extension/afe-form-array.js +4 -2
  4. package/esm2015/abstract-controls-extension/afe-form-control.js +4 -2
  5. package/esm2015/abstract-controls-extension/afe-form-group.js +4 -2
  6. package/esm2015/form-entry/control-hiders-disablers/can-disable.js +1 -1
  7. package/esm2015/form-entry/form-entry.module.js +6 -3
  8. package/esm2015/form-entry/form-factory/hiders-disablers.factory.js +2 -1
  9. package/esm2015/form-entry/form-factory/index.js +7 -0
  10. package/esm2015/form-entry/form-factory/question.factory.js +17 -2
  11. package/esm2015/form-entry/form-renderer/form-renderer.component.js +4 -2
  12. package/esm2015/form-entry/question-models/interfaces/base-options.js +1 -1
  13. package/esm2015/form-entry/question-models/question-base.js +1 -1
  14. package/esm2015/form-entry/value-adapters/patient-identifier.adapter.js +76 -0
  15. package/esm2015/lib/index.js +2 -1
  16. package/fesm2015/openmrs-ngx-formentry.js +107 -8
  17. package/fesm2015/openmrs-ngx-formentry.js.map +1 -1
  18. package/form-entry/control-hiders-disablers/can-disable.d.ts +1 -0
  19. package/form-entry/form-factory/index.d.ts +6 -0
  20. package/form-entry/form-factory/question.factory.d.ts +1 -0
  21. package/form-entry/question-models/interfaces/base-options.d.ts +1 -0
  22. package/form-entry/question-models/question-base.d.ts +1 -0
  23. package/form-entry/value-adapters/patient-identifier.adapter.d.ts +13 -0
  24. package/lib/index.d.ts +1 -0
  25. package/package.json +1 -1
@@ -1358,7 +1358,9 @@
1358
1358
  });
1359
1359
  AfeFormControl.prototype.disable = function (param) {
1360
1360
  _super.prototype.disable.call(this, param);
1361
- _super.prototype.setValue.call(this, '');
1361
+ if (this.disablers.some(function (disabler) { return disabler.resetValueOnDisable === true; })) {
1362
+ _super.prototype.setValue.call(this, '');
1363
+ }
1362
1364
  };
1363
1365
  AfeFormControl.prototype.hide = function () {
1364
1366
  this.hiderHelper.hideControl(this);
@@ -1445,7 +1447,9 @@
1445
1447
  };
1446
1448
  AfeFormGroup.prototype.disable = function (param) {
1447
1449
  _super.prototype.disable.call(this, param);
1448
- _super.prototype.setValue.call(this, {});
1450
+ if (this.disablers.some(function (disabler) { return disabler.resetValueOnDisable === true; })) {
1451
+ _super.prototype.setValue.call(this, {});
1452
+ }
1449
1453
  };
1450
1454
  AfeFormGroup.prototype.setHidingFn = function (newHider) {
1451
1455
  this.hiderHelper.setHiderForControl(this, newHider);
@@ -1524,7 +1528,9 @@
1524
1528
  };
1525
1529
  AfeFormArray.prototype.disable = function (param) {
1526
1530
  _super.prototype.disable.call(this, param);
1527
- _super.prototype.setValue.call(this, []);
1531
+ if (this.disablers.some(function (disabler) { return disabler.resetValueOnDisable === true; })) {
1532
+ _super.prototype.setValue.call(this, []);
1533
+ }
1528
1534
  };
1529
1535
  AfeFormArray.prototype.setHidingFn = function (newHider) {
1530
1536
  this.hiderHelper.setHiderForControl(this, newHider);
@@ -2650,6 +2656,7 @@
2650
2656
  var disabler = {
2651
2657
  toDisable: false,
2652
2658
  disableWhenExpression: question.disable,
2659
+ resetValueOnDisable: question.resetValueOnDisable,
2653
2660
  reEvaluateDisablingExpression: function () {
2654
2661
  var result = runnable.run();
2655
2662
  disabler.toDisable = result;
@@ -10218,7 +10225,9 @@
10218
10225
  }
10219
10226
  };
10220
10227
  FormRendererComponent.prototype.hasErrors = function () {
10221
- return this.node.control.touched && !this.node.control.valid;
10228
+ return (this.node.control.touched &&
10229
+ !this.node.control.valid &&
10230
+ this.node.control.disablers.length === 0);
10222
10231
  };
10223
10232
  FormRendererComponent.prototype.errors = function () {
10224
10233
  return this.getErrors(this.node);
@@ -13563,7 +13572,8 @@
13563
13572
  question.renderingType = 'remote-select';
13564
13573
  question.validators = this.addValidators(schemaQuestion);
13565
13574
  question.extras = schemaQuestion;
13566
- question.dataSource = schemaQuestion.questionOptions.dataSource || 'diagnoses';
13575
+ question.dataSource =
13576
+ schemaQuestion.questionOptions.dataSource || 'diagnoses';
13567
13577
  var mappings = {
13568
13578
  label: 'label',
13569
13579
  required: 'required',
@@ -13855,6 +13865,14 @@
13855
13865
  if (typeof schemaQuestion.disable === 'object') {
13856
13866
  question.disable = schemaQuestion.disable.disableWhenExpression;
13857
13867
  }
13868
+ if (schemaQuestion.disable) {
13869
+ //if resetValueOnDisable doesn't exist on the config or no value is provided the default value will be passed (true)
13870
+ question.resetValueOnDisable =
13871
+ !schemaQuestion.hasOwnProperty('resetValueOnDisable') ||
13872
+ this.isEmpty(schemaQuestion.resetValueOnDisable)
13873
+ ? true
13874
+ : schemaQuestion.resetValueOnDisable;
13875
+ }
13858
13876
  if (!!schemaQuestion.hide) {
13859
13877
  question.hide = schemaQuestion.hide;
13860
13878
  }
@@ -13875,6 +13893,12 @@
13875
13893
  }
13876
13894
  return '_' + s;
13877
13895
  };
13896
+ QuestionFactory.prototype.isEmpty = function (value) {
13897
+ if (value === '' || value === null || value === undefined) {
13898
+ return true;
13899
+ }
13900
+ return false;
13901
+ };
13878
13902
  return QuestionFactory;
13879
13903
  }());
13880
13904
  QuestionFactory.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: QuestionFactory, deps: [], target: i0__namespace.ɵɵFactoryTarget.Injectable });
@@ -16194,6 +16218,83 @@
16194
16218
  }]
16195
16219
  }] });
16196
16220
 
16221
+ var PatientIdentifierAdapter = /** @class */ (function () {
16222
+ function PatientIdentifierAdapter() {
16223
+ }
16224
+ PatientIdentifierAdapter.prototype.generateFormPayload = function (form, locationUuid) {
16225
+ return this.generateNodePayload(form.rootNode, locationUuid);
16226
+ };
16227
+ PatientIdentifierAdapter.prototype.generateNodePayload = function (rootNode, locationUuid) {
16228
+ var nodes = this.getPatientIdentifierNodes(rootNode);
16229
+ var payload = [];
16230
+ nodes.forEach(function (node) {
16231
+ if (node.control.value !== null &&
16232
+ node.control.value !== undefined &&
16233
+ node.control.value !== '') {
16234
+ payload.push({
16235
+ identifierType: node.question.extras.questionOptions.identifierType,
16236
+ identifier: node.control.value,
16237
+ location: locationUuid,
16238
+ preferred: false
16239
+ });
16240
+ }
16241
+ });
16242
+ return payload;
16243
+ };
16244
+ PatientIdentifierAdapter.prototype.populateForm = function (form, payload) {
16245
+ this.populateNode(form.rootNode, payload);
16246
+ };
16247
+ PatientIdentifierAdapter.prototype.populateNode = function (rootNode, payload) {
16248
+ if (!Array.isArray(payload)) {
16249
+ throw new Error('Expected an array of patient identfiers');
16250
+ }
16251
+ var nodes = this.getPatientIdentifierNodes(rootNode);
16252
+ nodes.forEach(function (node) {
16253
+ payload.forEach(function (element) {
16254
+ if (element.identifierType.uuid ===
16255
+ node.question.extras.questionOptions.identifierType) {
16256
+ if (element.identifier) {
16257
+ node.control.setValue(element.identifier);
16258
+ node.initialValue = element.identifier;
16259
+ }
16260
+ }
16261
+ });
16262
+ });
16263
+ };
16264
+ PatientIdentifierAdapter.prototype.getPatientIdentifierNodes = function (rootNode) {
16265
+ var results = [];
16266
+ this.getPatientIdentifierTypeNodes(rootNode, results);
16267
+ return results;
16268
+ };
16269
+ PatientIdentifierAdapter.prototype.getPatientIdentifierTypeNodes = function (rootNode, array) {
16270
+ var _this = this;
16271
+ if (rootNode.question.extras &&
16272
+ rootNode.question.extras.type === 'patientIdentifier') {
16273
+ array.push(rootNode);
16274
+ }
16275
+ if (rootNode instanceof GroupNode) {
16276
+ var node = rootNode;
16277
+ for (var o in node.children) {
16278
+ if (node.children[o] instanceof NodeBase) {
16279
+ this.getPatientIdentifierTypeNodes(node.children[o], array);
16280
+ }
16281
+ }
16282
+ }
16283
+ if (rootNode instanceof ArrayNode) {
16284
+ var node = rootNode;
16285
+ node.children.forEach(function (child) {
16286
+ _this.getPatientIdentifierTypeNodes(child, array);
16287
+ });
16288
+ }
16289
+ };
16290
+ return PatientIdentifierAdapter;
16291
+ }());
16292
+ PatientIdentifierAdapter.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: PatientIdentifierAdapter, deps: [], target: i0__namespace.ɵɵFactoryTarget.Injectable });
16293
+ PatientIdentifierAdapter.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: PatientIdentifierAdapter });
16294
+ i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: PatientIdentifierAdapter, decorators: [{
16295
+ type: i0.Injectable
16296
+ }] });
16297
+
16197
16298
  var FormEntryModule = /** @class */ (function () {
16198
16299
  function FormEntryModule() {
16199
16300
  }
@@ -16248,7 +16349,8 @@
16248
16349
  PersonAttribuAdapter,
16249
16350
  OrderValueAdapter,
16250
16351
  DiagnosisValueAdapter,
16251
- DebugModeService
16352
+ DebugModeService,
16353
+ PatientIdentifierAdapter
16252
16354
  ], imports: [[
16253
16355
  i1.CommonModule,
16254
16356
  i21.ReactiveFormsModule,
@@ -16325,7 +16427,8 @@
16325
16427
  PersonAttribuAdapter,
16326
16428
  OrderValueAdapter,
16327
16429
  DiagnosisValueAdapter,
16328
- DebugModeService
16430
+ DebugModeService,
16431
+ PatientIdentifierAdapter
16329
16432
  ],
16330
16433
  exports: [
16331
16434
  FormRendererComponent,
@@ -16406,6 +16509,7 @@
16406
16509
  exports.Option = Option;
16407
16510
  exports.OrderValueAdapter = OrderValueAdapter;
16408
16511
  exports.Pair = Pair;
16512
+ exports.PatientIdentifierAdapter = PatientIdentifierAdapter;
16409
16513
  exports.PersonAttribuAdapter = PersonAttribuAdapter;
16410
16514
  exports.QuestionBase = QuestionBase;
16411
16515
  exports.QuestionFactory = QuestionFactory;