@iapps/ng-dhis2-ui 1.1.55 → 1.1.56
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 +570 -2
- package/fesm2022/iapps-ng-dhis2-ui.mjs.map +1 -1
- package/index.d.ts +1 -0
- package/lib/modules/form/containers/flat-form/flat-form.component.d.ts +11 -0
- package/lib/modules/form/form.module.d.ts +7 -6
- package/lib/modules/form/index.d.ts +1 -0
- package/lib/modules/form/shared/components/base-form-wrapper.component.d.ts +26 -0
- package/lib/modules/form/shared/components/index.d.ts +1 -0
- package/lib/modules/form/shared/index.d.ts +1 -0
- package/lib/modules/program-entry-form/index.d.ts +2 -0
- package/lib/modules/program-entry-form/models/index.d.ts +3 -0
- package/lib/modules/program-entry-form/models/program-entry-form-metadata.d.ts +28 -0
- package/lib/modules/program-entry-form/models/program-entry-form-section.model.d.ts +16 -0
- package/lib/modules/program-entry-form/models/program-entry-form.config.d.ts +47 -0
- package/lib/modules/program-entry-form/program-entry-form.component.d.ts +35 -0
- package/lib/modules/program-entry-form/utils/index.d.ts +2 -0
- package/lib/modules/program-entry-form/utils/program-entry-form-field.util.d.ts +62 -0
- package/lib/modules/program-entry-form/utils/program-entry-form-section.util.d.ts +8 -0
- package/package.json +1 -1
|
@@ -6051,19 +6051,101 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.1.8", ngImpor
|
|
|
6051
6051
|
type: Output
|
|
6052
6052
|
}] } });
|
|
6053
6053
|
|
|
6054
|
+
// Copyright 2025 UDSM DHIS2 Lab. All rights reserved.
|
|
6055
|
+
// Use of this source code is governed by a BSD-style
|
|
6056
|
+
// license that can be found in the LICENSE file.
|
|
6057
|
+
class BaseFormWrapperComponent {
|
|
6058
|
+
#updatedDataValues;
|
|
6059
|
+
constructor() {
|
|
6060
|
+
this.ngZone = inject(NgZone);
|
|
6061
|
+
this.name = input();
|
|
6062
|
+
this.fields = input.required();
|
|
6063
|
+
this.rules = input([]);
|
|
6064
|
+
this.dataValues = input({});
|
|
6065
|
+
this.ruleActions = signal([]);
|
|
6066
|
+
this.isFormValid = signal(true);
|
|
6067
|
+
this.#updatedDataValues = signal({});
|
|
6068
|
+
this.formSave = new EventEmitter();
|
|
6069
|
+
this.formUpdate = new EventEmitter();
|
|
6070
|
+
this.formCancel = new EventEmitter();
|
|
6071
|
+
this.formValidityUpdate = new EventEmitter();
|
|
6072
|
+
this.ruleProcessor = effect(() => {
|
|
6073
|
+
if (this.#updatedDataValues()) {
|
|
6074
|
+
this.executeRules();
|
|
6075
|
+
}
|
|
6076
|
+
});
|
|
6077
|
+
}
|
|
6078
|
+
updateDataValues(dataValues) {
|
|
6079
|
+
this.#updatedDataValues.set(dataValues);
|
|
6080
|
+
this.formUpdate.emit(this.#updatedDataValues());
|
|
6081
|
+
}
|
|
6082
|
+
updateFormValidity(isFormValid) {
|
|
6083
|
+
this.isFormValid.set(isFormValid);
|
|
6084
|
+
this.formValidityUpdate.emit(isFormValid);
|
|
6085
|
+
}
|
|
6086
|
+
executeRules() {
|
|
6087
|
+
this.ruleActions.set(new ProgramRuleEngine()
|
|
6088
|
+
.setRules(this.rules())
|
|
6089
|
+
.setDataValues(this.#updatedDataValues())
|
|
6090
|
+
.execute());
|
|
6091
|
+
}
|
|
6092
|
+
ngOnDestroy() {
|
|
6093
|
+
this.ruleProcessor.destroy();
|
|
6094
|
+
}
|
|
6095
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.1.8", ngImport: i0, type: BaseFormWrapperComponent, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
|
|
6096
|
+
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "19.1.8", type: BaseFormWrapperComponent, isStandalone: true, inputs: { name: { classPropertyName: "name", publicName: "name", isSignal: true, isRequired: false, transformFunction: null }, fields: { classPropertyName: "fields", publicName: "fields", isSignal: true, isRequired: true, transformFunction: null }, rules: { classPropertyName: "rules", publicName: "rules", isSignal: true, isRequired: false, transformFunction: null }, dataValues: { classPropertyName: "dataValues", publicName: "dataValues", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { formSave: "formSave", formUpdate: "formUpdate", formCancel: "formCancel", formValidityUpdate: "formValidityUpdate" }, ngImport: i0 }); }
|
|
6097
|
+
}
|
|
6098
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.1.8", ngImport: i0, type: BaseFormWrapperComponent, decorators: [{
|
|
6099
|
+
type: Directive
|
|
6100
|
+
}], ctorParameters: () => [], propDecorators: { formSave: [{
|
|
6101
|
+
type: Output
|
|
6102
|
+
}], formUpdate: [{
|
|
6103
|
+
type: Output
|
|
6104
|
+
}], formCancel: [{
|
|
6105
|
+
type: Output
|
|
6106
|
+
}], formValidityUpdate: [{
|
|
6107
|
+
type: Output
|
|
6108
|
+
}] } });
|
|
6109
|
+
|
|
6110
|
+
// Copyright 2025 UDSM DHIS2 Lab. All rights reserved.
|
|
6111
|
+
// Use of this source code is governed by a BSD-style
|
|
6112
|
+
// license that can be found in the LICENSE file.
|
|
6113
|
+
|
|
6114
|
+
// Copyright 2025 UDSM DHIS2 Lab. All rights reserved.
|
|
6115
|
+
// Use of this source code is governed by a BSD-style
|
|
6116
|
+
// license that can be found in the LICENSE file.
|
|
6117
|
+
|
|
6118
|
+
class FlatFormComponent extends BaseFormWrapperComponent {
|
|
6119
|
+
ngOnInit() {
|
|
6120
|
+
this.formGroup = FormUtil.getFormGroup(this.fields(), this.dataValues());
|
|
6121
|
+
}
|
|
6122
|
+
onFormUpdate() {
|
|
6123
|
+
this.updateDataValues(this.formGroup.getRawValue());
|
|
6124
|
+
this.updateFormValidity(this.formGroup.valid);
|
|
6125
|
+
}
|
|
6126
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.1.8", ngImport: i0, type: FlatFormComponent, deps: null, target: i0.ɵɵFactoryTarget.Component }); }
|
|
6127
|
+
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.1.8", type: FlatFormComponent, isStandalone: false, selector: "ng-dhis2-ui-flat-form", usesInheritance: true, ngImport: i0, template: "<!-- <ng-dhis2-ui-form\n*ngIf=\"fieldGroup.fields.length > 0\"\n[fields]=\"fieldGroup.fields\"\n[form]=\"formGroup\"\n[dataEntities]=\"dataValueEntities()\"\n[programRuleActions]=\"ruleActions()\"\n[isFormHorizontal]=\"fieldGroup.isFormHorizontal || false\"\n(formUpdate)=\"onFormUpdate($event, fieldGroup.id)\"\n></ng-dhis2-ui-form> -->\n\n<ng-dhis2-ui-form\n [fields]=\"fields()\"\n [form]=\"formGroup\"\n [dataEntities]=\"dataValues()\"\n [programRuleActions]=\"ruleActions()\"\n (formUpdate)=\"onFormUpdate()\"\n/>\n", dependencies: [{ kind: "component", type: FormComponent, selector: "ng-dhis2-ui-form", inputs: ["formConfig", "fields", "form", "isFormHorizontal", "showSaveButton", "fieldsData", "fieldClass", "shouldRenderAsCheckBoxesButton", "programRuleActions", "dataEntities"], outputs: ["formUpdate"] }] }); }
|
|
6128
|
+
}
|
|
6129
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.1.8", ngImport: i0, type: FlatFormComponent, decorators: [{
|
|
6130
|
+
type: Component,
|
|
6131
|
+
args: [{ selector: 'ng-dhis2-ui-flat-form', standalone: false, template: "<!-- <ng-dhis2-ui-form\n*ngIf=\"fieldGroup.fields.length > 0\"\n[fields]=\"fieldGroup.fields\"\n[form]=\"formGroup\"\n[dataEntities]=\"dataValueEntities()\"\n[programRuleActions]=\"ruleActions()\"\n[isFormHorizontal]=\"fieldGroup.isFormHorizontal || false\"\n(formUpdate)=\"onFormUpdate($event, fieldGroup.id)\"\n></ng-dhis2-ui-form> -->\n\n<ng-dhis2-ui-form\n [fields]=\"fields()\"\n [form]=\"formGroup\"\n [dataEntities]=\"dataValues()\"\n [programRuleActions]=\"ruleActions()\"\n (formUpdate)=\"onFormUpdate()\"\n/>\n" }]
|
|
6132
|
+
}] });
|
|
6133
|
+
|
|
6054
6134
|
class D2FormModule {
|
|
6055
6135
|
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.1.8", ngImport: i0, type: D2FormModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
|
|
6056
6136
|
static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "19.1.8", ngImport: i0, type: D2FormModule, declarations: [FormFieldComponent,
|
|
6057
6137
|
FormComponent,
|
|
6058
6138
|
RepeatableFormComponent,
|
|
6059
6139
|
SectionFormComponent,
|
|
6140
|
+
FlatFormComponent,
|
|
6060
6141
|
FormFieldItemComponent], imports: [CommonModule,
|
|
6061
6142
|
ReactiveFormsModule,
|
|
6062
6143
|
ReactWrapperModule,
|
|
6063
6144
|
OrganisationUnitSelectorModule], exports: [FormFieldComponent,
|
|
6064
6145
|
FormComponent,
|
|
6065
6146
|
RepeatableFormComponent,
|
|
6066
|
-
SectionFormComponent
|
|
6147
|
+
SectionFormComponent,
|
|
6148
|
+
FlatFormComponent] }); }
|
|
6067
6149
|
static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "19.1.8", ngImport: i0, type: D2FormModule, imports: [CommonModule,
|
|
6068
6150
|
ReactiveFormsModule,
|
|
6069
6151
|
OrganisationUnitSelectorModule] }); }
|
|
@@ -6076,6 +6158,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.1.8", ngImpor
|
|
|
6076
6158
|
FormComponent,
|
|
6077
6159
|
RepeatableFormComponent,
|
|
6078
6160
|
SectionFormComponent,
|
|
6161
|
+
FlatFormComponent,
|
|
6079
6162
|
FormFieldItemComponent,
|
|
6080
6163
|
],
|
|
6081
6164
|
imports: [
|
|
@@ -6089,6 +6172,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.1.8", ngImpor
|
|
|
6089
6172
|
FormComponent,
|
|
6090
6173
|
RepeatableFormComponent,
|
|
6091
6174
|
SectionFormComponent,
|
|
6175
|
+
FlatFormComponent,
|
|
6092
6176
|
],
|
|
6093
6177
|
}]
|
|
6094
6178
|
}] });
|
|
@@ -6536,9 +6620,493 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.1.8", ngImpor
|
|
|
6536
6620
|
// Use of this source code is governed by a BSD-style
|
|
6537
6621
|
// license that can be found in the LICENSE file.
|
|
6538
6622
|
|
|
6623
|
+
// Copyright 2025 UDSM DHIS2 Lab. All rights reserved.
|
|
6624
|
+
// Use of this source code is governed by a BSD-style
|
|
6625
|
+
// license that can be found in the LICENSE file.
|
|
6626
|
+
class ProgramEntryFormConfig {
|
|
6627
|
+
constructor(config) {
|
|
6628
|
+
this.displayType = 'FLAT';
|
|
6629
|
+
this.submitButtonLabel = 'Submit';
|
|
6630
|
+
this.cancelButtonLabel = 'Cancel';
|
|
6631
|
+
Object.assign(this, config);
|
|
6632
|
+
}
|
|
6633
|
+
}
|
|
6634
|
+
|
|
6635
|
+
// Copyright 2025 UDSM DHIS2 Lab. All rights reserved.
|
|
6636
|
+
// Use of this source code is governed by a BSD-style
|
|
6637
|
+
// license that can be found in the LICENSE file.
|
|
6638
|
+
class ProgramEntryFormFieldUtil {
|
|
6639
|
+
constructor(program, config) {
|
|
6640
|
+
this.program = program;
|
|
6641
|
+
this.config = config;
|
|
6642
|
+
}
|
|
6643
|
+
get attributes() {
|
|
6644
|
+
return (this.program.programTrackedEntityAttributes || []).map((programTrackedEntityAttribute) => {
|
|
6645
|
+
return {
|
|
6646
|
+
...programTrackedEntityAttribute.trackedEntityAttribute,
|
|
6647
|
+
sortOrder: programTrackedEntityAttribute.sortOrder,
|
|
6648
|
+
mandatory: programTrackedEntityAttribute.mandatory,
|
|
6649
|
+
allowFutureDate: programTrackedEntityAttribute.allowFutureDate,
|
|
6650
|
+
metaType: 'ATTRIBUTE',
|
|
6651
|
+
stepId: null,
|
|
6652
|
+
};
|
|
6653
|
+
});
|
|
6654
|
+
}
|
|
6655
|
+
get dataElements() {
|
|
6656
|
+
return flatten((this.program.programStages || []).map((programStage) => {
|
|
6657
|
+
return (programStage.programStageDataElements || []).map((stageDataElement) => {
|
|
6658
|
+
return {
|
|
6659
|
+
...stageDataElement.dataElement,
|
|
6660
|
+
sortOrder: stageDataElement.sortOrder,
|
|
6661
|
+
mandatory: stageDataElement.compulsory,
|
|
6662
|
+
allowFutureDate: stageDataElement.allowFutureDate,
|
|
6663
|
+
stepId: programStage.id,
|
|
6664
|
+
metaType: 'DATA_ELEMENT',
|
|
6665
|
+
};
|
|
6666
|
+
});
|
|
6667
|
+
}));
|
|
6668
|
+
}
|
|
6669
|
+
#getOrgUniField() {
|
|
6670
|
+
if (this.config.hideRegistrationUnit) {
|
|
6671
|
+
return null;
|
|
6672
|
+
}
|
|
6673
|
+
return new FormField({
|
|
6674
|
+
id: 'orgUnit',
|
|
6675
|
+
key: 'orgUnit',
|
|
6676
|
+
label: this.program.orgUnitLabel || 'Registering unit',
|
|
6677
|
+
code: 'orgUnit',
|
|
6678
|
+
required: true,
|
|
6679
|
+
controlType: 'org-unit',
|
|
6680
|
+
disabled: this.config.disableRegistrationUnit,
|
|
6681
|
+
});
|
|
6682
|
+
}
|
|
6683
|
+
#getEnrollmentDateField() {
|
|
6684
|
+
if (this.config.hideEnrollmentDate) {
|
|
6685
|
+
return null;
|
|
6686
|
+
}
|
|
6687
|
+
return new FormField({
|
|
6688
|
+
id: 'enrollmentDate',
|
|
6689
|
+
label: this.program.enrollmentDateLabel || 'Enrollment date',
|
|
6690
|
+
code: 'enrollmentDate',
|
|
6691
|
+
key: 'enrollmentDate',
|
|
6692
|
+
required: true,
|
|
6693
|
+
type: 'date',
|
|
6694
|
+
controlType: 'date',
|
|
6695
|
+
disabled: this.config.disableEnrollmentDate,
|
|
6696
|
+
});
|
|
6697
|
+
}
|
|
6698
|
+
#getIncidentDateField() {
|
|
6699
|
+
if (!this.program.displayIncidentDate) {
|
|
6700
|
+
return null;
|
|
6701
|
+
}
|
|
6702
|
+
return new DateField({
|
|
6703
|
+
id: 'incidentDate',
|
|
6704
|
+
label: this.program.incidentDateLabel || 'Incident date',
|
|
6705
|
+
code: 'incidentDate',
|
|
6706
|
+
key: 'incidentDate',
|
|
6707
|
+
required: true,
|
|
6708
|
+
type: 'date',
|
|
6709
|
+
controlType: 'date',
|
|
6710
|
+
disabled: this.config.disabledIncidentDate,
|
|
6711
|
+
});
|
|
6712
|
+
}
|
|
6713
|
+
get reportFields() {
|
|
6714
|
+
return [
|
|
6715
|
+
this.#getOrgUniField(),
|
|
6716
|
+
this.#getEnrollmentDateField(),
|
|
6717
|
+
this.#getIncidentDateField(),
|
|
6718
|
+
].filter((field) => field != null);
|
|
6719
|
+
}
|
|
6720
|
+
get fields() {
|
|
6721
|
+
const fields = [...this.attributes, ...this.dataElements]
|
|
6722
|
+
.map((field) => {
|
|
6723
|
+
const options = FieldDropdown.getDropdownOptions(field);
|
|
6724
|
+
const hasOptions = options?.length > 0;
|
|
6725
|
+
return new FormField({
|
|
6726
|
+
...field,
|
|
6727
|
+
id: field.id,
|
|
6728
|
+
code: field.code,
|
|
6729
|
+
label: field.formName || field.name,
|
|
6730
|
+
key: field.code ? camelCase(field.code) : field.id,
|
|
6731
|
+
required: field.mandatory,
|
|
6732
|
+
type: field.valueType,
|
|
6733
|
+
options,
|
|
6734
|
+
disabled: this.#getDisabledStatus(field),
|
|
6735
|
+
order: field.sortOrder,
|
|
6736
|
+
hasOptions,
|
|
6737
|
+
controlType: FieldUtil.getFieldControlType(field.valueType, hasOptions),
|
|
6738
|
+
metaType: field.metaType,
|
|
6739
|
+
stepId: field.stepId,
|
|
6740
|
+
});
|
|
6741
|
+
})
|
|
6742
|
+
.sort((a, b) => a.order ?? 0 - (b.order ?? 0));
|
|
6743
|
+
return [...this.reportFields, ...fields];
|
|
6744
|
+
}
|
|
6745
|
+
#getDisabledStatus(field) {
|
|
6746
|
+
if (field?.generated) {
|
|
6747
|
+
return true;
|
|
6748
|
+
}
|
|
6749
|
+
if (this.config.autoAssignedValues &&
|
|
6750
|
+
this.config.autoAssignedValues.length > 0) {
|
|
6751
|
+
const key = field.code ? camelCase(field.code) : field.id;
|
|
6752
|
+
const assignedValue = (this.config.autoAssignedValues || []).find((assignedValue) => assignedValue.field === key)?.value;
|
|
6753
|
+
return !isUndefined(assignedValue);
|
|
6754
|
+
}
|
|
6755
|
+
return false;
|
|
6756
|
+
}
|
|
6757
|
+
}
|
|
6758
|
+
|
|
6759
|
+
// Copyright 2025 UDSM DHIS2 Lab. All rights reserved.
|
|
6760
|
+
// Use of this source code is governed by a BSD-style
|
|
6761
|
+
// license that can be found in the LICENSE file.
|
|
6762
|
+
class ProgramEntryFormSectionUtil {
|
|
6763
|
+
constructor(program, config) {
|
|
6764
|
+
this.program = program;
|
|
6765
|
+
this.config = config;
|
|
6766
|
+
}
|
|
6767
|
+
get sections() {
|
|
6768
|
+
return [];
|
|
6769
|
+
}
|
|
6770
|
+
}
|
|
6771
|
+
|
|
6772
|
+
// Copyright 2025 UDSM DHIS2 Lab. All rights reserved.
|
|
6773
|
+
// Use of this source code is governed by a BSD-style
|
|
6774
|
+
// license that can be found in the LICENSE file.
|
|
6775
|
+
|
|
6776
|
+
// Copyright 2025 UDSM DHIS2 Lab. All rights reserved.
|
|
6777
|
+
// Use of this source code is governed by a BSD-style
|
|
6778
|
+
// license that can be found in the LICENSE file.
|
|
6779
|
+
class ProgramEntryFormMetaData {
|
|
6780
|
+
constructor() {
|
|
6781
|
+
this.d2 = window?.d2Web;
|
|
6782
|
+
}
|
|
6783
|
+
setConfig(config) {
|
|
6784
|
+
this.config = config;
|
|
6785
|
+
return this;
|
|
6786
|
+
}
|
|
6787
|
+
getProgramPromise() {
|
|
6788
|
+
const program = this.config.program;
|
|
6789
|
+
const programQuery = this.d2.programModule.program
|
|
6790
|
+
.select([
|
|
6791
|
+
'id',
|
|
6792
|
+
'code',
|
|
6793
|
+
'name',
|
|
6794
|
+
'captureCoordinates',
|
|
6795
|
+
'featureType',
|
|
6796
|
+
'enrollmentDateLabel',
|
|
6797
|
+
'incidentDateLabel',
|
|
6798
|
+
'displayIncidentDate',
|
|
6799
|
+
'onlyEnrollOnce',
|
|
6800
|
+
'orgUnitLabel',
|
|
6801
|
+
'programType',
|
|
6802
|
+
'useFirstStageDuringRegistration',
|
|
6803
|
+
'trackedEntityType',
|
|
6804
|
+
])
|
|
6805
|
+
.with(this.d2.programModule.programTrackedEntityAttribute.with(this.d2.programModule.trackedEntityAttribute.with(this.d2.optionSetModule.optionSet.with(this.d2.optionSetModule.option), 'ToOne'), 'ToOne'))
|
|
6806
|
+
.with(this.d2.programModule.programRuleVariable
|
|
6807
|
+
.with(this.d2.dataElementModule.dataElement.select([
|
|
6808
|
+
'id',
|
|
6809
|
+
'code',
|
|
6810
|
+
'name',
|
|
6811
|
+
]), 'ToOne')
|
|
6812
|
+
.with(this.d2.programModule.trackedEntityAttribute.select([
|
|
6813
|
+
'id',
|
|
6814
|
+
'code',
|
|
6815
|
+
'name',
|
|
6816
|
+
]), 'ToOne'))
|
|
6817
|
+
.byId(program);
|
|
6818
|
+
if (this.config.displayType === 'FLAT') {
|
|
6819
|
+
programQuery.with(this.d2.programModule.programSection.with(this.d2.programModule.trackedEntityAttribute.select(['id'])));
|
|
6820
|
+
}
|
|
6821
|
+
if (!this.config.excludeProgramStages) {
|
|
6822
|
+
programQuery.with(this.d2.programModule.programStage
|
|
6823
|
+
.with(this.d2.programModule.programStageSection)
|
|
6824
|
+
.with(this.d2.programModule.programStageDataElement.with(this.d2.dataElementModule.dataElement.with(this.d2.optionSetModule.optionSet.with(this.d2.optionSetModule.option), 'ToOne'), 'ToOne')));
|
|
6825
|
+
}
|
|
6826
|
+
return programQuery.get();
|
|
6827
|
+
}
|
|
6828
|
+
async #getProgramMetaData() {
|
|
6829
|
+
const program = this.config.program;
|
|
6830
|
+
if (!this.d2) {
|
|
6831
|
+
return null;
|
|
6832
|
+
}
|
|
6833
|
+
const metaDataResponse = await Promise.all([
|
|
6834
|
+
this.getProgramPromise(),
|
|
6835
|
+
this.d2.programModule.programRule
|
|
6836
|
+
.where({
|
|
6837
|
+
attribute: 'program.id',
|
|
6838
|
+
value: program,
|
|
6839
|
+
})
|
|
6840
|
+
.with(this.d2.programModule.programRuleAction
|
|
6841
|
+
.select([
|
|
6842
|
+
'id',
|
|
6843
|
+
'programRuleActionType',
|
|
6844
|
+
'data',
|
|
6845
|
+
'displayContent',
|
|
6846
|
+
'content',
|
|
6847
|
+
])
|
|
6848
|
+
.with(this.d2.dataElementModule.dataElement.select([
|
|
6849
|
+
'id',
|
|
6850
|
+
'code',
|
|
6851
|
+
'name',
|
|
6852
|
+
]), 'ToOne')
|
|
6853
|
+
.with(this.d2.programModule.trackedEntityAttribute.select([
|
|
6854
|
+
'id',
|
|
6855
|
+
'code',
|
|
6856
|
+
'name',
|
|
6857
|
+
]), 'ToOne')
|
|
6858
|
+
.with(this.d2.optionSetModule.optionGroup
|
|
6859
|
+
.select(['id'])
|
|
6860
|
+
.with(this.d2.optionSetModule.option.select([
|
|
6861
|
+
'id',
|
|
6862
|
+
'code',
|
|
6863
|
+
'displayName',
|
|
6864
|
+
]), 'ToMany'), 'ToOne')
|
|
6865
|
+
.with(this.d2.optionSetModule.option.select([
|
|
6866
|
+
'id',
|
|
6867
|
+
'code',
|
|
6868
|
+
'displayName',
|
|
6869
|
+
]), 'ToOne'))
|
|
6870
|
+
.get(),
|
|
6871
|
+
]);
|
|
6872
|
+
const [programResponse, programRuleResponse] = metaDataResponse;
|
|
6873
|
+
const metaData = programResponse.data;
|
|
6874
|
+
metaData.programRules = programRuleResponse.data;
|
|
6875
|
+
return metaData;
|
|
6876
|
+
}
|
|
6877
|
+
get formFields() {
|
|
6878
|
+
if (!this.metaData) {
|
|
6879
|
+
return [];
|
|
6880
|
+
}
|
|
6881
|
+
return new ProgramEntryFormFieldUtil(this.metaData, this.config).fields;
|
|
6882
|
+
}
|
|
6883
|
+
get sections() {
|
|
6884
|
+
if (!this.metaData || this.config.displayType !== 'SECTION') {
|
|
6885
|
+
return [];
|
|
6886
|
+
}
|
|
6887
|
+
return new ProgramEntryFormSectionUtil(this.metaData, this.config).sections;
|
|
6888
|
+
}
|
|
6889
|
+
get rules() {
|
|
6890
|
+
if (!this.metaData || !this.metaData.programRules) {
|
|
6891
|
+
return [];
|
|
6892
|
+
}
|
|
6893
|
+
return this.metaData.programRules.map((programRule) => new MetadataRule(programRule, this.metaData.programRuleVariables || []).toJson());
|
|
6894
|
+
}
|
|
6895
|
+
toJson() {
|
|
6896
|
+
return {
|
|
6897
|
+
id: this.metaData?.id,
|
|
6898
|
+
name: this.metaData?.name,
|
|
6899
|
+
description: this.metaData?.description,
|
|
6900
|
+
formFields: this.formFields,
|
|
6901
|
+
sections: this.sections,
|
|
6902
|
+
rules: this.rules,
|
|
6903
|
+
};
|
|
6904
|
+
}
|
|
6905
|
+
async get() {
|
|
6906
|
+
try {
|
|
6907
|
+
const metaData = await this.#getProgramMetaData();
|
|
6908
|
+
if (metaData) {
|
|
6909
|
+
this.metaData = metaData;
|
|
6910
|
+
return this.toJson();
|
|
6911
|
+
}
|
|
6912
|
+
return null;
|
|
6913
|
+
}
|
|
6914
|
+
catch (err) {
|
|
6915
|
+
return null;
|
|
6916
|
+
}
|
|
6917
|
+
}
|
|
6918
|
+
}
|
|
6919
|
+
|
|
6920
|
+
// Copyright 2025 UDSM DHIS2 Lab. All rights reserved.
|
|
6921
|
+
// Use of this source code is governed by a BSD-style
|
|
6922
|
+
// license that can be found in the LICENSE file.
|
|
6923
|
+
class ProgramEntryFormSection {
|
|
6924
|
+
constructor(props) {
|
|
6925
|
+
this.formFields = [];
|
|
6926
|
+
this.orientation = 'HORIZONTAL';
|
|
6927
|
+
Object.assign(this, props);
|
|
6928
|
+
}
|
|
6929
|
+
}
|
|
6930
|
+
|
|
6931
|
+
// Copyright 2025 UDSM DHIS2 Lab. All rights reserved.
|
|
6932
|
+
// Use of this source code is governed by a BSD-style
|
|
6933
|
+
// license that can be found in the LICENSE file.
|
|
6934
|
+
|
|
6935
|
+
// eslint-disable-next-line @angular-eslint/component-class-suffix
|
|
6936
|
+
class ProgramEntryFormModule {
|
|
6937
|
+
constructor() {
|
|
6938
|
+
this.config = input.required();
|
|
6939
|
+
this.trackedEntity = input();
|
|
6940
|
+
this.event = input();
|
|
6941
|
+
this.enrollment = input();
|
|
6942
|
+
this.orgUnit = input();
|
|
6943
|
+
this.ngZone = inject(NgZone);
|
|
6944
|
+
this.d2 = window.d2Web;
|
|
6945
|
+
this.loading = signal(false);
|
|
6946
|
+
this.metaData = signal(null);
|
|
6947
|
+
this.isFormValid = signal(true);
|
|
6948
|
+
this.isFormValid$ = toObservable(this.isFormValid);
|
|
6949
|
+
this.instance = signal(null);
|
|
6950
|
+
this.instanceSave = new EventEmitter();
|
|
6951
|
+
this.instanceSaveCompleted = new EventEmitter();
|
|
6952
|
+
this.instanceUpdate = new EventEmitter();
|
|
6953
|
+
this.formValidityUpdate = new EventEmitter();
|
|
6954
|
+
this.formCancel = new EventEmitter();
|
|
6955
|
+
this.FormLoader = () => {
|
|
6956
|
+
return React__default.createElement(CircularLoader$1, { small: true });
|
|
6957
|
+
};
|
|
6958
|
+
this.FormActionButtons = computed(() => {
|
|
6959
|
+
if (this.config().hideActionButtons) {
|
|
6960
|
+
return React__default.createElement(React__default.Fragment, null);
|
|
6961
|
+
}
|
|
6962
|
+
return () => {
|
|
6963
|
+
const [isValid, setIsValid] = useState();
|
|
6964
|
+
const [submitting, setSubmitting] = useState(false);
|
|
6965
|
+
useEffect(() => {
|
|
6966
|
+
const isValidSubscription = this.isFormValid$.subscribe((isValid) => {
|
|
6967
|
+
setIsValid(isValid);
|
|
6968
|
+
});
|
|
6969
|
+
return () => {
|
|
6970
|
+
isValidSubscription.unsubscribe();
|
|
6971
|
+
};
|
|
6972
|
+
}, []);
|
|
6973
|
+
const onSave = () => {
|
|
6974
|
+
setSubmitting(true);
|
|
6975
|
+
this.ngZone.run(async () => {
|
|
6976
|
+
const saveResponse = await this.#saveInstance();
|
|
6977
|
+
this.instanceSaveCompleted.emit(saveResponse);
|
|
6978
|
+
setSubmitting(false);
|
|
6979
|
+
});
|
|
6980
|
+
};
|
|
6981
|
+
return (React__default.createElement(ButtonStrip$1, null,
|
|
6982
|
+
!this.config().hideSubmitButton && (React__default.createElement(Button$1, { primary: true, disabled: !isValid, loading: submitting, onClick: onSave }, this.config().submitButtonLabel)),
|
|
6983
|
+
!this.config().hideCancelButton && (React__default.createElement(Button$1, { onClick: () => {
|
|
6984
|
+
this.ngZone.run(() => {
|
|
6985
|
+
this.onCancel();
|
|
6986
|
+
});
|
|
6987
|
+
} }, this.config().cancelButtonLabel))));
|
|
6988
|
+
};
|
|
6989
|
+
});
|
|
6990
|
+
}
|
|
6991
|
+
async ngOnInit() {
|
|
6992
|
+
this.loading.set(true);
|
|
6993
|
+
try {
|
|
6994
|
+
// Loading metadata
|
|
6995
|
+
const metaData = await new ProgramEntryFormMetaData()
|
|
6996
|
+
.setConfig(this.config())
|
|
6997
|
+
.get();
|
|
6998
|
+
this.metaData.set(metaData);
|
|
6999
|
+
// Load initial instance information
|
|
7000
|
+
const instance = await this.#getInstance();
|
|
7001
|
+
this.instance.set(instance);
|
|
7002
|
+
if (this.config().autoAssignedValues) {
|
|
7003
|
+
this.#updateInstanceWithAutoAssignedValues(this.config().autoAssignedValues);
|
|
7004
|
+
}
|
|
7005
|
+
this.loading.set(false);
|
|
7006
|
+
}
|
|
7007
|
+
catch (err) {
|
|
7008
|
+
this.loading.set(false);
|
|
7009
|
+
}
|
|
7010
|
+
}
|
|
7011
|
+
onFormUpdate(dataValues) {
|
|
7012
|
+
this.#updateInstance(dataValues);
|
|
7013
|
+
if (this.instance()) {
|
|
7014
|
+
this.instanceUpdate.emit(this.instance());
|
|
7015
|
+
}
|
|
7016
|
+
}
|
|
7017
|
+
onValidityUpdate(isFormValid) {
|
|
7018
|
+
this.isFormValid.set(isFormValid);
|
|
7019
|
+
this.formValidityUpdate.emit(isFormValid);
|
|
7020
|
+
}
|
|
7021
|
+
onCancel() {
|
|
7022
|
+
this.formCancel.emit();
|
|
7023
|
+
}
|
|
7024
|
+
#updateInstanceWithAutoAssignedValues(autoAssignedValues) {
|
|
7025
|
+
const assignedDataValues = autoAssignedValues.reduce((entities, assignedValue) => {
|
|
7026
|
+
return {
|
|
7027
|
+
...entities,
|
|
7028
|
+
[assignedValue.field]: assignedValue.value,
|
|
7029
|
+
};
|
|
7030
|
+
}, {});
|
|
7031
|
+
this.#updateInstance(assignedDataValues);
|
|
7032
|
+
}
|
|
7033
|
+
#updateInstance(dataValues) {
|
|
7034
|
+
this.instance.update((instance) => {
|
|
7035
|
+
instance?.updateDataValues(dataValues);
|
|
7036
|
+
return instance;
|
|
7037
|
+
});
|
|
7038
|
+
}
|
|
7039
|
+
async #saveInstance() {
|
|
7040
|
+
switch (this.config().formType) {
|
|
7041
|
+
case 'TRACKER':
|
|
7042
|
+
return this.instanceQuery
|
|
7043
|
+
.setData(this.instance())
|
|
7044
|
+
.save();
|
|
7045
|
+
case 'EVENT':
|
|
7046
|
+
return this.instanceQuery
|
|
7047
|
+
.setData(this.instance())
|
|
7048
|
+
.save();
|
|
7049
|
+
default:
|
|
7050
|
+
return firstValueFrom(of(null));
|
|
7051
|
+
}
|
|
7052
|
+
}
|
|
7053
|
+
async #getTrackerInstance() {
|
|
7054
|
+
this.instanceQuery = this.d2.trackerModule.trackedEntity
|
|
7055
|
+
.setProgram(this.config().program)
|
|
7056
|
+
.setOrgUnit(this.orgUnit());
|
|
7057
|
+
return this.trackedEntity()
|
|
7058
|
+
? (await this.instanceQuery
|
|
7059
|
+
.setTrackedEntity(this.trackedEntity())
|
|
7060
|
+
.get()).data || (await this.instanceQuery.create())
|
|
7061
|
+
: await this.instanceQuery.create();
|
|
7062
|
+
}
|
|
7063
|
+
async #getEventInstance() {
|
|
7064
|
+
this.instanceQuery = this.d2.eventModule.event
|
|
7065
|
+
.setProgram(this.config().program)
|
|
7066
|
+
.setProgramStage(this.config().programStage)
|
|
7067
|
+
.setEnrollment(this.enrollment())
|
|
7068
|
+
.setTrackedEntity(this.trackedEntity())
|
|
7069
|
+
.setOrgUnit(this.orgUnit());
|
|
7070
|
+
return this.event()
|
|
7071
|
+
? (await this.instanceQuery.setEvent(this.event()).get())
|
|
7072
|
+
.data || (await this.instanceQuery.create())
|
|
7073
|
+
: await this.instanceQuery.create();
|
|
7074
|
+
}
|
|
7075
|
+
#getInstance() {
|
|
7076
|
+
switch (this.config().formType) {
|
|
7077
|
+
case 'TRACKER':
|
|
7078
|
+
return this.#getTrackerInstance();
|
|
7079
|
+
case 'EVENT':
|
|
7080
|
+
return this.#getEventInstance();
|
|
7081
|
+
default:
|
|
7082
|
+
return firstValueFrom(of(null));
|
|
7083
|
+
}
|
|
7084
|
+
}
|
|
7085
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.1.8", ngImport: i0, type: ProgramEntryFormModule, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
|
|
7086
|
+
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"] }] }); }
|
|
7087
|
+
}
|
|
7088
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.1.8", ngImport: i0, type: ProgramEntryFormModule, decorators: [{
|
|
7089
|
+
type: Component,
|
|
7090
|
+
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"] }]
|
|
7091
|
+
}], propDecorators: { instanceSave: [{
|
|
7092
|
+
type: Output
|
|
7093
|
+
}], instanceSaveCompleted: [{
|
|
7094
|
+
type: Output
|
|
7095
|
+
}], instanceUpdate: [{
|
|
7096
|
+
type: Output
|
|
7097
|
+
}], formValidityUpdate: [{
|
|
7098
|
+
type: Output
|
|
7099
|
+
}], formCancel: [{
|
|
7100
|
+
type: Output
|
|
7101
|
+
}] } });
|
|
7102
|
+
|
|
7103
|
+
// Copyright 2025 UDSM DHIS2 Lab. All rights reserved.
|
|
7104
|
+
// Use of this source code is governed by a BSD-style
|
|
7105
|
+
// license that can be found in the LICENSE file.
|
|
7106
|
+
|
|
6539
7107
|
/**
|
|
6540
7108
|
* Generated bundle index. Do not edit.
|
|
6541
7109
|
*/
|
|
6542
7110
|
|
|
6543
|
-
export { Boolean$1 as Boolean, BreadcrumbComponent, BreadcrumbModule, ButtonComponent, ButtonModule, CheckBox, D2FormModule, DataTableUIComponent, DataTableUIModule, DateField, DateRangeValue, Dropdown, EventFormComponent, EventFormModule, FieldConfig, FieldControlTypeUtil, FieldDropdown, FieldType, FieldUtil, FormComponent, FormConfig, FormField, FormFieldComponent, FormFieldGroup, FormFieldTypeUtil, FormMetaData, FormMetadataSection, FormUtil, FormValue, FormValueUtil, HeaderBarComponent, HeaderBarModule, LineListModule, LineListTableComponent, MetadataRule, MetadataRuleAction, OrganisationUnitSelectionConfig, OrganisationUnitSelectorComponent, OrganisationUnitSelectorModalComponent, OrganisationUnitSelectorModule, PeriodSelectorComponent, PeriodSelectorModalComponent, PeriodSelectorModule, ReactWrapperModule, RepeatableFormComponent, SectionFormComponent, SelectionFiltersComponent, SelectionFiltersUiModule, TrackerFormComponent, TrackerFormModule, TranslationUtil };
|
|
7111
|
+
export { Boolean$1 as Boolean, BreadcrumbComponent, BreadcrumbModule, ButtonComponent, ButtonModule, CheckBox, D2FormModule, DataTableUIComponent, DataTableUIModule, DateField, DateRangeValue, Dropdown, EventFormComponent, EventFormModule, FieldConfig, FieldControlTypeUtil, FieldDropdown, FieldType, FieldUtil, FlatFormComponent, FormComponent, FormConfig, FormField, FormFieldComponent, FormFieldGroup, FormFieldTypeUtil, FormMetaData, FormMetadataSection, FormUtil, FormValue, FormValueUtil, HeaderBarComponent, HeaderBarModule, LineListModule, LineListTableComponent, MetadataRule, MetadataRuleAction, OrganisationUnitSelectionConfig, OrganisationUnitSelectorComponent, OrganisationUnitSelectorModalComponent, OrganisationUnitSelectorModule, PeriodSelectorComponent, PeriodSelectorModalComponent, PeriodSelectorModule, ProgramEntryFormConfig, ProgramEntryFormMetaData, ProgramEntryFormModule, ProgramEntryFormSection, ReactWrapperModule, RepeatableFormComponent, SectionFormComponent, SelectionFiltersComponent, SelectionFiltersUiModule, TrackerFormComponent, TrackerFormModule, TranslationUtil };
|
|
6544
7112
|
//# sourceMappingURL=iapps-ng-dhis2-ui.mjs.map
|