UNPKG

acr-assist-simulator-module

Version:

This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 1.7.4.

1,087 lines (1,086 loc) 296 kB
import { __values, __extends, __spread } from 'tslib'; import { Injectable, NgModule, InjectionToken, Inject, Component, Input, Output, EventEmitter } from '@angular/core'; import { BehaviorSubject } from 'rxjs/BehaviorSubject'; import { CommonModule } from '@angular/common'; import { FormBuilder, Validators, FormsModule, ReactiveFormsModule } from '@angular/forms'; import { SlideComponent } from 'ngx-bootstrap/carousel/slide.component'; import { CarouselComponent } from 'ngx-bootstrap/carousel/carousel.component'; import { CarouselConfig } from 'ngx-bootstrap/carousel/carousel.config'; import { Http } from '@angular/http'; import 'rxjs/add/operator/map'; var SimulatorState = /** @class */ (function () { function SimulatorState() { this.nonRelevantDataElementIds = []; this.endPointId = ''; this.selectedDecisionPointId = ''; this.selectedDecisionPointLabel = ''; this.selectedBranchLabel = ''; } return SimulatorState; }()); var DataElementValues = /** @class */ (function () { function DataElementValues(values) { this.values = values; } DataElementValues.prototype.addOrUpdate = function (key, value) { this.values[key] = value; }; DataElementValues.prototype.get = function (key) { return this.values[key]; }; DataElementValues.prototype.delete = function (key) { return this.values.delete(key); }; DataElementValues.prototype.getAll = function () { return this.values; }; return DataElementValues; }()); var SimulatorEngineService = /** @class */ (function () { function SimulatorEngineService() { this.endOfRoadReached = false; this.lastConditionMetBranchLevel = 1; this.simulatorStateChanged = new BehaviorSubject(new SimulatorState()); this.dataElementValues = new Map(); this.dataElementTexts = new Map(); } SimulatorEngineService.prototype.getAllDataElementValues = function () { return this.dataElementValues; }; SimulatorEngineService.prototype.getAllDataElementTexts = function () { return this.dataElementTexts; }; SimulatorEngineService.prototype.getDataElementValue = function (dataElementId) { return this.dataElementValues[dataElementId]; }; SimulatorEngineService.prototype.getDataElementText = function (dataElementId) { return this.dataElementTexts[dataElementId]; }; SimulatorEngineService.prototype.addOrUpdateDataElement = function (dataElementId, value, text) { this.dataElementValues[dataElementId] = value; this.dataElementTexts[dataElementId] = text; this.evaluateDecisionPoints(); }; SimulatorEngineService.prototype.evaluateDecisionPoint = function (decisionPoint, branchingLevel, nonRelevantDataElementIds) { if (nonRelevantDataElementIds === void 0) { nonRelevantDataElementIds = []; } var currentBranchCount = 0; var totalBranchesInDecisionPoint = decisionPoint.branches.length; try { for (var _a = __values(decisionPoint.branches), _b = _a.next(); !_b.done; _b = _a.next()) { var branch = _b.value; currentBranchCount++; var conditionMet = false; if (this.endOfRoadReached) { break; } if (branch.compositeCondition !== undefined) { conditionMet = branch.compositeCondition.evaluate(new DataElementValues(this.dataElementValues)); } else if (branch.condition !== undefined) { conditionMet = branch.condition.evaluate(new DataElementValues(this.dataElementValues)); } if (conditionMet) { this.lastConditionMetBranchLevel = branchingLevel; if (nonRelevantDataElementIds === undefined) { nonRelevantDataElementIds = new Array(); } if (branch.notRelevantDataElements !== undefined) { try { for (var _c = __values(branch.notRelevantDataElements.dataElementReferences), _d = _c.next(); !_d.done; _d = _c.next()) { var nonRelevantDataElementReference = _d.value; nonRelevantDataElementIds.push(nonRelevantDataElementReference.dataElementId); } } catch (e_1_1) { e_1 = { error: e_1_1 }; } finally { try { if (_d && !_d.done && (_e = _c.return)) _e.call(_c); } finally { if (e_1) throw e_1.error; } } } if (branch.decisionPoints !== undefined) { try { for (var _f = __values(branch.decisionPoints), _g = _f.next(); !_g.done; _g = _f.next()) { var branchDecisionPoint = _g.value; var newBranchingLevel = branchingLevel + 1; this.evaluateDecisionPoint(branchDecisionPoint, newBranchingLevel, nonRelevantDataElementIds); } } catch (e_2_1) { e_2 = { error: e_2_1 }; } finally { try { if (_g && !_g.done && (_h = _f.return)) _h.call(_f); } finally { if (e_2) throw e_2.error; } } } else if (branch.endPointRef !== undefined) { var simulatorState = new SimulatorState(); simulatorState.endPointId = branch.endPointRef.endPointId; simulatorState.nonRelevantDataElementIds = nonRelevantDataElementIds; simulatorState.selectedBranchLabel = branch.label; simulatorState.selectedDecisionPointId = decisionPoint.id; simulatorState.selectedDecisionPointLabel = decisionPoint.label; this.resetValuesOfNonRelevantDataElements(nonRelevantDataElementIds); this.simulatorStateChanged.next(simulatorState); this.endOfRoadReached = true; break; } } else { if (currentBranchCount >= totalBranchesInDecisionPoint) { this.endOfRoadReached = true; var simulatorState = new SimulatorState(); simulatorState.nonRelevantDataElementIds = nonRelevantDataElementIds; this.resetValuesOfNonRelevantDataElements(nonRelevantDataElementIds); this.simulatorStateChanged.next(simulatorState); return; } else { continue; } } } } catch (e_3_1) { e_3 = { error: e_3_1 }; } finally { try { if (_b && !_b.done && (_j = _a.return)) _j.call(_a); } finally { if (e_3) throw e_3.error; } } var e_3, _j, e_1, _e, e_2, _h; }; SimulatorEngineService.prototype.resetValuesOfNonRelevantDataElements = function (nonRelevantDataElementIds) { try { for (var nonRelevantDataElementIds_1 = __values(nonRelevantDataElementIds), nonRelevantDataElementIds_1_1 = nonRelevantDataElementIds_1.next(); !nonRelevantDataElementIds_1_1.done; nonRelevantDataElementIds_1_1 = nonRelevantDataElementIds_1.next()) { var nonRelevantDataElementId = nonRelevantDataElementIds_1_1.value; var defaultValue = void 0; try { for (var _a = __values(this.template.dataElements), _b = _a.next(); !_b.done; _b = _a.next()) { var dataElement = _b.value; if (dataElement.id === nonRelevantDataElementId) { defaultValue = dataElement.defaultValue; break; } } } catch (e_4_1) { e_4 = { error: e_4_1 }; } finally { try { if (_b && !_b.done && (_c = _a.return)) _c.call(_a); } finally { if (e_4) throw e_4.error; } } this.dataElementValues[nonRelevantDataElementId] = defaultValue; } } catch (e_5_1) { e_5 = { error: e_5_1 }; } finally { try { if (nonRelevantDataElementIds_1_1 && !nonRelevantDataElementIds_1_1.done && (_d = nonRelevantDataElementIds_1.return)) _d.call(nonRelevantDataElementIds_1); } finally { if (e_5) throw e_5.error; } } var e_5, _d, e_4, _c; }; SimulatorEngineService.prototype.evaluateComputedElementDecisionPoint = function (elementId, decisionPoint, branchingLevel) { var currentBranchCount = 0; var totalBranchesInDecisionPoint = decisionPoint.branches.length; try { for (var _a = __values(decisionPoint.branches), _b = _a.next(); !_b.done; _b = _a.next()) { var branch = _b.value; currentBranchCount++; var conditionMet = false; if (this.endOfRoadReached) { break; } if (branch.compositeCondition !== undefined) { conditionMet = branch.compositeCondition.evaluate(new DataElementValues(this.dataElementValues)); } else if (branch.condition !== undefined) { conditionMet = branch.condition.evaluate(new DataElementValues(this.dataElementValues)); } if (conditionMet) { this.lastConditionMetBranchLevel = branchingLevel; if (branch.decisionPoints !== undefined) { try { for (var _c = __values(branch.decisionPoints), _d = _c.next(); !_d.done; _d = _c.next()) { var branchDecisionPoint = _d.value; var newBranchingLevel = branchingLevel + 1; this.evaluateComputedElementDecisionPoint(elementId, branchDecisionPoint, newBranchingLevel); } } catch (e_6_1) { e_6 = { error: e_6_1 }; } finally { try { if (_d && !_d.done && (_e = _c.return)) _e.call(_c); } finally { if (e_6) throw e_6.error; } } } else if (branch.computedValue !== undefined) { this.dataElementValues[elementId] = branch.computedValue.expressionText; this.endOfRoadReached = true; break; } } else { if (currentBranchCount >= totalBranchesInDecisionPoint) { this.endOfRoadReached = true; this.dataElementValues[elementId] = undefined; return; } else { continue; } } } } catch (e_7_1) { e_7 = { error: e_7_1 }; } finally { try { if (_b && !_b.done && (_f = _a.return)) _f.call(_a); } finally { if (e_7) throw e_7.error; } } var e_7, _f, e_6, _e; }; SimulatorEngineService.prototype.evaluateComputedExpressions = function () { this.endOfRoadReached = false; try { for (var _a = __values(this.template.dataElements), _b = _a.next(); !_b.done; _b = _a.next()) { var element = _b.value; if (element.dataElementType === 'ComputedDataElement') { var computedElement = (element); try { for (var _c = __values(computedElement.decisionPoints), _d = _c.next(); !_d.done; _d = _c.next()) { var decisionPoint = _d.value; this.evaluateComputedElementDecisionPoint(element.id, decisionPoint, 1); if (this.dataElementValues[element.id] === undefined && decisionPoint.defaultBranch && decisionPoint.defaultBranch.computedValue) { this.dataElementValues[element.id] = decisionPoint.defaultBranch.computedValue.expressionText; } this.endOfRoadReached = false; } } catch (e_8_1) { e_8 = { error: e_8_1 }; } finally { try { if (_d && !_d.done && (_e = _c.return)) _e.call(_c); } finally { if (e_8) throw e_8.error; } } } } } catch (e_9_1) { e_9 = { error: e_9_1 }; } finally { try { if (_b && !_b.done && (_f = _a.return)) _f.call(_a); } finally { if (e_9) throw e_9.error; } } var e_9, _f, e_8, _e; }; SimulatorEngineService.prototype.evaluateDecisionPoints = function () { this.evaluateComputedExpressions(); this.endOfRoadReached = false; try { for (var _a = __values(this.template.rules.decisionPoints), _b = _a.next(); !_b.done; _b = _a.next()) { var decisionPoint = _b.value; if (this.evaluateDecisionPoint(decisionPoint, 1, new Array())) { break; } } } catch (e_10_1) { e_10 = { error: e_10_1 }; } finally { try { if (_b && !_b.done && (_c = _a.return)) _c.call(_a); } finally { if (e_10) throw e_10.error; } } var e_10, _c; }; SimulatorEngineService.prototype.initialize = function (template) { this.template = template; try { for (var _a = __values(this.template.dataElements), _b = _a.next(); !_b.done; _b = _a.next()) { var dataElement = _b.value; this.dataElementValues[dataElement.id] = dataElement.currentValue; } } catch (e_11_1) { e_11 = { error: e_11_1 }; } finally { try { if (_b && !_b.done && (_c = _a.return)) _c.call(_a); } finally { if (e_11) throw e_11.error; } } var e_11, _c; }; return SimulatorEngineService; }()); SimulatorEngineService.decorators = [ { type: Injectable }, ]; SimulatorEngineService.ctorParameters = function () { return []; }; var CoreModule = /** @class */ (function () { function CoreModule() { } CoreModule.forRoot = function () { return { ngModule: CoreModule, providers: [SimulatorEngineService] }; }; return CoreModule; }()); CoreModule.decorators = [ { type: NgModule, args: [{ imports: [ CommonModule ], declarations: [] },] }, ]; var Template = /** @class */ (function () { function Template() { } return Template; }()); var Metadata = /** @class */ (function () { function Metadata() { } return Metadata; }()); var Diagram = /** @class */ (function () { function Diagram() { } return Diagram; }()); var ArrayCheckerService = /** @class */ (function () { function ArrayCheckerService() { } ArrayCheckerService.prototype.isArray = function (item) { return item instanceof Array; }; return ArrayCheckerService; }()); ArrayCheckerService.decorators = [ { type: Injectable }, ]; ArrayCheckerService.ctorParameters = function () { return []; }; var DiagramService = /** @class */ (function () { function DiagramService(arrayCheckerSeviceService) { this.arrayCheckerSeviceService = arrayCheckerSeviceService; } DiagramService.prototype.returnDiagram = function (diagramJSON) { var diagram = new Diagram(); if (diagramJSON.Attr) { diagram.displaySequence = diagramJSON.Attr.DisplaySequence; diagram.keyDiagram = diagramJSON.Attr.IsKeyDiagram ? diagramJSON.Attr.IsKeyDiagram : false; } else { diagram.displaySequence = undefined; diagram.keyDiagram = false; } diagram.label = diagramJSON.Label; diagram.location = diagramJSON.Location; return diagram; }; DiagramService.prototype.returnDiagrams = function (diagramsAsJSON) { var diagrams = new Array(); if (diagramsAsJSON !== undefined) { if (this.arrayCheckerSeviceService.isArray(diagramsAsJSON)) { try { for (var diagramsAsJSON_1 = __values(diagramsAsJSON), diagramsAsJSON_1_1 = diagramsAsJSON_1.next(); !diagramsAsJSON_1_1.done; diagramsAsJSON_1_1 = diagramsAsJSON_1.next()) { var diagram = diagramsAsJSON_1_1.value; diagrams.push(this.returnDiagram(diagram)); } } catch (e_12_1) { e_12 = { error: e_12_1 }; } finally { try { if (diagramsAsJSON_1_1 && !diagramsAsJSON_1_1.done && (_a = diagramsAsJSON_1.return)) _a.call(diagramsAsJSON_1); } finally { if (e_12) throw e_12.error; } } } else { diagrams.push(this.returnDiagram(diagramsAsJSON)); } } return diagrams; var e_12, _a; }; return DiagramService; }()); DiagramService.decorators = [ { type: Injectable }, ]; DiagramService.ctorParameters = function () { return [ { type: ArrayCheckerService, }, ]; }; var CreationServiceInjectorToken = new InjectionToken('one'); var DecisionPoint = /** @class */ (function () { function DecisionPoint() { } return DecisionPoint; }()); var Branch = /** @class */ (function () { function Branch() { } return Branch; }()); var EndPointRef = /** @class */ (function () { function EndPointRef() { } return EndPointRef; }()); var DataElementRef = /** @class */ (function () { function DataElementRef() { } return DataElementRef; }()); var NotRelevantDataElements = /** @class */ (function () { function NotRelevantDataElements() { } return NotRelevantDataElements; }()); var EqualCondition = /** @class */ (function () { function EqualCondition(conditionType) { this.conditionType = conditionType; } EqualCondition.prototype.evaluate = function (dataElementValues) { var value = dataElementValues.get(this.conditionType.dataElementId); return value === this.conditionType.comparisonValue; }; return EqualCondition; }()); var ConditionType = /** @class */ (function () { function ConditionType() { } return ConditionType; }()); var GreaterThanCondition = /** @class */ (function () { function GreaterThanCondition(conditionType) { this.conditionType = conditionType; } GreaterThanCondition.prototype.evaluate = function (dataElementValues) { var value = (+dataElementValues.get(this.conditionType.dataElementId)); var comparisonValue = -1; if (isNaN(this.conditionType.comparisonValue)) { comparisonValue = (+dataElementValues.get(this.conditionType.comparisonValue)); } else { comparisonValue = (+this.conditionType.comparisonValue); } return value > comparisonValue; }; return GreaterThanCondition; }()); var LessThanCondition = /** @class */ (function () { function LessThanCondition(conditionType) { this.conditionType = conditionType; } LessThanCondition.prototype.evaluate = function (dataElementValues) { var value = (+dataElementValues.get(this.conditionType.dataElementId)); var comparisonValue = -1; if (isNaN(this.conditionType.comparisonValue)) { comparisonValue = (+dataElementValues.get(this.conditionType.comparisonValue)); } else { comparisonValue = (+this.conditionType.comparisonValue); } return value < comparisonValue; }; return LessThanCondition; }()); var GreaterThanOrEqualsCondition = /** @class */ (function () { function GreaterThanOrEqualsCondition(conditionType) { this.conditionType = conditionType; } GreaterThanOrEqualsCondition.prototype.evaluate = function (dataElementValues) { var value = (+dataElementValues.get(this.conditionType.dataElementId)); var comparisonValue = -1; if (isNaN(this.conditionType.comparisonValue)) { comparisonValue = (+dataElementValues.get(this.conditionType.comparisonValue)); } else { comparisonValue = (+this.conditionType.comparisonValue); } return value >= comparisonValue; }; return GreaterThanOrEqualsCondition; }()); var LessThanOrEqualsCondition = /** @class */ (function () { function LessThanOrEqualsCondition(conditionType) { this.conditionType = conditionType; } LessThanOrEqualsCondition.prototype.evaluate = function (dataElementValues) { var value = (+dataElementValues.get(this.conditionType.dataElementId)); var comparisonValue = -1; if (isNaN(this.conditionType.comparisonValue)) { comparisonValue = (+dataElementValues.get(this.conditionType.comparisonValue)); } else { comparisonValue = (+this.conditionType.comparisonValue); } return value <= comparisonValue; }; return LessThanOrEqualsCondition; }()); var ContainsCondition = /** @class */ (function () { function ContainsCondition(conditionType) { this.conditionType = conditionType; } ContainsCondition.prototype.evaluate = function (dataElementValues) { var returnValue = false; var value = dataElementValues.get(this.conditionType.dataElementId); if (value !== undefined) { returnValue = value.indexOf(this.conditionType.comparisonValue) >= 0; } return returnValue; }; return ContainsCondition; }()); var AndCondition = /** @class */ (function () { function AndCondition() { this.conditions = []; this.conditionType = 'AndCondition'; } AndCondition.prototype.evaluate = function (dataElementValues) { var returnValue = true; for (var conditionCounter = 0; conditionCounter < this.conditions.length; conditionCounter++) { var condition = this.conditions[conditionCounter]; var executedCondition = condition.evaluate(dataElementValues); returnValue = (!executedCondition) ? false : (returnValue && executedCondition); if (!returnValue) { break; } } return returnValue; }; return AndCondition; }()); var OrCondition = /** @class */ (function () { function OrCondition() { this.conditions = []; this.conditionType = 'OrCondition'; } OrCondition.prototype.evaluate = function (dataElementValues) { var returnValue = false; for (var conditionCounter = 0; conditionCounter < this.conditions.length; conditionCounter++) { var condition = this.conditions[conditionCounter]; var executedCondition = condition.evaluate(dataElementValues); returnValue = (returnValue || executedCondition); if (returnValue) { break; } } return returnValue; }; return OrCondition; }()); var NotCondition = /** @class */ (function () { function NotCondition() { this.conditions = []; this.conditionType = 'NotCondition'; } NotCondition.prototype.evaluate = function (dataElementValues) { var results = new Array(); try { for (var _a = __values(this.conditions), _b = _a.next(); !_b.done; _b = _a.next()) { var condition = _b.value; results.push(condition.evaluate(dataElementValues)); } } catch (e_13_1) { e_13 = { error: e_13_1 }; } finally { try { if (_b && !_b.done && (_c = _a.return)) _c.call(_a); } finally { if (e_13) throw e_13.error; } } return !(results[0]); var e_13, _c; }; return NotCondition; }()); var ConditionsCreationService = /** @class */ (function () { function ConditionsCreationService(arrayCheckerService) { this.arrayCheckerService = arrayCheckerService; } ConditionsCreationService.prototype.returnConditionType = function (conditionJSON) { var conditionType = new ConditionType(); conditionType.comparisonValue = conditionJSON.Attr.ComparisonValue; conditionType.dataElementId = conditionJSON.Attr.DataElementId; return conditionType; }; ConditionsCreationService.prototype.returnCondition = function (branchJSON) { var condition; if (branchJSON.hasOwnProperty('EqualCondition')) { condition = new EqualCondition(this.returnConditionType(branchJSON.EqualCondition)); } if (branchJSON.hasOwnProperty('GreaterThanCondition')) { condition = new GreaterThanCondition(this.returnConditionType(branchJSON.GreaterThanCondition)); } if (branchJSON.hasOwnProperty('LessThanCondition')) { condition = new LessThanCondition(this.returnConditionType(branchJSON.LessThanCondition)); } if (branchJSON.hasOwnProperty('GreaterThanOrEqualsCondition')) { condition = new GreaterThanOrEqualsCondition(this.returnConditionType(branchJSON.GreaterThanOrEqualsCondition)); } if (branchJSON.hasOwnProperty('LessThanOrEqualsCondition')) { condition = new LessThanOrEqualsCondition(this.returnConditionType(branchJSON.LessThanOrEqualsCondition)); } if (branchJSON.hasOwnProperty('ContainsCondition')) { condition = new ContainsCondition(this.returnConditionType(branchJSON.ContainsCondition)); } return condition; }; ConditionsCreationService.prototype.isComposite = function (compositeElementJSON) { return compositeElementJSON.hasOwnProperty('AndCondition') || compositeElementJSON.hasOwnProperty('OrCondition') || compositeElementJSON.hasOwnProperty('NotCondition'); }; ConditionsCreationService.prototype.returnConditionFromJSON = function (conditionIdentifier, conditionJSON) { var condition; if (conditionIdentifier === 'EqualCondition') { condition = new EqualCondition(this.returnConditionType(conditionJSON)); } if (conditionIdentifier === 'GreaterThanCondition') { condition = new GreaterThanCondition(this.returnConditionType(conditionJSON)); } if (conditionIdentifier === 'LessThanCondition') { condition = new LessThanCondition(this.returnConditionType(conditionJSON)); } if (conditionIdentifier === 'GreaterThanOrEqualsCondition') { condition = new GreaterThanOrEqualsCondition(this.returnConditionType(conditionJSON)); } if (conditionIdentifier === 'LessThanOrEqualsCondition') { condition = new LessThanOrEqualsCondition(this.returnConditionType(conditionJSON)); } if (conditionIdentifier === 'ContainsCondition') { condition = new ContainsCondition(this.returnConditionType(conditionJSON)); } return condition; }; ConditionsCreationService.prototype.returnConditions = function (conditionsJSON) { var conditions; var conditionIdentifiers = ['EqualCondition', 'GreaterThanCondition', 'LessThanCondition', 'GreaterThanOrEqualsCondition', 'LessThanOrEqualsCondition', 'ContainsCondition']; try { for (var conditionIdentifiers_1 = __values(conditionIdentifiers), conditionIdentifiers_1_1 = conditionIdentifiers_1.next(); !conditionIdentifiers_1_1.done; conditionIdentifiers_1_1 = conditionIdentifiers_1.next()) { var conditionIdentifier = conditionIdentifiers_1_1.value; var conditionJSON = conditionsJSON[conditionIdentifier]; if (conditionJSON !== undefined) { conditions = new Array(); if (this.arrayCheckerService.isArray(conditionJSON)) { try { for (var conditionJSON_1 = __values(conditionJSON), conditionJSON_1_1 = conditionJSON_1.next(); !conditionJSON_1_1.done; conditionJSON_1_1 = conditionJSON_1.next()) { var jsonValue = conditionJSON_1_1.value; conditions.push(this.returnConditionFromJSON(conditionIdentifier, jsonValue)); } } catch (e_14_1) { e_14 = { error: e_14_1 }; } finally { try { if (conditionJSON_1_1 && !conditionJSON_1_1.done && (_a = conditionJSON_1.return)) _a.call(conditionJSON_1); } finally { if (e_14) throw e_14.error; } } } else { conditions.push(this.returnConditionFromJSON(conditionIdentifier, conditionJSON)); } } } } catch (e_15_1) { e_15 = { error: e_15_1 }; } finally { try { if (conditionIdentifiers_1_1 && !conditionIdentifiers_1_1.done && (_b = conditionIdentifiers_1.return)) _b.call(conditionIdentifiers_1); } finally { if (e_15) throw e_15.error; } } return conditions; var e_15, _b, e_14, _a; }; ConditionsCreationService.prototype.isHybrid = function (compositeElementJSON) { var compositeExists = compositeElementJSON.hasOwnProperty('AndCondition') || compositeElementJSON.hasOwnProperty('OrCondition') || compositeElementJSON.hasOwnProperty('NotCondition'); var primitiveExists = compositeElementJSON.hasOwnProperty('EqualCondition') || compositeElementJSON.hasOwnProperty('GreaterThanCondition') || compositeElementJSON.hasOwnProperty('LessThanCondition') || compositeElementJSON.hasOwnProperty('GreaterThanOrEqualsCondition') || compositeElementJSON.hasOwnProperty('LessThanOrEqualsCondition') || compositeElementJSON.hasOwnProperty('ContainsCondition'); return compositeExists && primitiveExists; }; ConditionsCreationService.prototype.returnCompositeCondition = function (data) { if (!this.isComposite(data)) { return; } var compositeConditionJSON; var compositeCondition; if (data.hasOwnProperty('AndCondition')) { compositeConditionJSON = data.AndCondition; compositeCondition = new AndCondition(); } else if (data.hasOwnProperty('OrCondition')) { compositeConditionJSON = data.OrCondition; compositeCondition = new OrCondition(); } else if (data.hasOwnProperty('NotCondition')) { compositeConditionJSON = data.NotCondition; compositeCondition = new NotCondition(); } if (!this.isComposite(compositeConditionJSON)) { compositeCondition.conditions = this.returnConditions(compositeConditionJSON); } else if (this.isHybrid(compositeConditionJSON)) { var jsonKeys = Object.keys(compositeConditionJSON); try { for (var jsonKeys_1 = __values(jsonKeys), jsonKeys_1_1 = jsonKeys_1.next(); !jsonKeys_1_1.done; jsonKeys_1_1 = jsonKeys_1.next()) { var jsonKey = jsonKeys_1_1.value; var jsonValue = compositeConditionJSON[jsonKey]; var jsonString = '{"' + jsonKey + '":' + JSON.stringify(jsonValue) + '}'; var jsonObject = JSON.parse(jsonString); if (this.isComposite(jsonObject)) { this.returnInnerConditions(jsonObject, compositeCondition); } else { if (this.arrayCheckerService.isArray(jsonValue)) { try { for (var jsonValue_1 = __values(jsonValue), jsonValue_1_1 = jsonValue_1.next(); !jsonValue_1_1.done; jsonValue_1_1 = jsonValue_1.next()) { var arrayValue = jsonValue_1_1.value; compositeCondition.conditions.push(this.returnConditionFromJSON(jsonKey, arrayValue)); } } catch (e_16_1) { e_16 = { error: e_16_1 }; } finally { try { if (jsonValue_1_1 && !jsonValue_1_1.done && (_a = jsonValue_1.return)) _a.call(jsonValue_1); } finally { if (e_16) throw e_16.error; } } } else { compositeCondition.conditions.push(this.returnConditionFromJSON(jsonKey, jsonValue)); } } } } catch (e_17_1) { e_17 = { error: e_17_1 }; } finally { try { if (jsonKeys_1_1 && !jsonKeys_1_1.done && (_b = jsonKeys_1.return)) _b.call(jsonKeys_1); } finally { if (e_17) throw e_17.error; } } } else { this.returnInnerConditions(compositeConditionJSON, compositeCondition); } return compositeCondition; var e_17, _b, e_16, _a; }; ConditionsCreationService.prototype.returnCompositeConditionFromName = function (elementName) { var compositeCondition; switch (elementName) { case 'AndCondition': { compositeCondition = new AndCondition(); break; } case 'OrCondition': { compositeCondition = new OrCondition(); break; } case 'NotCondition': { compositeCondition = new NotCondition(); } } return compositeCondition; }; ConditionsCreationService.prototype.addConditionsToInnerConditions = function (key, value, compositeCondition) { var condition = this.returnCompositeConditionFromName(key); compositeCondition.conditions.push(condition); if (this.isHybrid(value)) { var jsonKeys = Object.keys(value); try { for (var jsonKeys_2 = __values(jsonKeys), jsonKeys_2_1 = jsonKeys_2.next(); !jsonKeys_2_1.done; jsonKeys_2_1 = jsonKeys_2.next()) { var jsonKey = jsonKeys_2_1.value; var jsonValue = value[jsonKey]; var jsonString = '{"' + jsonKey + '":' + JSON.stringify(jsonValue) + '}'; var jsonObject = JSON.parse(jsonString); if (this.isComposite(jsonObject)) { this.returnInnerConditions(jsonObject, condition); } else { if (this.arrayCheckerService.isArray(jsonValue)) { try { for (var jsonValue_2 = __values(jsonValue), jsonValue_2_1 = jsonValue_2.next(); !jsonValue_2_1.done; jsonValue_2_1 = jsonValue_2.next()) { var arrayValue = jsonValue_2_1.value; condition.conditions.push(this.returnConditionFromJSON(jsonKey, arrayValue)); } } catch (e_18_1) { e_18 = { error: e_18_1 }; } finally { try { if (jsonValue_2_1 && !jsonValue_2_1.done && (_a = jsonValue_2.return)) _a.call(jsonValue_2); } finally { if (e_18) throw e_18.error; } } } else { condition.conditions.push(this.returnConditionFromJSON(jsonKey, jsonValue)); } } } } catch (e_19_1) { e_19 = { error: e_19_1 }; } finally { try { if (jsonKeys_2_1 && !jsonKeys_2_1.done && (_b = jsonKeys_2.return)) _b.call(jsonKeys_2); } finally { if (e_19) throw e_19.error; } } } else if (this.isComposite(value)) { } else { condition.conditions = this.returnConditions(value); } var e_19, _b, e_18, _a; }; ConditionsCreationService.prototype.returnInnerConditions = function (innerConditionsJSON, compositeCondition) { var jsonKeys = Object.keys(innerConditionsJSON); try { for (var jsonKeys_3 = __values(jsonKeys), jsonKeys_3_1 = jsonKeys_3.next(); !jsonKeys_3_1.done; jsonKeys_3_1 = jsonKeys_3.next()) { var key = jsonKeys_3_1.value; var values = innerConditionsJSON[key]; if (this.arrayCheckerService.isArray(values)) { try { for (var values_1 = __values(values), values_1_1 = values_1.next(); !values_1_1.done; values_1_1 = values_1.next()) { var value = values_1_1.value; this.addConditionsToInnerConditions(key, value, compositeCondition); } } catch (e_20_1) { e_20 = { error: e_20_1 }; } finally { try { if (values_1_1 && !values_1_1.done && (_a = values_1.return)) _a.call(values_1); } finally { if (e_20) throw e_20.error; } } } else { this.addConditionsToInnerConditions(key, innerConditionsJSON[key], compositeCondition); } } } catch (e_21_1) { e_21 = { error: e_21_1 }; } finally { try { if (jsonKeys_3_1 && !jsonKeys_3_1.done && (_b = jsonKeys_3.return)) _b.call(jsonKeys_3); } finally { if (e_21) throw e_21.error; } } var e_21, _b, e_20, _a; }; return ConditionsCreationService; }()); ConditionsCreationService.decorators = [ { type: Injectable }, ]; ConditionsCreationService.ctorParameters = function () { return [ { type: ArrayCheckerService, }, ]; }; var TextExpression = /** @class */ (function () { function TextExpression() { } return TextExpression; }()); var ArithmeticExpression = /** @class */ (function () { function ArithmeticExpression() { } return ArithmeticExpression; }()); var ComputedValueCreationService = /** @class */ (function () { function ComputedValueCreationService() { } ComputedValueCreationService.prototype.createComputedValue = function (dataAsJSON) { if (dataAsJSON['TextExpression'] !== undefined) { var computedValue = new TextExpression(); computedValue.expressionText = dataAsJSON.TextExpression; return computedValue; } if (dataAsJSON['ArithmeticExpression'] !== undefined) { { var computedValue = new ArithmeticExpression(); computedValue.expressionText = dataAsJSON.ArithmeticExpression; return computedValue; } } }; return ComputedValueCreationService; }()); ComputedValueCreationService.decorators = [ { type: Injectable }, ]; ComputedValueCreationService.ctorParameters = function () { return []; }; var DecisionPointsCreationService = /** @class */ (function () { function DecisionPointsCreationService(arrayCheckerService, conditionsCreationService, computedValueCreationService) { this.arrayCheckerService = arrayCheckerService; this.conditionsCreationService = conditionsCreationService; this.computedValueCreationService = computedValueCreationService; } DecisionPointsCreationService.prototype.createRelevantDataElementReferences = function (dataElementRefJSON) { var dataElementRef = new DataElementRef(); dataElementRef.dataElementId = dataElementRefJSON.Attr.DataElementId; return dataElementRef; }; DecisionPointsCreationService.prototype.returnBranch = function (branchJSON) { var branch = new Branch(); branch.label = branchJSON.Label; if (branchJSON.EndPointRef) { branch.endPointRef = new EndPointRef(); branch.endPointRef.endPointId = branchJSON.EndPointRef.Attr.EndPointId; } branch.condition = this.conditionsCreationService.returnCondition(branchJSON); branch.computedValue = this.computedValueCreationService.createComputedValue(branchJSON); if (this.conditionsCreationService.isComposite(branchJSON)) { branch.compositeCondition = this.conditionsCreationService.returnCompositeCondition(branchJSON); } if (branchJSON.NotRelevantDataElements) { var notRelevantDataElements = new NotRelevantDataElements(); notRelevantDataElements.dataElementReferences = new Array(); var dataElementRefs = branchJSON.NotRelevantDataElements.DataElementRef; if (this.arrayCheckerService.isArray(dataElementRefs)) { try { for (var dataElementRefs_1 = __values(dataElementRefs), dataElementRefs_1_1 = dataElementRefs_1.next(); !dataElementRefs_1_1.done; dataElementRefs_1_1 = dataElementRefs_1.next()) { var dataElementRefJSON = dataElementRefs_1_1.value; notRelevantDataElements.dataElementReferences.push(this.createRelevantDataElementReferences(dataElementRefJSON)); } } catch (e_22_1) { e_22 = { error: e_22_1 }; } finally { try { if (dataElementRefs_1_1 && !dataElementRefs_1_1.done && (_a = dataElementRefs_1.return)) _a.call(dataElementRefs_1); } finally { if (e_22) throw e_22.error; } } } else { notRelevantDataElements.dataElementReferences.push(this.createRelevantDataElementReferences(dataElementRefs)); } branch.notRelevantDataElements = notRelevantDataElements; } if (branchJSON.DecisionPoint) { branch.decisionPoints = new Array(); this.addDecisionPoints(branchJSON.DecisionPoint, branch.decisionPoints); } return branch; var e_22, _a; }; DecisionPointsCreationService.prototype.addDecisionPoint = function (decsionPointAsJSON, decisionPoints) { var decisionPoint = new DecisionPoint(); if (decsionPointAsJSON.Attr && decsionPointAsJSON.Attr.Id) { decisionPoint.id = decsionPointAsJSON.Attr.Id; } decisionPoint.label = decsionPointAsJSON.Label; var branchesJSON = decsionPointAsJSON.Branch; if (branchesJSON !== undefined) { decisionPoint.branches = new Array(); if (this.arrayCheckerService.isArray(branchesJSON)) { try { for (var branchesJSON_1 = __values(branchesJSON), branchesJSON_1_1 = branchesJSON_1.next(); !branchesJSON_1_1.done; branchesJSON_1_1 = branchesJSON_1.next()) { var branchJSON = branchesJSON_1_1.value; decisionPoint.branches.push(this.returnBranch(branchJSON)); } } catch (e_23_1) { e_23 = { error: e_23_1 }; } finally { try { if (branchesJSON_1_1 && !branchesJSON_1_1.done && (_a = branchesJSON_1.return)) _a.call(branchesJSON_1); } finally { if (e_23) throw e_23.error; } } } else { decisionPoint.branches.push(this.returnBranch(branchesJSON)); } var defaultBranchJSON = decsionPointAsJSON.DefaultBranch; if (defaultBranchJSON !== undefined) { decisionPoint.defaultBranch = this.createDefaultBranch(defaultBranchJSON); } } decisionPoints.push(decisionPoint); var e_23, _a; }; DecisionPointsCreationService.prototype.addDecisionPoints = function (decsionPointsAsJSON, decisionPoints) { if (this.arrayCheckerService.isArray(decsionPointsAsJSON)) { try { for (var decsionPointsAsJSON_1 = __values(decsionPointsAsJSON), decsionPointsAsJSON_1_1 = decsionPointsAsJSON_1.next(); !decsionPointsAsJSON_1_1.done; decsionPointsAsJSON_1_1 = decsionPointsAsJSON_1.next()) { var decisionPoint = decsionPointsAsJSON_1_1.value; this.addDecisionPoint(decisionPoint, decisionPoints); } } catch (e_24_1) { e_24 = { error: e_24_1 }; } finally { try { if (decsionPointsAsJSON_1_1 && !decsionPointsAsJSON_1_1.done && (_a = decsionPointsAsJSON_1.return)) _a.call(decsionPointsAsJSON_1); } finally { if (e_24) throw e_24.error; } } } else { this.addDecisionPoint(decsionPointsAsJSON, decisionPoints); } var e_24, _a; }; DecisionPointsCreationService.prototype.createDecisionPoints = function (data) { var decisionPoints = new Array(); this.addDecisionPoints(data, decisionPoints); return decisionPoints; }; DecisionPointsCreationService.prototype.createDefaultBranch = function (data) { var defaultBranch = new Branch(); defaultBranch.label = 'Default Branch'; defaultBranch.computedValue = this.computedValueCreationService.createComputedValue(data); return defaultBranch; }; return DecisionPointsCreationService; }()); DecisionPointsCreationService.decorators = [ { type: Injectable }, ]; DecisionPointsCreationService.ctorParameters = function () { return [ { type: ArrayCheckerService, }, { type: ConditionsCreationService, }, { type: ComputedValueCreationService, }, ]; }; var Rules = /** @class */ (function () { function Rules() { } return Rules; }()); var TemplatePartial = /** @class */ (function () { function TemplatePartial() { } return TemplatePartial; }()); var TemplateManagerService = /** @class */ (function () { function TemplateManagerService(diagramService, elememtcreationService, arrayCheckerService, decisionPointsCreationService) { this.diagramService = diagramService; this.elememtcreationService = elememtcreationService; this.arrayCheckerService = arrayCheckerService; this.de