acr-assist-simulator-module
Version:
This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 1.7.4.
944 lines • 158 kB
JavaScript
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
import * as tslib_1 from "tslib";
import { Component, Input, Output, EventEmitter } from '@angular/core';
import { SimulatorEngineService } from '../../core/services/simulator-engine.service';
import { InputData } from '../../core/models/input-data.model';
import { SimulatorCommunicationService } from '../shared/services/simulator-communication.service';
var /** @type {?} */ $ = require('jquery');
var AssistDataElementComponent = /** @class */ (function () {
function AssistDataElementComponent(simulatorEngineService, simulatorCommunicationService) {
this.simulatorEngineService = simulatorEngineService;
this.simulatorCommunicationService = simulatorCommunicationService;
this.Endpoints = [];
this.returnReportText = new EventEmitter();
this.returnExecutionHistory = new EventEmitter();
this.returnDataElementChanged = new EventEmitter();
this.inputValues = [];
this.comparisonValues = [];
this.selectedChoiceValues = [];
this.executedResultIds = [];
this.executedResultHistories = [];
}
/**
* @return {?}
*/
AssistDataElementComponent.prototype.ngOnInit = /**
* @return {?}
*/
function () {
var _this = this;
this.simulatorEngineService.simulatorStateChanged.subscribe(function (message) {
_this.simulatorState = /** @type {?} */ (message);
_this.dataElementValues = _this.simulatorEngineService.getAllDataElementValues();
var /** @type {?} */ nonRelevantIDs = _this.simulatorEngineService.evaluateDecisionAndConditionalProperty();
try {
for (var _a = tslib_1.__values(_this.dataElements), _b = _a.next(); !_b.done; _b = _a.next()) {
var dataElement = _b.value;
if (nonRelevantIDs && nonRelevantIDs.length > 0) {
if (nonRelevantIDs.indexOf(dataElement.id) >= 0) {
dataElement.isVisible = false;
}
else {
dataElement.isVisible = true;
}
}
else {
dataElement.isVisible = true;
}
if (_this.dataElementValues[dataElement.id] !== undefined && dataElement.currentValue !== _this.dataElementValues[dataElement.id]) {
dataElement.currentValue = _this.dataElementValues[dataElement.id];
}
dataElement.currentValue = (dataElement.currentValue !== undefined) ? dataElement.currentValue : _this.dataElementValues[dataElement.id];
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
}
finally { if (e_1) throw e_1.error; }
}
_this.dataElements = _this.dataElements.filter(function (x) { return x.displaySequence != null; }).sort(function (DE_1, DE_2) { return DE_1.displaySequence - DE_2.displaySequence; });
if (_this.simulatorState.endPointId && _this.simulatorState.endPointId.length > 0) {
_this.generateReportText(_this.simulatorState.endPointId);
}
else {
_this.returnReportText.emit(undefined);
}
_this.simulatorCommunicationService.messageEmitter('');
var e_1, _c;
});
};
/**
* @param {?} changes
* @return {?}
*/
AssistDataElementComponent.prototype.ngOnChanges = /**
* @param {?} changes
* @return {?}
*/
function (changes) {
this.dataElements = this.dataElements.filter(function (x) { return x.displaySequence != null; }).sort(function (DE_1, DE_2) { return DE_1.displaySequence - DE_2.displaySequence; });
this.executedResultIds = [];
};
/**
* @param {?} $event
* @return {?}
*/
AssistDataElementComponent.prototype.choiceSelected = /**
* @param {?} $event
* @return {?}
*/
function ($event) {
if ($event !== undefined) {
if ($event.receivedElement !== undefined && $event.selectedCondition !== undefined) {
this.selectedChoiceValues[$event.receivedElement.elementId + 'SelectedValue'] = $event.receivedElement.selectedText;
this.simulatorEngineService.addOrUpdateDataElement($event.receivedElement.elementId, $event.receivedElement.selectedValue, $event.receivedElement.selectedText);
var /** @type {?} */ executedResults = [];
executedResults[$event.selectedCondition.selectedCondition] = $event.selectedCondition.selectedValue;
this.executedResultIds[$event.selectedCondition.selectedConditionId] = executedResults;
if (this.simulatorState.endPointId && this.simulatorState.endPointId.length > 0) {
this.generateExecutionHistory();
}
this.afterDataElementChanged();
}
}
else {
this.afterDataElementChanged();
}
};
/**
* @param {?} $event
* @return {?}
*/
AssistDataElementComponent.prototype.numericSelected = /**
* @param {?} $event
* @return {?}
*/
function ($event) {
if ($event !== undefined) {
if ($event.receivedElement !== undefined && $event.selectedCondition !== undefined) {
this.simulatorEngineService.addOrUpdateDataElement($event.receivedElement.elementId, $event.receivedElement.selectedValue, $event.receivedElement.selectedValue);
var /** @type {?} */ executedResults = [];
executedResults[$event.selectedCondition.selectedCondition] = $event.selectedCondition.selectedValue;
this.executedResultIds[$event.selectedCondition.selectedConditionId] = executedResults;
if (this.simulatorState.endPointId && this.simulatorState.endPointId.length > 0) {
this.generateExecutionHistory();
}
this.afterDataElementChanged();
}
}
else {
this.afterDataElementChanged();
}
};
/**
* @param {?} $event
* @return {?}
*/
AssistDataElementComponent.prototype.multiSelected = /**
* @param {?} $event
* @return {?}
*/
function ($event) {
if ($event !== undefined) {
if ($event.receivedElement !== undefined && $event.selectedCondition !== undefined) {
this.comparisonValues[$event.receivedElement.elementId + 'ComparisonValue'] = $event.receivedElement.selectedComparisonValues;
this.simulatorEngineService.addOrUpdateDataElement($event.receivedElement.elementId, $event.receivedElement.selectedComparisonValues, $event.receivedElement.selectedValues);
var /** @type {?} */ executedResults = [];
executedResults[$event.selectedCondition.selectedCondition] = $event.selectedCondition.selectedValue;
this.executedResultIds[$event.selectedCondition.selectedConditionId] = executedResults;
if (this.simulatorState.endPointId && this.simulatorState.endPointId.length > 0) {
this.generateExecutionHistory();
}
this.afterDataElementChanged();
}
}
else {
this.afterDataElementChanged();
}
};
/**
* @param {?} endpointId
* @return {?}
*/
AssistDataElementComponent.prototype.generateReportText = /**
* @param {?} endpointId
* @return {?}
*/
function (endpointId) {
var /** @type {?} */ endpointContent = this.returnEndPointContents(this.xmlContent, '<EndPoint Id="' + endpointId + '">', '</EndPoint>');
this.parseXml(endpointId, endpointContent);
};
/**
* @return {?}
*/
AssistDataElementComponent.prototype.afterDataElementChanged = /**
* @return {?}
*/
function () {
var /** @type {?} */ deValues = [];
var _loop_1 = function (de) {
if (de.isVisible && de.dataElementType !== 'ComputedDataElement' && de.dataElementType !== 'GlobalValue') {
var /** @type {?} */ inputData_1 = new InputData();
inputData_1.dataElementId = de.id;
inputData_1.dataElementLabel = de.label;
inputData_1.dataElementValue = de.currentValue;
if (de.currentValue === undefined || de.currentValue === '') {
inputData_1.dataElementDisplayValue = undefined;
}
else {
if (de.dataElementType === 'ChoiceDataElement') {
var /** @type {?} */ choices = (/** @type {?} */ (de)).choiceInfo;
inputData_1.dataElementDisplayValue = choices.filter(function (ch) { return ch.value === de.currentValue; })[0].label;
}
else if (de.dataElementType === 'MultiChoiceDataElement') {
var /** @type {?} */ choices = (/** @type {?} */ (de)).choiceInfo;
inputData_1.dataElementDisplayValue = [];
choices.forEach(function (choice) {
if (Array.isArray(de.currentValue)) {
de.currentValue.forEach(function (element) {
if (choice.value === element) {
inputData_1.dataElementDisplayValue.push(choice.label);
}
});
}
else {
if (choice.value === de.currentValue) {
inputData_1.dataElementDisplayValue.push(choice.label);
}
}
});
}
else {
inputData_1.dataElementDisplayValue = de.currentValue;
}
}
deValues.push(inputData_1);
}
};
try {
for (var _a = tslib_1.__values(this.dataElements), _b = _a.next(); !_b.done; _b = _a.next()) {
var de = _b.value;
_loop_1(de);
}
}
catch (e_2_1) { e_2 = { error: e_2_1 }; }
finally {
try {
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
}
finally { if (e_2) throw e_2.error; }
}
this.returnDataElementChanged.emit(deValues);
var e_2, _c;
};
/**
* @return {?}
*/
AssistDataElementComponent.prototype.generateExecutionHistory = /**
* @return {?}
*/
function () {
this.executedResultHistories = [];
var /** @type {?} */ isNonRelevant;
isNonRelevant = false;
// tslint:disable-next-line:forin
for (var /** @type {?} */ resultId in this.executedResultIds) {
try {
for (var _a = tslib_1.__values(this.simulatorState.nonRelevantDataElementIds), _b = _a.next(); !_b.done; _b = _a.next()) {
var nonRelevantDataElement = _b.value;
if (nonRelevantDataElement === resultId) {
isNonRelevant = true;
break;
}
else {
isNonRelevant = false;
}
}
}
catch (e_3_1) { e_3 = { error: e_3_1 }; }
finally {
try {
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
}
finally { if (e_3) throw e_3.error; }
}
if (!isNonRelevant) {
// tslint:disable-next-line:forin
for (var /** @type {?} */ label in this.executedResultIds[resultId]) {
var /** @type {?} */ executedResultHistory = new ExecutedResultHistory();
executedResultHistory.resultCondition = label;
executedResultHistory.resultValue = this.executedResultIds[resultId][label];
this.executedResultHistories.push(executedResultHistory);
}
}
}
var /** @type {?} */ finalExecution = new FinalExecutedHistory();
if (this.executedResultHistories.length > 0) {
finalExecution.executionHistories = this.executedResultHistories;
finalExecution.resultText = this.mainReportTextObj;
finalExecution.inputData = [];
try {
for (var _d = tslib_1.__values(this.dataElements), _e = _d.next(); !_e.done; _e = _d.next()) {
var de = _e.value;
if (de.isVisible && de.dataElementType !== 'ComputedDataElement' && de.dataElementType !== 'GlobalValue') {
var /** @type {?} */ inputData = new InputData();
inputData.dataElementId = de.id;
inputData.dataElementValue = de.currentValue;
finalExecution.inputData.push(inputData);
}
}
}
catch (e_4_1) { e_4 = { error: e_4_1 }; }
finally {
try {
if (_e && !_e.done && (_f = _d.return)) _f.call(_d);
}
finally { if (e_4) throw e_4.error; }
}
}
this.returnExecutionHistory.emit(finalExecution);
var e_3, _c, e_4, _f;
};
/**
* @param {?} content
* @param {?} startToken
* @param {?} endToken
* @return {?}
*/
AssistDataElementComponent.prototype.returnEndPointContents = /**
* @param {?} content
* @param {?} startToken
* @param {?} endToken
* @return {?}
*/
function (content, startToken, endToken) {
var /** @type {?} */ contents;
var /** @type {?} */ templateSearchIndexPosition = 0;
while (true) {
var /** @type {?} */ contentStartPosition = content.indexOf(startToken, templateSearchIndexPosition);
var /** @type {?} */ contentEndPosition = content.indexOf(endToken, templateSearchIndexPosition);
if (contentStartPosition >= 0 && contentEndPosition >= 0) {
var /** @type {?} */ endPosition = contentEndPosition + endToken.length;
var /** @type {?} */ contentData = content.substring(contentStartPosition, endPosition);
contents = contentData;
templateSearchIndexPosition = endPosition + 1;
}
else {
break;
}
}
return contents;
};
/**
* @param {?} xmlData
* @return {?}
*/
AssistDataElementComponent.prototype.parseToJson = /**
* @param {?} xmlData
* @return {?}
*/
function (xmlData) {
var /** @type {?} */ jsonResult;
var /** @type {?} */ parseString = require('xml2js').parseString;
parseString(xmlData, { explicitRoot: false, explicitArray: false, attrkey: 'Attr' }, function (err, result) {
jsonResult = result;
});
return jsonResult;
};
/**
* @param {?} endPointId
* @param {?} endpointContent
* @return {?}
*/
AssistDataElementComponent.prototype.parseXml = /**
* @param {?} endPointId
* @param {?} endpointContent
* @return {?}
*/
function (endPointId, endpointContent) {
var /** @type {?} */ templateIds = [];
var /** @type {?} */ canInsertText;
var /** @type {?} */ isSectionIf;
var /** @type {?} */ selectedElements;
var /** @type {?} */ executeSectionIfNot;
var /** @type {?} */ hasSectionNot;
var /** @type {?} */ insertValue;
var /** @type {?} */ executeTemplate;
var /** @type {?} */ isImpression;
var /** @type {?} */ isNewTemplate;
var /** @type {?} */ hasInsertPartial;
var /** @type {?} */ isMainText;
var /** @type {?} */ allReportText = [];
var /** @type {?} */ endpoints = this.Endpoints;
var /** @type {?} */ templatePartialsText;
var /** @type {?} */ selectedComparisonValues;
var /** @type {?} */ findingsText;
var /** @type {?} */ impressionText;
var /** @type {?} */ selectedSection;
var /** @type {?} */ selectedChoiceTexts;
var /** @type {?} */ textExpressionValue;
selectedElements = this.simulatorEngineService.getAllDataElementValues();
templatePartialsText = this.templatePartial;
selectedComparisonValues = this.comparisonValues;
selectedChoiceTexts = this.simulatorEngineService.getAllDataElementTexts();
executeSectionIfNot = false;
hasInsertPartial = false;
endpointContent = endpointContent.replace(/\n/g, ' ');
endpointContent = endpointContent.replace(/\t/g, ' ');
// endpointContent = endpointContent.replace(/\s/g, ' ');
// tslint:disable-next-line:forin
for (var /** @type {?} */ i in templatePartialsText) {
templatePartialsText[i] = templatePartialsText[i].replace(/\n/g, ' ');
templatePartialsText[i] = templatePartialsText[i].replace(/\t/g, ' ');
// templatePartialsText[i] = templatePartialsText[i].replace(/\s+/g, ' ');
}
findingsText = '';
impressionText = '';
var /** @type {?} */ isReportText;
var /** @type {?} */ reportTextContent = '';
var /** @type {?} */ endpointSax = require('sax'), /** @type {?} */
strict = true, /** @type {?} */
normalize = true, /** @type {?} */
// set to false for html-mode
trim = true, /** @type {?} */
reportTextParser = endpointSax.parser(strict, trim);
reportTextParser.onerror = function (e) {
// an error happened.
reportTextParser.resume();
};
reportTextParser.ontext = function (t) {
debugger;
// if (t.length > 1) {
// t = t.trim();
// }
var /** @type {?} */ isTextInserted;
isTextInserted = false;
if (executeTemplate) {
if (!isImpression) {
if (canInsertText && hasSectionNot && hasSectionNot !== undefined && executeSectionIfNot) {
findingsText = findingsText + t;
}
else if (canInsertText && isNewTemplate && hasInsertPartial && !isSectionIf) {
findingsText = findingsText + t;
}
else if (canInsertText && !isImpression) {
findingsText = findingsText + t;
}
}
else {
if (canInsertText && hasSectionNot && hasSectionNot !== undefined && executeSectionIfNot) {
impressionText = impressionText + t;
}
else if (canInsertText && !hasSectionNot && isImpression) {
impressionText = impressionText + t;
}
else if (canInsertText && isNewTemplate) {
impressionText = impressionText + t;
}
}
if (isReportText && !isTextInserted && isMainText && canInsertText) {
reportTextContent = reportTextContent + t;
}
}
};
reportTextParser.onopentag = function (node) {
switch (node.name) {
case 'Label':
canInsertText = false;
isReportText = false;
isMainText = false;
break;
case 'ReportText':
if (executeTemplate) {
isReportText = true;
canInsertText = true;
selectedSection = node.attributes.SectionId;
impressionText = '';
if (node.attributes.SectionId === 'findings' && executeTemplate) {
isImpression = false;
}
else if (node.attributes.SectionId === 'impression' && executeTemplate) {
isImpression = true;
}
}
isSectionIf = false;
// isMainText = true;
break;
case 'InsertPartial':
if (executeTemplate) {
generatePartialView(node.attributes.PartialId, isImpression);
executeTemplate = true;
canInsertText = true;
if (isReportText) {
hasInsertPartial = true;
}
else {
hasInsertPartial = false;
}
}
else {
canInsertText = false;
}
isReportText = false;
isMainText = false;
break;
case 'SectionIfValueNot':
if (executeTemplate) {
if (Array.isArray(selectedElements[node.attributes.DataElementId])) {
try {
for (var _a = tslib_1.__values(selectedElements[node.attributes.DataElementId]), _b = _a.next(); !_b.done; _b = _a.next()) {
var comaprisonValue = _b.value;
if (comaprisonValue !== node.attributes.ComparisonValue &&
comaprisonValue !== undefined && !isSectionIf) {
canInsertText = true;
executeSectionIfNot = true;
break;
}
else {
canInsertText = false;
executeSectionIfNot = false;
}
}
}
catch (e_5_1) { e_5 = { error: e_5_1 }; }
finally {
try {
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
}
finally { if (e_5) throw e_5.error; }
}
}
else if (selectedElements[node.attributes.DataElementId] !== node.attributes.ComparisonValue &&
selectedElements[node.attributes.DataElementId] !== '--Select--' &&
selectedElements[node.attributes.DataElementId] !== undefined &&
selectedElements[node.attributes.DataElementId] !== null) {
canInsertText = true;
executeSectionIfNot = true;
}
else {
canInsertText = false;
executeSectionIfNot = false;
}
}
hasSectionNot = true;
isMainText = false;
break;
case 'SectionIf':
if (selectedElements[node.attributes.DataElementId] !== undefined && selectedElements[node.attributes.DataElementId].length > 0 && selectedChoiceTexts[node.attributes.DataElementId] !== 'Other, please specify…') {
isSectionIf = true;
canInsertText = true;
}
else {
isSectionIf = false;
canInsertText = false;
}
break;
case 'SectionIfValue':
if (executeTemplate) {
if (executeTemplate) {
if (Array.isArray(selectedElements[node.attributes.DataElementId])) {
try {
for (var _d = tslib_1.__values(selectedElements[node.attributes.DataElementId]), _e = _d.next(); !_e.done; _e = _d.next()) {
var comaprisonValue = _e.value;
if (comaprisonValue === node.attributes.ComparisonValue &&
comaprisonValue !== undefined) {
isSectionIf = true;
if (selectedElements[node.attributes.DataElementId] !== undefined && !isSectionIf && selectedChoiceTexts[node.attributes.DataElementId] !== 'Other, please specify…') {
findingsText = findingsText + selectedChoiceTexts[node.attributes.DataElementId];
}
canInsertText = true;
break;
}
else {
isSectionIf = false;
canInsertText = false;
}
}
}
catch (e_6_1) { e_6 = { error: e_6_1 }; }
finally {
try {
if (_e && !_e.done && (_f = _d.return)) _f.call(_d);
}
finally { if (e_6) throw e_6.error; }
}
}
else if (selectedElements[node.attributes.DataElementId] === node.attributes.ComparisonValue &&
selectedElements[node.attributes.DataElementId] !== undefined) {
isSectionIf = true;
if (selectedElements[node.attributes.DataElementId] !== undefined && !isSectionIf && selectedChoiceTexts[node.attributes.DataElementId] !== 'Other, please specify…') {
findingsText = findingsText + selectedChoiceTexts[node.attributes.DataElementId];
}
canInsertText = true;
}
else {
canInsertText = false;
}
}
break;
}
isMainText = false;
break;
case 'InsertValue':
if (executeTemplate) {
isReportText = false;
insertValue = true;
var /** @type {?} */ choiceText = selectedChoiceTexts[node.attributes.DataElementId];
if (node.attributes.Id === 'findings' || canInsertText) {
if (selectedElements[node.attributes.DataElementId] !== undefined && hasSectionNot && executeSectionIfNot) {
if (isImpression) {
if (selectedChoiceTexts[node.attributes.DataElementId] !== undefined && selectedChoiceTexts[node.attributes.DataElementId] !== 'Other, please specify…') {
impressionText = impressionText + (Array.isArray(choiceText) ? choiceText.join(', ') : choiceText);
}
else {
getTextExpressionValue(selectedElements[node.attributes.DataElementId]);
impressionText = impressionText + (Array.isArray(selectedElements[node.attributes.DataElementId]) ? selectedElements[node.attributes.DataElementId].join(', ') : textExpressionValue);
}
}
else {
if (selectedChoiceTexts[node.attributes.DataElementId] !== undefined && selectedChoiceTexts[node.attributes.DataElementId] !== 'Other, please specify…') {
findingsText = findingsText + (Array.isArray(choiceText) ? choiceText.join(', ') : choiceText);
}
else {
getTextExpressionValue(selectedElements[node.attributes.DataElementId]);
findingsText = findingsText + (Array.isArray(selectedElements[node.attributes.DataElementId]) ? selectedElements[node.attributes.DataElementId].join(', ') : textExpressionValue);
}
}
}
else if (selectedElements[node.attributes.DataElementId] !== undefined && !hasSectionNot) {
if (isImpression) {
if (selectedChoiceTexts[node.attributes.DataElementId] !== undefined && selectedChoiceTexts[node.attributes.DataElementId] !== 'Other, please specify…') {
impressionText = impressionText + (Array.isArray(choiceText) ? choiceText.join(', ') : choiceText);
}
else {
getTextExpressionValue(selectedElements[node.attributes.DataElementId]);
impressionText = impressionText + (Array.isArray(selectedElements[node.attributes.DataElementId]) ? selectedElements[node.attributes.DataElementId].join(', ') : textExpressionValue);
}
}
else {
if (selectedChoiceTexts[node.attributes.DataElementId] !== undefined && selectedChoiceTexts[node.attributes.DataElementId] !== 'Other, please specify…') {
findingsText = findingsText + (Array.isArray(choiceText) ? choiceText.join(', ') : choiceText);
}
else {
getTextExpressionValue(selectedElements[node.attributes.DataElementId]);
findingsText = findingsText + (Array.isArray(selectedElements[node.attributes.DataElementId]) ? selectedElements[node.attributes.DataElementId].join(', ') : textExpressionValue);
}
}
}
if (isImpression) {
canInsertText = true;
}
}
isMainText = false;
break;
}
}
executeTemplate = true;
isNewTemplate = true;
var e_5, _c, e_6, _f;
};
reportTextParser.onclosetag = function (node) {
switch (node) {
case 'SectionIfValueNot':
executeSectionIfNot = false;
hasSectionNot = false;
if (isSectionIf) {
canInsertText = true;
}
break;
case 'TemplatePartial':
isNewTemplate = false;
canInsertText = false;
executeTemplate = false;
break;
case 'ReportText':
// isImpression = false;
if (!hasInsertPartial && !isImpression) {
var /** @type {?} */ reportTextObj = new AllReportText();
reportTextObj.sectionId = 'findings';
reportTextObj.reportText = findingsText;
allReportText[reportTextObj.sectionId] = reportTextObj;
}
if (impressionText !== '' && impressionText !== undefined) {
var /** @type {?} */ reportTextObj = new AllReportText();
reportTextObj.sectionId = selectedSection;
reportTextObj.reportText = impressionText;
allReportText[reportTextObj.sectionId] = reportTextObj;
}
hasInsertPartial = false;
break;
case 'SectionIf':
isSectionIf = false;
canInsertText = true;
break;
case 'InsertPartial':
canInsertText = true;
break;
case 'InsertValue':
if ((hasSectionNot && executeSectionIfNot || !hasSectionNot)) {
canInsertText = true;
}
break;
case 'SectionIfValue':
canInsertText = true;
break;
}
};
reportTextParser.onend = function () {
// parser stream is done, and ready to have more stuff written to it.
// if (impressionText !== '' && impressionText !== undefined) {
// const reportTextObj: AllReportText = new AllReportText();
// reportTextObj.sectionId = selectedSection;
// reportTextObj.reportText = impressionText;
// allReportText[reportTextObj.sectionId] = reportTextObj;
// }
};
reportTextParser.write(endpointContent).onend();
/**
* @param {?} textExpression
* @return {?}
*/
function getTextExpressionValue(textExpression) {
if (textExpression.indexOf('{') === 0 && (textExpression.indexOf('}') > 1)) {
var /** @type {?} */ subString = textExpression.substr(textExpression.indexOf('{') + 1, textExpression.indexOf('}') - 1);
getTextExpressionValue(selectedElements[subString]);
}
else {
textExpressionValue = textExpression;
}
}
/**
* @param {?} partialViewId
* @param {?} isImpressionTemplate
* @return {?}
*/
function generatePartialView(partialViewId, isImpressionTemplate) {
// this.templateIds = [];
var /** @type {?} */ sax = require('sax'), /** @type {?} */
parser = sax.parser(strict, trim);
parser.onerror = function (e) {
// an error happened.
// parser.resume();
};
parser.ontext = function (t) {
if (executeTemplate) {
if (!isImpressionTemplate) {
if (canInsertText && hasSectionNot && hasSectionNot !== undefined && executeSectionIfNot) {
findingsText = findingsText + t;
}
else if (canInsertText && !hasSectionNot && isImpression) {
findingsText = findingsText + t;
}
else if (canInsertText && isNewTemplate) {
findingsText = findingsText + t;
}
}
else {
if (canInsertText && hasSectionNot && hasSectionNot !== undefined && executeSectionIfNot) {
impressionText = impressionText + t;
}
else if (canInsertText && !hasSectionNot && isImpression) {
impressionText = impressionText + t;
}
else if (canInsertText && isNewTemplate) {
impressionText = impressionText + t;
}
}
}
};
parser.onopentag = function (node) {
switch (node.name) {
case 'Label':
canInsertText = false;
break;
case 'EndPoint':
if (node.attributes.Id !== '') {
canInsertText = true;
isImpression = true;
}
else {
canInsertText = false;
isImpression = false;
}
break;
case 'InsertPartial':
canInsertText = false;
break;
case 'ReportText':
canInsertText = true;
break;
case 'TemplatePartial':
hasSectionNot = false;
executeSectionIfNot = false;
if (node.attributes.Id === partialViewId) {
executeTemplate = true;
canInsertText = true;
isNewTemplate = true;
break;
}
else {
isNewTemplate = false;
executeTemplate = false;
}
break;
case 'SectionIfValueNot':
if (executeTemplate) {
if (Array.isArray(selectedElements[node.attributes.DataElementId])) {
try {
for (var _a = tslib_1.__values(selectedComparisonValues[node.attributes.DataElementId + 'ComparisonValue']), _b = _a.next(); !_b.done; _b = _a.next()) {
var comaprisonValue = _b.value;
if (comaprisonValue !== node.attributes.ComparisonValue &&
comaprisonValue !== undefined && !isSectionIf) {
canInsertText = true;
executeSectionIfNot = true;
break;
}
else {
canInsertText = false;
executeSectionIfNot = false;
}
}
}
catch (e_7_1) { e_7 = { error: e_7_1 }; }
finally {
try {
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
}
finally { if (e_7) throw e_7.error; }
}
}
else if (selectedElements[node.attributes.DataElementId] !== node.attributes.ComparisonValue &&
selectedElements[node.attributes.DataElementId] !== '--Select--' &&
selectedElements[node.attributes.DataElementId] !== undefined &&
selectedElements[node.attributes.DataElementId] !== null) {
canInsertText = true;
executeSectionIfNot = true;
}
else {
canInsertText = false;
executeSectionIfNot = false;
}
}
hasSectionNot = true;
break;
case 'SectionIf':
if (selectedElements[node.attributes.DataElementId] !== undefined && selectedElements[node.attributes.DataElementId].length > 0 && (!hasSectionNot || (hasSectionNot && executeSectionIfNot))
&& selectedChoiceTexts[node.attributes.DataElementId] !== 'Other, please specify…') {
isSectionIf = true;
canInsertText = true;
}
else {
isSectionIf = false;
canInsertText = false;
}
break;
case 'SectionIfValue':
if (executeTemplate) {
if (Array.isArray(selectedElements[node.attributes.DataElementId])) {
try {
for (var _d = tslib_1.__values(selectedComparisonValues[node.attributes.DataElementId + 'ComparisonValue']), _e = _d.next(); !_e.done; _e = _d.next()) {
var comaprisonValue = _e.value;
if (comaprisonValue === node.attributes.ComparisonValue &&
comaprisonValue !== undefined) {
isSectionIf = true;
if (selectedElements[node.attributes.DataElementId] !== undefined && !isSectionIf && selectedChoiceTexts[node.attributes.DataElementId] !== 'Other, please specify…') {
findingsText = findingsText + selectedChoiceTexts[node.attributes.DataElementId];
}
canInsertText = true;
break;
}
else {
isSectionIf = false;
canInsertText = false;
}
}
}
catch (e_8_1) { e_8 = { error: e_8_1 }; }
finally {
try {
if (_e && !_e.done && (_f = _d.return)) _f.call(_d);
}
finally { if (e_8) throw e_8.error; }
}
}
else if (selectedElements[node.attributes.DataElementId] === node.attributes.ComparisonValue &&
selectedElements[node.attributes.DataElementId] !== undefined) {
isSectionIf = true;
if (selectedElements[node.attributes.DataElementId] !== undefined && !isSectionIf && selectedChoiceTexts[node.attributes.DataElementId] !== 'Other, please specify…') {
findingsText = findingsText + selectedChoiceTexts[node.attributes.DataElementId];
}
canInsertText = true;
}
else {
canInsertText = false;
}
}
break;
case 'InsertValue':
if (executeTemplate) {
insertValue = true;
var /** @type {?} */ choiceText = selectedChoiceTexts[node.attributes.DataElementId];
if (node.attributes.Id === 'findings' || canInsertText) {
if (isImpression) {
canInsertText = true;
if (selectedElements[node.attributes.DataElementId] !== undefined && hasSectionNot && executeSectionIfNot && selectedChoiceTexts[node.attributes.DataElementId] !== 'Other, please specify…') {
if (selectedChoiceTexts[node.attributes.DataElementId] !== undefined) {
impressionText = impressionText + (Array.isArray(choiceText) ? choiceText.join(', ') : choiceText);
}
else {
impressionText = impressionText + (Array.isArray(choiceText) ? choiceText.join(', ') : choiceText);
}
}
else if (selectedElements[node.attributes.DataElementId] !== undefined && !hasSectionNot && selectedChoiceTexts[node.attributes.DataElementId] !== 'Other, please specify…') {
if (selectedChoiceTexts[node.attributes.DataElementId] !== undefined) {
impressionText = impressionText + (Array.isArray(choiceText) ? choiceText.join(', ') : choiceText);
}
else {
if (selectedChoiceTexts[node.attributes.DataElementId] !== undefined && selectedChoiceTexts[node.attributes.DataElementId] !== 'Other, please specify…') {
impressionText = impressionText + (Array.isArray(choiceText) ? choiceText.join(', ') : choiceText);
}
}
}
}
else {
if (selectedElements[node.attributes.DataElementId] !== undefined && hasSectionNot && executeSectionIfNot && selectedChoiceTexts[node.attributes.DataElementId] !== 'Other, please specify…') {
if (selectedChoiceTexts[node.attributes.DataElementId] !== undefined) {
findingsText = findingsText + (Array.isArray(choiceText) ? choiceText.join(', ') : choiceText);
}
}
else if (selectedElements[node.attributes.DataElementId] !== undefined && !hasSectionNot && selectedChoiceTexts[node.attributes.DataElementId] !== 'Other, please specify…') {
if (selectedChoiceTexts[node.attributes.DataElementId] !== undefined) {
findingsText = findingsText + (Array.isArray(choiceText) ? choiceText.join(', ') : choiceText);
}
}
}
}
break;
}
}
var e_7, _c, e_8, _f;
};
parser.onclosetag = function (node) {
switch (node) {
case 'SectionIfValueNot':
executeSectionIfNot = false;
hasSectionNot = false;
if (isSectionIf) {
canInsertText = true;
}
break;
case 'TemplatePartial':
isNewTemplate = true;
canInsertText = false;
executeTemplate = true;
break;
case 'InsertPartial':
canInsertText = true;
break;
case 'SectionIf' || 'SectionIfValue':
isSectionIf