UNPKG

acr-assist-simulator-module

Version:

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

1,403 lines (1,367 loc) 278 kB
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'; /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ class SimulatorState { constructor() { this.nonRelevantDataElementIds = []; this.endPointId = ''; this.selectedDecisionPointId = ''; this.selectedDecisionPointLabel = ''; this.selectedBranchLabel = ''; } } /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ class DataElementValues { /** * @param {?} values */ constructor(values) { this.values = values; } /** * @param {?} key * @param {?} value * @return {?} */ addOrUpdate(key, value) { this.values[key] = value; } /** * @param {?} key * @return {?} */ get(key) { return this.values[key]; } /** * @param {?} key * @return {?} */ delete(key) { return this.values.delete(key); } /** * @return {?} */ getAll() { return this.values; } } /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ class SimulatorEngineService { constructor() { this.endOfRoadReached = false; this.lastConditionMetBranchLevel = 1; this.simulatorStateChanged = new BehaviorSubject(new SimulatorState()); this.dataElementValues = new Map(); this.dataElementTexts = new Map(); } /** * @return {?} */ getAllDataElementValues() { return this.dataElementValues; } /** * @return {?} */ getAllDataElementTexts() { return this.dataElementTexts; } /** * @param {?} dataElementId * @return {?} */ getDataElementValue(dataElementId) { return this.dataElementValues[dataElementId]; } /** * @param {?} dataElementId * @return {?} */ getDataElementText(dataElementId) { return this.dataElementTexts[dataElementId]; } /** * @param {?} dataElementId * @param {?} value * @param {?} text * @return {?} */ addOrUpdateDataElement(dataElementId, value, text) { this.dataElementValues[dataElementId] = value; this.dataElementTexts[dataElementId] = text; this.evaluateDecisionPoints(); } /** * @param {?} decisionPoint * @param {?} branchingLevel * @param {?=} nonRelevantDataElementIds * @return {?} */ evaluateDecisionPoint(decisionPoint, branchingLevel, nonRelevantDataElementIds = []) { let /** @type {?} */ currentBranchCount = 0; const /** @type {?} */ totalBranchesInDecisionPoint = decisionPoint.branches.length; for (const /** @type {?} */ branch of decisionPoint.branches) { currentBranchCount++; let /** @type {?} */ 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)); } // console.log( 'Decision Point:- ' + decisionPoint.id + ', Branch:- ' + branch.label + ', Condition Met :- ' + conditionMet); if (conditionMet) { this.lastConditionMetBranchLevel = branchingLevel; if (nonRelevantDataElementIds === undefined) { nonRelevantDataElementIds = new Array(); } if (branch.notRelevantDataElements !== undefined) { for (const /** @type {?} */ nonRelevantDataElementReference of branch.notRelevantDataElements.dataElementReferences) { nonRelevantDataElementIds.push(nonRelevantDataElementReference.dataElementId); } } if (branch.decisionPoints !== undefined) { for (const /** @type {?} */ branchDecisionPoint of branch.decisionPoints) { const /** @type {?} */ newBranchingLevel = branchingLevel + 1; this.evaluateDecisionPoint(branchDecisionPoint, newBranchingLevel, nonRelevantDataElementIds); } } else if (branch.endPointRef !== undefined) { const /** @type {?} */ 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; const /** @type {?} */ simulatorState = new SimulatorState(); simulatorState.nonRelevantDataElementIds = nonRelevantDataElementIds; this.resetValuesOfNonRelevantDataElements(nonRelevantDataElementIds); this.simulatorStateChanged.next(simulatorState); return; } else { continue; } } } } /** * @param {?} nonRelevantDataElementIds * @return {?} */ resetValuesOfNonRelevantDataElements(nonRelevantDataElementIds) { for (const /** @type {?} */ nonRelevantDataElementId of nonRelevantDataElementIds) { let /** @type {?} */ defaultValue; for (const /** @type {?} */ dataElement of this.template.dataElements) { if (dataElement.id === nonRelevantDataElementId) { defaultValue = dataElement.defaultValue; break; } } this.dataElementValues[nonRelevantDataElementId] = defaultValue; } } /** * @param {?} elementId * @param {?} decisionPoint * @param {?} branchingLevel * @return {?} */ evaluateComputedElementDecisionPoint(elementId, decisionPoint, branchingLevel) { let /** @type {?} */ currentBranchCount = 0; const /** @type {?} */ totalBranchesInDecisionPoint = decisionPoint.branches.length; for (const /** @type {?} */ branch of decisionPoint.branches) { currentBranchCount++; let /** @type {?} */ 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) { for (const /** @type {?} */ branchDecisionPoint of branch.decisionPoints) { const /** @type {?} */ newBranchingLevel = branchingLevel + 1; this.evaluateComputedElementDecisionPoint(elementId, branchDecisionPoint, newBranchingLevel); } } 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; } } } } /** * @return {?} */ evaluateComputedExpressions() { this.endOfRoadReached = false; for (const /** @type {?} */ element of this.template.dataElements) { if (element.dataElementType === 'ComputedDataElement') { const /** @type {?} */ computedElement = /** @type {?} */ (element); for (const /** @type {?} */ decisionPoint of computedElement.decisionPoints) { 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; } } } } /** * @return {?} */ evaluateDecisionPoints() { this.evaluateComputedExpressions(); this.endOfRoadReached = false; for (const /** @type {?} */ decisionPoint of this.template.rules.decisionPoints) { if (this.evaluateDecisionPoint(decisionPoint, 1, new Array())) { break; } } } /** * @param {?} template * @return {?} */ initialize(template) { this.template = template; for (const /** @type {?} */ dataElement of this.template.dataElements) { this.dataElementValues[dataElement.id] = dataElement.currentValue; } } } SimulatorEngineService.decorators = [ { type: Injectable }, ]; /** @nocollapse */ SimulatorEngineService.ctorParameters = () => []; /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ class CoreModule { /** * @return {?} */ static forRoot() { return { ngModule: CoreModule, providers: [SimulatorEngineService] }; } } CoreModule.decorators = [ { type: NgModule, args: [{ imports: [ CommonModule ], declarations: [] },] }, ]; /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ class Template { } /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ class Metadata { } /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ class Diagram { } /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ class ArrayCheckerService { constructor() { } /** * @param {?} item * @return {?} */ isArray(item) { return item instanceof Array; } } ArrayCheckerService.decorators = [ { type: Injectable }, ]; /** @nocollapse */ ArrayCheckerService.ctorParameters = () => []; /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ class DiagramService { /** * @param {?} arrayCheckerSeviceService */ constructor(arrayCheckerSeviceService) { this.arrayCheckerSeviceService = arrayCheckerSeviceService; } /** * @param {?} diagramJSON * @return {?} */ returnDiagram(diagramJSON) { const /** @type {?} */ 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; } /** * @param {?} diagramsAsJSON * @return {?} */ returnDiagrams(diagramsAsJSON) { const /** @type {?} */ diagrams = new Array(); if (diagramsAsJSON !== undefined) { if (this.arrayCheckerSeviceService.isArray(diagramsAsJSON)) { for (const /** @type {?} */ diagram of diagramsAsJSON) { diagrams.push(this.returnDiagram(diagram)); } } else { diagrams.push(this.returnDiagram(diagramsAsJSON)); } } return diagrams; } } DiagramService.decorators = [ { type: Injectable }, ]; /** @nocollapse */ DiagramService.ctorParameters = () => [ { type: ArrayCheckerService, }, ]; /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ const CreationServiceInjectorToken = new InjectionToken('one'); /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ class DecisionPoint { } /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ class Branch { } /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ class EndPointRef { } /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ class DataElementRef { } /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ class NotRelevantDataElements { } /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ class EqualCondition { /** * @param {?} conditionType */ constructor(conditionType) { this.conditionType = conditionType; } /** * @param {?} dataElementValues * @return {?} */ evaluate(dataElementValues) { const /** @type {?} */ value = dataElementValues.get(this.conditionType.dataElementId); return value === this.conditionType.comparisonValue; } } /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ class ConditionType { } /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ class GreaterThanCondition { /** * @param {?} conditionType */ constructor(conditionType) { this.conditionType = conditionType; } /** * @param {?} dataElementValues * @return {?} */ evaluate(dataElementValues) { const /** @type {?} */ value = /** @type {?} */ (+dataElementValues.get(this.conditionType.dataElementId)); let /** @type {?} */ comparisonValue = -1; if (isNaN(this.conditionType.comparisonValue)) { comparisonValue = /** @type {?} */ (+dataElementValues.get(this.conditionType.comparisonValue)); } else { comparisonValue = /** @type {?} */ (+this.conditionType.comparisonValue); } return value > comparisonValue; } } /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ class LessThanCondition { /** * @param {?} conditionType */ constructor(conditionType) { this.conditionType = conditionType; } /** * @param {?} dataElementValues * @return {?} */ evaluate(dataElementValues) { const /** @type {?} */ value = /** @type {?} */ (+dataElementValues.get(this.conditionType.dataElementId)); let /** @type {?} */ comparisonValue = -1; if (isNaN(this.conditionType.comparisonValue)) { comparisonValue = /** @type {?} */ (+dataElementValues.get(this.conditionType.comparisonValue)); } else { comparisonValue = /** @type {?} */ (+this.conditionType.comparisonValue); } return value < comparisonValue; } } /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ class GreaterThanOrEqualsCondition { /** * @param {?} conditionType */ constructor(conditionType) { this.conditionType = conditionType; } /** * @param {?} dataElementValues * @return {?} */ evaluate(dataElementValues) { const /** @type {?} */ value = /** @type {?} */ (+dataElementValues.get(this.conditionType.dataElementId)); let /** @type {?} */ comparisonValue = -1; if (isNaN(this.conditionType.comparisonValue)) { comparisonValue = /** @type {?} */ (+dataElementValues.get(this.conditionType.comparisonValue)); } else { comparisonValue = /** @type {?} */ (+this.conditionType.comparisonValue); } return value >= comparisonValue; } } /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ class LessThanOrEqualsCondition { /** * @param {?} conditionType */ constructor(conditionType) { this.conditionType = conditionType; } /** * @param {?} dataElementValues * @return {?} */ evaluate(dataElementValues) { const /** @type {?} */ value = /** @type {?} */ (+dataElementValues.get(this.conditionType.dataElementId)); let /** @type {?} */ comparisonValue = -1; if (isNaN(this.conditionType.comparisonValue)) { comparisonValue = /** @type {?} */ (+dataElementValues.get(this.conditionType.comparisonValue)); } else { comparisonValue = /** @type {?} */ (+this.conditionType.comparisonValue); } return value <= comparisonValue; } } /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ class ContainsCondition { /** * @param {?} conditionType */ constructor(conditionType) { this.conditionType = conditionType; } /** * @param {?} dataElementValues * @return {?} */ evaluate(dataElementValues) { let /** @type {?} */ returnValue = false; const /** @type {?} */ value = dataElementValues.get(this.conditionType.dataElementId); if (value !== undefined) { returnValue = value.indexOf(this.conditionType.comparisonValue) >= 0; } return returnValue; } } /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ class AndCondition { constructor() { this.conditions = []; this.conditionType = 'AndCondition'; } /** * @param {?} dataElementValues * @return {?} */ evaluate(dataElementValues) { let /** @type {?} */ returnValue = true; for (let /** @type {?} */ conditionCounter = 0; conditionCounter < this.conditions.length; conditionCounter++) { const /** @type {?} */ condition = this.conditions[conditionCounter]; const /** @type {?} */ executedCondition = condition.evaluate(dataElementValues); returnValue = (!executedCondition) ? false : (returnValue && executedCondition); if (!returnValue) { break; } } return returnValue; } } /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ class OrCondition { constructor() { this.conditions = []; this.conditionType = 'OrCondition'; } /** * @param {?} dataElementValues * @return {?} */ evaluate(dataElementValues) { let /** @type {?} */ returnValue = false; for (let /** @type {?} */ conditionCounter = 0; conditionCounter < this.conditions.length; conditionCounter++) { const /** @type {?} */ condition = this.conditions[conditionCounter]; const /** @type {?} */ executedCondition = condition.evaluate(dataElementValues); returnValue = (returnValue || executedCondition); if (returnValue) { break; } } return returnValue; } } /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ class NotCondition { constructor() { this.conditions = []; this.conditionType = 'NotCondition'; } /** * @param {?} dataElementValues * @return {?} */ evaluate(dataElementValues) { const /** @type {?} */ results = new Array(); for (const /** @type {?} */ condition of this.conditions) { results.push(condition.evaluate(dataElementValues)); } return !(results[0]); } } /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ class ConditionsCreationService { /** * @param {?} arrayCheckerService */ constructor(arrayCheckerService) { this.arrayCheckerService = arrayCheckerService; } /** * @param {?} conditionJSON * @return {?} */ returnConditionType(conditionJSON) { const /** @type {?} */ conditionType = new ConditionType(); conditionType.comparisonValue = conditionJSON.Attr.ComparisonValue; conditionType.dataElementId = conditionJSON.Attr.DataElementId; return conditionType; } /** * @param {?} branchJSON * @return {?} */ returnCondition(branchJSON) { let /** @type {?} */ 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; } /** * @param {?} compositeElementJSON * @return {?} */ isComposite(compositeElementJSON) { return compositeElementJSON.hasOwnProperty('AndCondition') || compositeElementJSON.hasOwnProperty('OrCondition') || compositeElementJSON.hasOwnProperty('NotCondition'); } /** * @param {?} conditionIdentifier * @param {?} conditionJSON * @return {?} */ returnConditionFromJSON(conditionIdentifier, conditionJSON) { let /** @type {?} */ 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; } /** * @param {?} conditionsJSON * @return {?} */ returnConditions(conditionsJSON) { let /** @type {?} */ conditions; const /** @type {?} */ conditionIdentifiers = ['EqualCondition', 'GreaterThanCondition', 'LessThanCondition', 'GreaterThanOrEqualsCondition', 'LessThanOrEqualsCondition', 'ContainsCondition']; for (const /** @type {?} */ conditionIdentifier of conditionIdentifiers) { const /** @type {?} */ conditionJSON = conditionsJSON[conditionIdentifier]; if (conditionJSON !== undefined) { conditions = new Array(); if (this.arrayCheckerService.isArray(conditionJSON)) { for (const /** @type {?} */ jsonValue of conditionJSON) { conditions.push(this.returnConditionFromJSON(conditionIdentifier, jsonValue)); } } else { conditions.push(this.returnConditionFromJSON(conditionIdentifier, conditionJSON)); } } } return conditions; } /** * @param {?} compositeElementJSON * @return {?} */ isHybrid(compositeElementJSON) { const /** @type {?} */ compositeExists = compositeElementJSON.hasOwnProperty('AndCondition') || compositeElementJSON.hasOwnProperty('OrCondition') || compositeElementJSON.hasOwnProperty('NotCondition'); const /** @type {?} */ primitiveExists = compositeElementJSON.hasOwnProperty('EqualCondition') || compositeElementJSON.hasOwnProperty('GreaterThanCondition') || compositeElementJSON.hasOwnProperty('LessThanCondition') || compositeElementJSON.hasOwnProperty('GreaterThanOrEqualsCondition') || compositeElementJSON.hasOwnProperty('LessThanOrEqualsCondition') || compositeElementJSON.hasOwnProperty('ContainsCondition'); return compositeExists && primitiveExists; } /** * @param {?} data * @return {?} */ returnCompositeCondition(data) { if (!this.isComposite(data)) { return; } let /** @type {?} */ compositeConditionJSON; let /** @type {?} */ 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)) { const /** @type {?} */ jsonKeys = Object.keys(compositeConditionJSON); for (const /** @type {?} */ jsonKey of jsonKeys) { const /** @type {?} */ jsonValue = compositeConditionJSON[jsonKey]; const /** @type {?} */ jsonString = '{"' + jsonKey + '":' + JSON.stringify(jsonValue) + '}'; const /** @type {?} */ jsonObject = JSON.parse(jsonString); if (this.isComposite(jsonObject)) { this.returnInnerConditions(jsonObject, compositeCondition); } else { if (this.arrayCheckerService.isArray(jsonValue)) { for (const /** @type {?} */ arrayValue of jsonValue) { compositeCondition.conditions.push(this.returnConditionFromJSON(jsonKey, arrayValue)); } } else { compositeCondition.conditions.push(this.returnConditionFromJSON(jsonKey, jsonValue)); } } } } else { this.returnInnerConditions(compositeConditionJSON, compositeCondition); } return compositeCondition; } /** * @param {?} elementName * @return {?} */ returnCompositeConditionFromName(elementName) { let /** @type {?} */ compositeCondition; switch (elementName) { case 'AndCondition': { compositeCondition = new AndCondition(); break; } case 'OrCondition': { compositeCondition = new OrCondition(); break; } case 'NotCondition': { compositeCondition = new NotCondition(); } } return compositeCondition; } /** * @param {?} key * @param {?} value * @param {?} compositeCondition * @return {?} */ addConditionsToInnerConditions(key, value, compositeCondition) { const /** @type {?} */ condition = this.returnCompositeConditionFromName(key); compositeCondition.conditions.push(condition); if (this.isHybrid(value)) { const /** @type {?} */ jsonKeys = Object.keys(value); for (const /** @type {?} */ jsonKey of jsonKeys) { const /** @type {?} */ jsonValue = value[jsonKey]; const /** @type {?} */ jsonString = '{"' + jsonKey + '":' + JSON.stringify(jsonValue) + '}'; const /** @type {?} */ jsonObject = JSON.parse(jsonString); if (this.isComposite(jsonObject)) { this.returnInnerConditions(jsonObject, condition); } else { if (this.arrayCheckerService.isArray(jsonValue)) { for (const /** @type {?} */ arrayValue of jsonValue) { condition.conditions.push(this.returnConditionFromJSON(jsonKey, arrayValue)); } } else { condition.conditions.push(this.returnConditionFromJSON(jsonKey, jsonValue)); } } } } else if (this.isComposite(value)) { // console.log( 'isComposite'); } else { condition.conditions = this.returnConditions(value); } } /** * @param {?} innerConditionsJSON * @param {?} compositeCondition * @return {?} */ returnInnerConditions(innerConditionsJSON, compositeCondition) { const /** @type {?} */ jsonKeys = Object.keys(innerConditionsJSON); for (const /** @type {?} */ key of jsonKeys) { const /** @type {?} */ values = innerConditionsJSON[key]; if (this.arrayCheckerService.isArray(values)) { for (const /** @type {?} */ value of values) { this.addConditionsToInnerConditions(key, value, compositeCondition); } } else { this.addConditionsToInnerConditions(key, innerConditionsJSON[key], compositeCondition); } } } } ConditionsCreationService.decorators = [ { type: Injectable }, ]; /** @nocollapse */ ConditionsCreationService.ctorParameters = () => [ { type: ArrayCheckerService, }, ]; /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ class TextExpression { } /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ class ArithmeticExpression { } /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ class ComputedValueCreationService { constructor() { } /** * @param {?} dataAsJSON * @return {?} */ createComputedValue(dataAsJSON) { if (dataAsJSON['TextExpression'] !== undefined) { const /** @type {?} */ computedValue = new TextExpression(); computedValue.expressionText = dataAsJSON.TextExpression; return computedValue; } if (dataAsJSON['ArithmeticExpression'] !== undefined) { { const /** @type {?} */ computedValue = new ArithmeticExpression(); computedValue.expressionText = dataAsJSON.ArithmeticExpression; return computedValue; } } } } ComputedValueCreationService.decorators = [ { type: Injectable }, ]; /** @nocollapse */ ComputedValueCreationService.ctorParameters = () => []; /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ class DecisionPointsCreationService { /** * @param {?} arrayCheckerService * @param {?} conditionsCreationService * @param {?} computedValueCreationService */ constructor(arrayCheckerService, conditionsCreationService, computedValueCreationService) { this.arrayCheckerService = arrayCheckerService; this.conditionsCreationService = conditionsCreationService; this.computedValueCreationService = computedValueCreationService; } /** * @param {?} dataElementRefJSON * @return {?} */ createRelevantDataElementReferences(dataElementRefJSON) { const /** @type {?} */ dataElementRef = new DataElementRef(); dataElementRef.dataElementId = dataElementRefJSON.Attr.DataElementId; return dataElementRef; } /** * @param {?} branchJSON * @return {?} */ returnBranch(branchJSON) { const /** @type {?} */ 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) { const /** @type {?} */ notRelevantDataElements = new NotRelevantDataElements(); notRelevantDataElements.dataElementReferences = new Array(); const /** @type {?} */ dataElementRefs = branchJSON.NotRelevantDataElements.DataElementRef; if (this.arrayCheckerService.isArray(dataElementRefs)) { for (const /** @type {?} */ dataElementRefJSON of dataElementRefs) { notRelevantDataElements.dataElementReferences.push(this.createRelevantDataElementReferences(dataElementRefJSON)); } } 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; } /** * @param {?} decsionPointAsJSON * @param {?} decisionPoints * @return {?} */ addDecisionPoint(decsionPointAsJSON, decisionPoints) { const /** @type {?} */ decisionPoint = new DecisionPoint(); if (decsionPointAsJSON.Attr && decsionPointAsJSON.Attr.Id) { decisionPoint.id = decsionPointAsJSON.Attr.Id; } decisionPoint.label = decsionPointAsJSON.Label; const /** @type {?} */ branchesJSON = decsionPointAsJSON.Branch; if (branchesJSON !== undefined) { decisionPoint.branches = new Array(); if (this.arrayCheckerService.isArray(branchesJSON)) { for (const /** @type {?} */ branchJSON of branchesJSON) { decisionPoint.branches.push(this.returnBranch(branchJSON)); } } else { decisionPoint.branches.push(this.returnBranch(branchesJSON)); } const /** @type {?} */ defaultBranchJSON = decsionPointAsJSON.DefaultBranch; if (defaultBranchJSON !== undefined) { decisionPoint.defaultBranch = this.createDefaultBranch(defaultBranchJSON); } } decisionPoints.push(decisionPoint); } /** * @param {?} decsionPointsAsJSON * @param {?} decisionPoints * @return {?} */ addDecisionPoints(decsionPointsAsJSON, decisionPoints) { if (this.arrayCheckerService.isArray(decsionPointsAsJSON)) { for (const /** @type {?} */ decisionPoint of decsionPointsAsJSON) { this.addDecisionPoint(decisionPoint, decisionPoints); } } else { this.addDecisionPoint(decsionPointsAsJSON, decisionPoints); } } /** * @param {?} data * @return {?} */ createDecisionPoints(data) { const /** @type {?} */ decisionPoints = new Array(); this.addDecisionPoints(data, decisionPoints); return decisionPoints; } /** * @param {?} data * @return {?} */ createDefaultBranch(data) { const /** @type {?} */ defaultBranch = new Branch(); defaultBranch.label = 'Default Branch'; defaultBranch.computedValue = this.computedValueCreationService.createComputedValue(data); return defaultBranch; } } DecisionPointsCreationService.decorators = [ { type: Injectable }, ]; /** @nocollapse */ DecisionPointsCreationService.ctorParameters = () => [ { type: ArrayCheckerService, }, { type: ConditionsCreationService, }, { type: ComputedValueCreationService, }, ]; /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ class Rules { } /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ class TemplatePartial { } /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ class TemplateManagerService { /** * @param {?} diagramService * @param {?} elememtcreationService * @param {?} arrayCheckerService * @param {?} decisionPointsCreationService */ constructor(diagramService, elememtcreationService, arrayCheckerService, decisionPointsCreationService) { this.diagramService = diagramService; this.elememtcreationService = elememtcreationService; this.arrayCheckerService = arrayCheckerService; this.decisionPointsCreationService = decisionPointsCreationService; this.endPointXMLString = []; this.stringParser = require('string'); } /** * @param {?} templateContent * @return {?} */ getTemplate(templateContent) { const /** @type {?} */ template = new Template(); let /** @type {?} */ templateContentAsJSON; templateContentAsJSON = this.parseToJson(templateContent); if (template === undefined) { throw new Error('Unable to parse the template'); } template.metadata = this.getMetaData(templateContentAsJSON.Metadata); template.dataElements = this.getDataElements(templateContentAsJSON.DataElements); if (templateContentAsJSON.Rules) { template.rules = new Rules(); template.rules.decisionPoints = this.decisionPointsCreationService. createDecisionPoints(templateContentAsJSON.Rules.DecisionPoint); } template.templatePartial = this.returnEndpoints(templateContent); template.endPointsString = this.endPointXMLString; template.xmlContent = templateContent; return template; } /** * @param {?} templatePartialJSON * @return {?} */ getTemplatePartial(templatePartialJSON) { const /** @type {?} */ templatePartial = new TemplatePartial; templatePartial.id = templatePartialJSON.Attr.Id; templatePartial.sectionIfNotValue = templatePartialJSON.SectionIfValueNot; templatePartial.sectionIfValues = templatePartialJSON.SectionIfValue; return templatePartial; } /** * @param {?} content * @param {?} startToken * @param {?} endToken * @return {?} */ returnEndPointContents(content, startToken, endToken) { const /** @type {?} */ contents = new Array(); let /** @type {?} */ templateSearchIndexPosition = 0; while (true) { const /** @type {?} */ contentStartPosition = content.indexOf(startToken, templateSearchIndexPosition); const /** @type {?} */ contentEndPosition = content.indexOf(endToken, templateSearchIndexPosition); if (contentStartPosition >= 0 && contentEndPosition >= 0) { const /** @type {?} */ endPosition = contentEndPosition + endToken.length; const /** @type {?} */ contentData = content.substring(contentStartPosition, endPosition); contents.push(contentData); templateSearchIndexPosition = endPosition + 1; } else { break; } } return contents; } /** * @param {?} templatePartialArray * @return {?} */ returnTemplatePartials(templatePartialArray) { const /** @type {?} */ templatePartials = new Array(); for (const /** @type {?} */ arrayItem of templatePartialArray) { const /** @type {?} */ templatePartial = new TemplatePartial(); const /** @type {?} */ templatePartialAsJSON = this.parseToJson(arrayItem); templatePartial.id = templatePartialAsJSON.Attr.Id; } return templatePartials; } /** * @param {?} xmlData * @return {?} */ returnEndpoints(xmlData) { const /** @type {?} */ endPointStartToken = '<EndPoints>'; const /** @type {?} */ endPointEndToken = '</EndPoints>'; const /** @type {?} */ endPointStartTokenPosition = xmlData.indexOf(endPointStartToken); const /** @type {?} */ endPointEndTokenPosition = xmlData.indexOf(endPointEndToken); if (endPointStartTokenPosition >= 0 && endPointEndTokenPosition >= 0) { const /** @type {?} */ contentStartPosition = (endPointStartTokenPosition + endPointStartToken.length); const /** @type {?} */ endPointContent = xmlData.substring(contentStartPosition, endPointEndTokenPosition); if (endPointContent.length > 0) { const /** @type {?} */ templatePartials = this.returnEndPointContents(endPointContent, '<TemplatePartial', '</TemplatePartial>'); this.endPointXMLString = this.returnEndPointContents(endPointContent, '<EndPoint', '</EndPoint>'); return templatePartials; } } } /** * @param {?} xmlData * @return {?} */ parseToJson(xmlData) { let /** @type {?} */ jsonResult; const /** @type {?} */ parseString = require('xml2js').parseString; parseString(xmlData, { explicitRoot: false, explicitArray: false, attrkey: 'Attr' }, function (err, result) { jsonResult = result; }); return jsonResult; } /** * @param {?} metadataJSON * @return {?} */ getMetaData(metadataJSON) { const /** @type {?} */ metadata = new Metadata(); metadata.label = metadataJSON.Label; metadata.id = metadataJSON.ID; metadata.schemaVersion = metadataJSON.SchemaVersion; metadata.ruleVersion = metadataJSON.RuleVersion; const /** @type {?} */ diagramsAsJSON = metadataJSON.Info.Diagrams.Diagram; metadata.diagrams = this.diagramService.returnDiagrams(diagramsAsJSON); return metadata; } /** * @param {?} elementType * @param {?} dataElementsJSON * @return {?} */ returnDataElement(elementType, dataElementsJSON) { const /** @type {?} */ dataElements = new Array(); let /** @type {?} */ dataElementCreationServiceInstance; for (const /** @type {?} */ dataElementCreationService of this.elememtcreationService) { if (dataElementCreationService.elementType === elementType) { dataElementCreationServiceInstance = dataElementCreationService; break; } } if (dataElementCreationServiceInstance !== undefined && dataElementsJSON !== undefined) { if (this.arrayCheckerService.isArray(dataElementsJSON)) { for (const /** @type {?} */ dataElementJSON of dataElementsJSON) { const /** @type {?} */ dataElement = dataElementCreationServiceInstance.createElement(dataElementJSON); dataElements.push(dataElement); } } else { const /** @type {?} */ dataElement = dataElementCreationServiceInstance.createElement(dataElementsJSON); dataElements.push(dataElement); } } return dataElements; } /** * @param {?} dataElementsJSON * @return {?} */ getDataElements(dataElementsJSON) { let /** @type {?} */ dataElements = new Array(); dataElements = dataElements.concat(this.returnDataElement('ChoiceDataElement', dataElementsJSON.ChoiceDataElement)); dataElements = dataElements.concat(this.returnDataElement('MultiChoiceDataElement', dataElementsJSON.MultiChoiceDataElement)); dataElements = dataElements.concat(this.returnDataElement('NumericDataElement', dataElementsJSON.NumericDataElement)); dataElements = dataElements.concat(this.returnDataElement('GlobalValue', dataElementsJSON.GlobalValue)); dataElements = dataElements.concat(this.returnDataElement('ComputedDataElement', dataElementsJSON.ComputedDataElement)); dataElements = dataElements.concat(this.returnDataElement('IntegerDataElement', dataElementsJSON.IntegerDataElement)); return dataElements; } } TemplateManagerService.decorators = [ { type: Injectable }, ]; /** @nocollapse */ TemplateManagerService.ctorParameters = () => [ { type: DiagramService, }, { type: Array, decorators: [{ type: Inject, args: [CreationServiceInjectorToken,] },] }, { type: ArrayCheckerService, }, { type: DecisionPointsCreationService, }, ]; /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ class AllTextReport { } /** @enum {number} */ const ReportTextPosition = { Down: 0, Right: 1, }; ReportTextPosition[ReportTextPosition.Down] = "Down"; ReportTextPosition[ReportTextPosition.Right] = "Right"; /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ class AcrAssistSimulatorComponent { /** * @param {?} templateManagerService * @param {?} simulatorEngineService */ constructor(templateManagerService, simulatorEngineService) { this.templateManagerService = templateManagerService; this.simulatorEngineService = simulatorEngineService; this.returnExecutionHistory = new EventEmitter(); this.returnDefaultElements = new EventEmitter(); this.inputValues = []; this.position = ReportTextPosition; } /** * @param {?} changes * @return {?} */ ngOnChanges(changes) { this.isReset = true; this.isEmptyContent = this.templateContent === undefined || this.templateContent.length === 0 && this.inputValues.length === 0 && this.inputData === undefined; if (this.isEmptyContent) { return; } if (this.inputData !== undefined) { if (this.inputData.length > 0) { this.inputValues = JSON.parse(this.inputData); } } this.template = this.templateManagerService.getTemplate(this.templateContent); this.simulatorEngineService.initialize(this.template); if (this.inputValues.length !== 0) { for (const /** @type {?} */ dataeElement of this.template.dataElements) { const /** @type {?} */ inputValue = this.inputValues.filter(x => x.dataElementId === dataeElement.id); if (inputValue !== undefined && inputValue.length > 0) { dataeElement.currentValue = inputValue[0].dataElementValue; } } } this.dataElements = this.template.dataElements; for (let /** @type {?} */ index = 0; index < this.template.metadata.diagrams.length; index++) { if (this.template.metadata.diagrams[index].keyDiagram) { const /** @type {?} */ element = new Diagram(); element.label = this.template.metadata.diagrams[index].label; element.location = this.imagePath + '/' + this.template.metadata.diagrams[index].location;