acr-assist-simulator-module
Version:
This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 1.7.4.
1,315 lines (1,285 loc) • 757 kB
JavaScript
import { Injectable, NgModule, InjectionToken, Inject, Component, Input, Output, EventEmitter, ViewChild, Directive, ElementRef, HostListener } from '@angular/core';
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
import { isArray } from 'util';
import { CommonModule } from '@angular/common';
import { Subject } from 'rxjs/internal/Subject';
import { DomSanitizer } from '@angular/platform-browser';
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 { DragScrollModule } from 'ngx-drag-scroll';
import { AngularDateTimePickerModule } from 'angular2-datetimepicker';
import { DurationPickerModule } from 'ngx-duration-picker';
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 ArithmeticExpression {
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
const /** @type {?} */ expressionParser = require('expr-eval').Parser;
class SimulatorEngineService {
constructor() {
this.endOfRoadReached = false;
this.lastConditionMetBranchLevel = 1;
this.nonRelevantDataElementIds = new Array();
this.simulatorStateChanged = new BehaviorSubject(new SimulatorState());
this.dataElementValues = new Map();
this.dataElementTexts = new Map();
this.nonRelevantDataElementIds = new Array();
}
/**
* @return {?}
*/
getTemplate() {
return this.template;
}
/**
* @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
* @return {?}
*/
evaluateDecisionPoint(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 (nonRelevantDataElementIds === undefined) {
// nonRelevantDataElementIds = new Array<string>();
// }
// if (branch.notRelevantDataElements !== undefined) {
// for (const 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);
this.evaluateDecisionPoint(branchDecisionPoint, newBranchingLevel);
}
}
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) {
// console.log(this.template.dataElements);
if (nonRelevantDataElementIds !== undefined) {
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;
if (branch.computedValue instanceof ArithmeticExpression) {
this.dataElementValues[elementId] = this.evaluateArithmeticExpression(branch.computedValue.expressionText);
this.endOfRoadReached = true;
}
else {
this.dataElementValues[elementId] = branch.computedValue.expressionText;
this.endOfRoadReached = true;
}
break;
}
}
else {
if (currentBranchCount >= totalBranchesInDecisionPoint) {
this.endOfRoadReached = true;
this.dataElementValues[elementId] = undefined;
return;
}
else {
continue;
}
}
}
}
/**
* @param {?} computedValue
* @return {?}
*/
evaluateArithmeticExpression(computedValue) {
let /** @type {?} */ startIndex = 0;
let /** @type {?} */ endIndex = 0;
while (startIndex !== -1 && endIndex !== -1) {
startIndex = computedValue.indexOf('{');
endIndex = computedValue.indexOf('}');
if (startIndex !== -1 && endIndex !== -1) {
const /** @type {?} */ dataElementId = computedValue.substring(startIndex + 1, endIndex);
const /** @type {?} */ replacingValue = computedValue.substring(startIndex, endIndex + 1);
let /** @type {?} */ dataElementValue = this.dataElementValues[dataElementId];
if (isArray(dataElementValue)) {
let /** @type {?} */ sum = 0;
dataElementValue.forEach(val => {
sum += +val;
});
dataElementValue = sum;
}
computedValue = computedValue.replace(replacingValue, dataElementValue);
}
}
return expressionParser.evaluate(computedValue).toString();
}
/**
* @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;
}
}
}
}
/**
* @param {?} dataelement
* @param {?=} nonRelevantDataElementIds
* @return {?}
*/
evaluateConditionalProperty(dataelement, nonRelevantDataElementIds = []) {
if (dataelement.conditionalProperties !== undefined) {
let /** @type {?} */ conditionMet = false;
for (const /** @type {?} */ conditionalProperty of dataelement.conditionalProperties) {
if (conditionalProperty.condition !== undefined) {
conditionMet = conditionalProperty.condition.evaluate(new DataElementValues(this.dataElementValues));
}
else if (conditionalProperty.compositeCondition !== undefined) {
conditionMet = conditionalProperty.compositeCondition.evaluate(new DataElementValues(this.dataElementValues));
}
if (conditionMet) {
if (nonRelevantDataElementIds === undefined) {
this.nonRelevantDataElementIds = new Array();
}
if (conditionalProperty.isRelevant === 'false') {
this.nonRelevantDataElementIds.push(dataelement.id);
}
else {
dataelement.displaySequence = conditionalProperty.DisplaySequence;
dataelement.isRequired = conditionalProperty.isRequired !== undefined ?
(conditionalProperty.isRequired.toLowerCase() === 'true' ? true : false)
: true;
if (conditionalProperty.Minimum !== undefined && conditionalProperty.Minimum != null) {
dataelement.minimum = +conditionalProperty.Minimum;
}
if (conditionalProperty.Maximum !== undefined && conditionalProperty.Maximum != null) {
dataelement.maximum = +conditionalProperty.Maximum;
}
if (dataelement.dataElementType === 'ChoiceDataElement') {
(/** @type {?} */ (dataelement)).ChoiceNotRelevant = conditionalProperty.ChoiceNotRelevant;
}
if (dataelement.dataElementType === 'MultiChoiceDataElement') {
(/** @type {?} */ (dataelement)).ChoiceNotRelevant = conditionalProperty.ChoiceNotRelevant;
}
if (dataelement.dataElementType === 'DurationDataElement') {
(/** @type {?} */ (dataelement)).MinimumDay = +conditionalProperty.MinimumDay;
(/** @type {?} */ (dataelement)).MaximumDay = +conditionalProperty.MaximumDay;
(/** @type {?} */ (dataelement)).MinimumHours = +conditionalProperty.MinimumHours;
(/** @type {?} */ (dataelement)).MaximumHours = +conditionalProperty.MaximumHours;
(/** @type {?} */ (dataelement)).MinimumMinutes = +conditionalProperty.MinimumMinutes;
(/** @type {?} */ (dataelement)).MaxmimumMinutes = +conditionalProperty.MaxmimumMinutes;
}
}
return this.nonRelevantDataElementIds;
}
else {
if (dataelement.dataElementType === 'ChoiceDataElement') {
(/** @type {?} */ (dataelement)).ChoiceNotRelevant = new Array();
}
if (dataelement.dataElementType === 'MultiChoiceDataElement') {
(/** @type {?} */ (dataelement)).ChoiceNotRelevant = new Array();
}
}
}
}
}
/**
* @return {?}
*/
isCondtionMet() {
for (const /** @type {?} */ dataelement of this.template.dataElements) {
if (dataelement.conditionalProperties !== undefined) {
let /** @type {?} */ conditionMet = false;
for (const /** @type {?} */ conditionalProperty of dataelement.conditionalProperties) {
if (conditionalProperty.condition !== undefined) {
conditionMet = conditionalProperty.condition.evaluate(new DataElementValues(this.dataElementValues));
}
else if (conditionalProperty.compositeCondition !== undefined) {
conditionMet = conditionalProperty.compositeCondition.evaluate(new DataElementValues(this.dataElementValues));
}
if (conditionMet) {
return true;
}
return false;
}
}
}
}
/**
* @return {?}
*/
evaluateDecisionAndConditionalProperty() {
this.nonRelevantDataElementIds = new Array();
this.RevertConditionValues();
for (const /** @type {?} */ dataelement of this.template.dataElements) {
this.evaluateConditionalProperty(dataelement, new Array());
}
this.resetValuesOfNonRelevantDataElements(this.nonRelevantDataElementIds);
return this.nonRelevantDataElementIds;
}
/**
* @return {?}
*/
RevertConditionValues() {
for (const /** @type {?} */ dataelement of this.template.dataElements) {
dataelement.isRequired = dataelement.isRequiredOverrider;
dataelement.displaySequence = dataelement.displaySequenceOverrider;
if (dataelement.dataElementType === 'NumericDataElement') {
(/** @type {?} */ (dataelement)).minimum = +(/** @type {?} */ (dataelement)).minimumOverrider;
(/** @type {?} */ (dataelement)).maximum = +(/** @type {?} */ (dataelement)).maximumOverrider;
}
if (dataelement.dataElementType === 'IntegerDataElement') {
(/** @type {?} */ (dataelement)).minimum = +(/** @type {?} */ (dataelement)).minimumOverrider;
(/** @type {?} */ (dataelement)).maximum = +(/** @type {?} */ (dataelement)).maximumOverrider;
}
if (dataelement.dataElementType === 'DurationDataElement') {
(/** @type {?} */ (dataelement)).MinimumDay = +(/** @type {?} */ (dataelement)).MinimumDayOverrider;
(/** @type {?} */ (dataelement)).MaximumDay = +(/** @type {?} */ (dataelement)).MaximumDayOverrider;
(/** @type {?} */ (dataelement)).MinimumHours = +(/** @type {?} */ (dataelement)).MinimumHoursOverrider;
(/** @type {?} */ (dataelement)).MaximumHours = +(/** @type {?} */ (dataelement)).MaximumHoursOverrider;
(/** @type {?} */ (dataelement)).MinimumMinutes = +(/** @type {?} */ (dataelement)).MinimumMinutesOverrider;
(/** @type {?} */ (dataelement)).MaxmimumMinutes = +(/** @type {?} */ (dataelement)).MaxmimumMinutesOverrider;
}
}
}
/**
* @return {?}
*/
evaluateDecisionPoints() {
this.evaluateComputedExpressions();
this.endOfRoadReached = false;
for (const /** @type {?} */ decisionPoint of this.template.rules.decisionPoints) {
this.evaluateDecisionPoint(decisionPoint, 1);
}
}
/**
* @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 /** @type {?} */ 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);
if (value !== undefined) {
return value.toUpperCase() === this.conditionType.comparisonValue.toUpperCase();
}
return false;
}
}
/**
* @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) {
for (let /** @type {?} */ counter = 0; counter < value.length; counter++) {
const /** @type {?} */ value1 = value[counter];
if (value1.toUpperCase() === this.conditionType.comparisonValue.toUpperCase()) {
returnValue = true;
}
}
}
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));
}
// if (condition !== undefined) {
// condition.IsRelevant = branchJSON.IsRelevant !== undefined
// ? branchJSON.IsRelevant : false;
// }
// condition.IsRelevant = branchJSON.IsRelevant !== undefined
// ? branchJSON.IsRelevant : true;
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 (data.hasOwnProperty('IsRelevant')){
// compositeConditionJSON += data.IsRelevant;
// }
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)) ;
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 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 */
Decis