/**
 * @fileoverview added by tsickle
 * Generated from: lib/fhir/medication/taked-medication/add/taked-medication-add.component.ts
 * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
 */
import * as tslib_1 from "tslib";
import { CAN_NOT_START_WITH_WHITE_SPACE } from './../../../../shared/regular-expressions/regex';
import { Component, Input, Output, EventEmitter } from '@angular/core';
import { AbstractAddComponent } from '../../../../shared/abstracts/add/abstract-add/abstract-add.component';
import { FormGroup, FormControl, FormArray, Validators } from '@angular/forms';
import { ModalController } from '@ionic/angular';
import { AlertService } from '../../../../widgets/entry-components/alert/services/alert.service';
var TakedMedicationAddComponent = /** @class */ (function (_super) {
    tslib_1.__extends(TakedMedicationAddComponent, _super);
    // addingMedication = false;
    // panelOpenState = false;
    function TakedMedicationAddComponent(modalController, alertService) {
        var _this = _super.call(this) || this;
        _this.modalController = modalController;
        _this.alertService = alertService;
        _this.callMedicationSave = new EventEmitter();
        _this.callDelete = new EventEmitter();
        return _this;
    }
    /**
     * @return {?}
     */
    TakedMedicationAddComponent.prototype.ngOnInit = /**
     * @return {?}
     */
    function () {
        if (this.inData) { // update
            this.form.controls.medicationRequest.patchValue(this.inData);
            /*this.form.controls.medicationGroupDisplayer
              .setValue(this.extraData.find((element: IMedication) => (this.inData.basedOn as IReference).reference === element.id).form.text); */
        }
        else { // add
            this.form.get('medicationRequest.subject').setValue({ reference: this.patient.id, display: this.patient.name[0].text });
            this.form.get('medicationRequest.requester').setValue({ display: this.user.displayName, reference: this.user.uid });
            this.form.get('medicationRequest.recorder').setValue({ display: this.user.displayName, reference: this.user.uid });
            this.form.get('medicationRequest.dosageInstruction.0.doseAndRate.0.doseQuantity.unit').setValue(this.doseUnit.value);
        }
    };
    /**
     * @return {?}
     */
    TakedMedicationAddComponent.prototype.resetForm = /**
     * @return {?}
     */
    function () {
        return new FormGroup({
            medicationRequest: new FormGroup({
                id: new FormControl(''),
                authoredOn: new FormControl(new Date().toISOString()),
                basedOn: new FormArray([
                    new FormGroup({
                        reference: new FormControl(''),
                        display: new FormControl('')
                    })
                ]),
                medicationReference: new FormGroup({
                    display: new FormControl('', Validators.compose([Validators.required, Validators.pattern(CAN_NOT_START_WITH_WHITE_SPACE)])),
                }),
                dosageInstruction: new FormArray([
                    new FormGroup({
                        timing: new FormGroup({
                            repeat: new FormGroup({
                                dayOfWeek: new FormControl(''),
                                periodUnit: new FormControl('')
                            })
                        }),
                        doseAndRate: new FormArray([
                            new FormGroup({
                                doseQuantity: new FormGroup({
                                    value: new FormControl(''),
                                    unit: new FormControl('')
                                }),
                                rateQuantity: new FormGroup({
                                    value: new FormControl(''),
                                    unit: new FormControl('')
                                })
                            })
                        ])
                    })
                ]),
                note: new FormArray([
                    new FormGroup({
                        text: new FormControl('')
                    })
                ]),
                dispenseRequest: new FormGroup({
                    validityPeriod: new FormGroup({
                        start: new FormControl(new Date(new Date().getFullYear(), new Date().getMonth(), 1, 0, 0, 0, 0).toString())
                    })
                }),
                subject: new FormGroup({
                    reference: new FormControl(''),
                    display: new FormControl('')
                }),
                requester: new FormGroup({
                    reference: new FormControl(''),
                    display: new FormControl('')
                }),
                recorder: new FormGroup({
                    reference: new FormControl(''),
                    display: new FormControl('')
                }),
                // medicationGroupDisplayer helyett
                category: new FormGroup({
                    text: new FormControl('')
                })
            }),
        });
    };
    // csak a belsőknek kell, hogy req-ek legyenek a külsőknek nem
    // csak a belsőknek kell, hogy req-ek legyenek a külsőknek nem
    /**
     * @return {?}
     */
    TakedMedicationAddComponent.prototype.resetMedicationForm = 
    // csak a belsőknek kell, hogy req-ek legyenek a külsőknek nem
    /**
     * @return {?}
     */
    function () {
        return new FormGroup({
            status: new FormControl('active'),
            code: new FormGroup({
                text: new FormControl('', Validators.required)
            }),
            form: new FormGroup({
                text: new FormControl('', Validators.required)
            }),
            amount: new FormGroup({
                numerator: new FormGroup({
                    value: new FormControl(''),
                    unit: new FormControl('')
                })
            }),
            batch: new FormGroup({
                lotNumber: new FormControl('')
            })
        });
    };
    /**
     * @return {?}
     */
    TakedMedicationAddComponent.prototype.close = /**
     * @return {?}
     */
    function () {
        this.modalController.dismiss();
    };
    /**
     * @param {?} inData
     * @return {?}
     */
    TakedMedicationAddComponent.prototype.submit = /**
     * @param {?} inData
     * @return {?}
     */
    function (inData) {
        this.modalController.dismiss(inData);
    };
    TakedMedicationAddComponent.decorators = [
        { type: Component, args: [{
                    selector: 'inc-taked-medication-add',
                    template: "<form [formGroup]=\"form\" (submit)=\"submit(form.value.medicationRequest)\">\r\n  <ion-grid>\r\n    <span formGroupName=\"medicationRequest\">\r\n      <ion-row>\r\n        <ion-col size=\"12\" size-md=\"12\">\r\n          <ion-item style=\"width: 100%;\" formGroupName=\"medicationReference\">\r\n            <ion-label position=\"floating\">{{'NAME_OF_MEDICINE' | translate}} <span class=\"required\">*</span>\r\n            </ion-label>\r\n            <!-- <ion-select id=\"medication-select\" interface=\"popover\" formControlName=\"reference\"\r\n            (ionChange)=\"medicationChanged($event)\" okText=\"{{'DONE' | translate}}\"\r\n            cancelText=\"{{'CANCEL' | translate}}\" clearInput>\r\n            <ion-select-option *ngFor=\"let medication of extraData\" [value]=\"medication.id\">\r\n              {{medication.code.text | translate}}\r\n            </ion-select-option>\r\n          </ion-select> -->\r\n            <ion-input id=\"medication-name-input\" type=\"text\" formControlName=\"display\" clearInput>\r\n            </ion-input>\r\n          </ion-item>\r\n        </ion-col>\r\n        <!-- <ion-col size=\"2\" size-md=\"2\">\r\n        <ion-button id=\"add-medication-button\" style=\"height: 100%; width: 100%;\" fill=\"clear\"\r\n          [disabled]=\"addingMedication\" (click)=\"openMedicationAdd()\">\r\n          <ion-icon slot=\"icon-only\" name=\"add-circle-outline\"></ion-icon>\r\n        </ion-button>\r\n      </ion-col>\r\n      <ion-col size=\"2\" size-md=\"2\">\r\n        <ion-button id=\"delete-medication-button\" style=\"height: 100%; width: 100%;\" fill=\"clear\"\r\n          [disabled]=\"!form.get('medicationRequest.basedOn.reference').value\"\r\n          (click)=\"openDeleteAlert(form.value.medicationRequest.basedOn.reference)\">\r\n          <ion-icon slot=\"icon-only\" name=\"close-circle-outline\"></ion-icon>\r\n        </ion-button>\r\n      </ion-col> -->\r\n      </ion-row>\r\n      <!-- <ion-row *ngIf=\"addingMedication\" formGroupName=\"medication\">\r\n      <ion-col size=\"12\">\r\n        <mat-accordion>\r\n          <mat-expansion-panel [expanded]=\"panelOpenState\" (opened)=\"panelOpenState = true\"\r\n            (closed)=\"panelOpenState = false\">\r\n            <mat-expansion-panel-header>\r\n              <mat-panel-title> \u00DAj gy\u00F3gyszer hozz\u00E1ad\u00E1sa </mat-panel-title>\r\n              <mat-panel-description class=\"ion-text-left\">\r\n                <ion-text *ngIf=\"form.value.medication.code.text\"> {{form.value.medication.code.text}} </ion-text>\r\n                <ion-text *ngIf=\"form.value.medication.code.text && form.value.medication.form.text\">\r\n                  &nbsp; | &nbsp;\r\n                </ion-text>\r\n                <ion-text *ngIf=\"form.value.medication.form.text\"> {{form.value.medication.form.text}} </ion-text>\r\n              </mat-panel-description>\r\n            </mat-expansion-panel-header>\r\n            <ion-item style=\"width: 100%;\" formGroupName=\"code\">\r\n              <ion-label position=\"floating\">Gy\u00F3gyszer neve</ion-label>\r\n              <ion-input id=\"add-medication-name-input\" type=\"text\" formControlName=\"text\" clearInput>\r\n              </ion-input>\r\n            </ion-item>\r\n            <ion-item style=\"width: 100%;\" formGroupName=\"form\">\r\n              <ion-label position=\"floating\">Gy\u00F3gyszer csoportja</ion-label>\r\n              <ion-input id=\"add-medication-group-input\" type=\"text\" formControlName=\"text\" clearInput>\r\n              </ion-input>\r\n            </ion-item>\r\n            <div style=\"width: 100%;\" class=\"ion-margin-top ion-text-right\">\r\n              <ion-button id=\"add-medication-cancel-button\" fill=\"clear\" color=\"primary\"\r\n                (click)=\"cancelMedicationAdd()\">\r\n                {{'CANCEL_BUTTON' | translate}}\r\n              </ion-button>\r\n              <ion-button id=\"add-medication-save-button\" color=\"primary\"\r\n                (click)=\"submitMedicationAdd(form.value.medication)\" [disabled]=\"form.controls.medication.invalid\">\r\n                {{'READY_BUTTON' | translate}}\r\n              </ion-button>\r\n            </div>\r\n          </mat-expansion-panel>\r\n        </mat-accordion>\r\n      </ion-col>\r\n    </ion-row> -->\r\n      <ion-row>\r\n        <ion-col size=\"12\" size-md=\"12\">\r\n          <ion-item style=\"width: 100%;\" formGroupName=\"category\">\r\n            <ion-label position=\"floating\">{{'MEDICATION_GROUP' | translate}}</ion-label>\r\n            <ion-input id=\"medication-group-input\" type=\"text\" formControlName=\"text\" clearInput>\r\n            </ion-input>\r\n          </ion-item>\r\n        </ion-col>\r\n      </ion-row>\r\n      <span formArrayName=\"dosageInstruction\">\r\n        <span formGroupName=\"0\">\r\n          <span formGroupName=\"timing\">\r\n            <ion-row formGroupName=\"repeat\">\r\n              <ion-col size=\"12\" size-md=\"6\">\r\n                <ion-item>\r\n                  <ion-label position=\"stacked\">{{'DOSAGE' | translate}}</ion-label>\r\n                  <ion-select id=\"dosage-period-select\" interface=\"popover\" formControlName=\"periodUnit\"\r\n                    okText=\"{{'DONE' | translate}}\" cancelText=\"{{'CANCEL' | translate}}\">\r\n                    <ion-select-option *ngFor=\"let dosagePeriod of dosagePeriods\" [value]=\"dosagePeriod.value\">\r\n                      {{dosagePeriod.text | translate}}\r\n                    </ion-select-option>\r\n                  </ion-select>\r\n                </ion-item>\r\n              </ion-col>\r\n              <ion-col size=\"12\" size-md=\"6\">\r\n                <ion-item>\r\n                  <ion-label position=\"stacked\">{{'DAYS' | translate}}</ion-label>\r\n                  <ion-select id=\"days-select\" multiple formControlName=\"dayOfWeek\" okText=\"{{'DONE' | translate}}\"\r\n                    cancelText=\"{{'CANCEL' | translate}}\">\r\n                    <ion-select-option *ngFor=\"let day of days\" [value]=\"day.value\">{{day.text | translate}}\r\n                    </ion-select-option>\r\n                  </ion-select>\r\n                </ion-item>\r\n              </ion-col>\r\n            </ion-row>\r\n          </span>\r\n          <span formArrayName=\"doseAndRate\">\r\n            <ion-row formGroupName=\"0\">\r\n              <ion-col size=\"12\" size-md=\"6\">\r\n                <ion-item formGroupName=\"doseQuantity\">\r\n                  <ion-label position=\"floating\">{{'DOSE' | translate}}\r\n                    <p class=\"unit\">{{doseUnit.text | translate}}</p>\r\n                  </ion-label>\r\n                  <ion-input id=\"dose-input\" type=\"text\" min=\"1\" formControlName=\"value\" clearInput></ion-input>\r\n                </ion-item>\r\n              </ion-col>\r\n              <ion-col size=\"12\" size-md=\"6\">\r\n                <ion-item formGroupName=\"rateQuantity\">\r\n                  <ion-label position=\"floating\">{{'QUANTITY' | translate}}\r\n                    <p class=\"unit\">{{'EG' | translate}} 2x3</p>\r\n                  </ion-label>\r\n                  <ion-input id=\"quantity-input\" type=\"text\" formControlName=\"value\" clearInput></ion-input>\r\n                </ion-item>\r\n              </ion-col>\r\n            </ion-row>\r\n          </span>\r\n        </span>\r\n      </span>\r\n      <ion-row formGroupName=\"dispenseRequest\">\r\n        <ion-col size=\"12\" size-md=\"12\">\r\n          <ion-item formGroupName=\"validityPeriod\">\r\n            <ion-label position=\"floating\">{{'STARTDATE' | translate}}</ion-label>\r\n            <ion-datetime id=\"start-date-datetime\" displayFormat=\"YYYY.MM\" formControlName=\"start\"\r\n              doneText=\"{{'DONE' | translate}}\" cancelText=\"{{'CANCEL' | translate}}\">\r\n            </ion-datetime>\r\n          </ion-item>\r\n        </ion-col>\r\n      </ion-row>\r\n      <ion-row formArrayName=\"note\">\r\n        <ion-col size=\"12\">\r\n          <ion-item formGroupName=\"0\">\r\n            <ion-label position=\"floating\" color=\"primary\">{{'COMMENTS' | translate}}</ion-label>\r\n            <ion-textarea id=\"comments-textarea\" rows=\"3\" auto-grow=\"true\" formControlName=\"text\">\r\n            </ion-textarea>\r\n          </ion-item>\r\n        </ion-col>\r\n      </ion-row>\r\n    </span>\r\n    <ion-row>\r\n      <ion-col size=\"6\" size-md=\"3\" offset-md=\"6\">\r\n        <ion-button id=\"cancel-button\" fill=\"clear\" color=\"primary\" (click)=\"close()\" expand=\"block\">\r\n          {{'CANCEL_BUTTON' | translate}}\r\n        </ion-button>\r\n      </ion-col>\r\n      <ion-col size=\"6\" size-md=\"3\">\r\n        <ion-button id=\"save-button\" color=\"primary\" type=\"submit\" [disabled]=\"form.invalid\" expand=\"block\">\r\n          {{'READY_BUTTON' | translate}}\r\n        </ion-button>\r\n      </ion-col>\r\n    </ion-row>\r\n  </ion-grid>\r\n</form>",
                    styles: [""]
                }] }
    ];
    /** @nocollapse */
    TakedMedicationAddComponent.ctorParameters = function () { return [
        { type: ModalController },
        { type: AlertService }
    ]; };
    TakedMedicationAddComponent.propDecorators = {
        patient: [{ type: Input }],
        user: [{ type: Input }],
        extraData: [{ type: Input }],
        dosagePeriods: [{ type: Input }],
        days: [{ type: Input }],
        doseUnit: [{ type: Input }],
        callMedicationSave: [{ type: Output }],
        callDelete: [{ type: Output }]
    };
    return TakedMedicationAddComponent;
}(AbstractAddComponent));
export { TakedMedicationAddComponent };
if (false) {
    /** @type {?} */
    TakedMedicationAddComponent.prototype.patient;
    /** @type {?} */
    TakedMedicationAddComponent.prototype.user;
    /** @type {?} */
    TakedMedicationAddComponent.prototype.extraData;
    /** @type {?} */
    TakedMedicationAddComponent.prototype.dosagePeriods;
    /** @type {?} */
    TakedMedicationAddComponent.prototype.days;
    /** @type {?} */
    TakedMedicationAddComponent.prototype.doseUnit;
    /** @type {?} */
    TakedMedicationAddComponent.prototype.callMedicationSave;
    /** @type {?} */
    TakedMedicationAddComponent.prototype.callDelete;
    /**
     * @type {?}
     * @private
     */
    TakedMedicationAddComponent.prototype.modalController;
    /**
     * @type {?}
     * @private
     */
    TakedMedicationAddComponent.prototype.alertService;
}
//# sourceMappingURL=data:application/json;base64, 