@wbg-mde/repository
Version:
Managing all common method for file system CRUD operations.
664 lines (663 loc) • 43.1 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const model_1 = require("@wbg-mde/model");
const export_master_config_1 = require("../shared/configs/export.master.config");
const app_repo_utility_1 = require("../shared/app.repo.utility");
const export_master_1 = require("./export.master");
const js2xmlparser = require("@wbg-mde/js2xmlparser");
const template_service_1 = require("../shared/services/template.service");
const _ = require('lodash');
class ExportDDI extends export_master_1.ExportMaster {
constructor() {
super();
this.templateService = new template_service_1.TemplateService();
}
exportStudy(filePath, project, callback, asJson, options) {
try {
if (asJson) {
this.exportToJSON(project, filePath);
callback({ result: 'ok' });
}
else {
let header = project.header;
let metadata = _.cloneDeep(project.metadata);
this.templateService.getTreeViewSchema(header.type, header.language, (response) => {
metadata = this.removeExcludedDatasetsFromMetadata(metadata, options);
metadata = this.removeExcludedVariablesFromMetadata(metadata, options);
let xmlJson = this.formatMetadata(response.nodes, response.schema, response.form, metadata, options);
if (asJson === true) {
app_repo_utility_1.App_Repository_Utility.writeFile(filePath, JSON.stringify(xmlJson));
}
else {
let xml = js2xmlparser.parse(export_master_config_1.Export_Master_Config.xmlNodeProps.rootNode, xmlJson, {
cdataInvalidChars: true,
format: {
doubleQuotes: true
},
declaration: {
encoding: 'UTF-8'
}
});
app_repo_utility_1.App_Repository_Utility.writeFile(filePath, xml);
}
callback({ result: 'ok' });
});
}
}
catch (e) {
callback({ result: 'error', message: e });
app_repo_utility_1.App_Repository_Utility.LogText('Export > DDI > exportStudy > ' + e, 3);
}
}
removeExcludedDatasetsFromMetadata(metadata, options) {
if (!options) {
return metadata;
}
let datasets = _.map(options.datasets, (dset) => {
if (dset.selected === false) {
return dset.id;
}
});
_.omit(datasets, _.isUndefined);
if (metadata.datasets && metadata.datasets.fileDscr) {
let fileDscrs = metadata.datasets.fileDscr;
_.remove(fileDscrs, (fileDscr) => {
return datasets.indexOf(fileDscr.ID) !== -1;
});
}
return metadata;
}
removeExcludedVariablesFromMetadata(metadata, options) {
if (!options) {
return metadata;
}
_.forEach(options.datasets, (dset) => {
if (dset.selected === false) {
if (metadata.variables && metadata.variables[dset.id]) {
delete metadata.variables[dset.id];
}
}
});
return metadata;
}
formatMetadata(treeNodes, schema, form, metadata, options) {
let formattedJson = {};
try {
let headerData = this.getHeaderAttributes();
let idVal = _.get(metadata, 'stdyDscr.title_statement.idno');
headerData.ID = idVal ? idVal : '';
formattedJson[export_master_config_1.Export_Master_Config.xmlNodeProps.headerAttribute] = headerData;
let self = this;
_.forEach(treeNodes, function (treeNode) {
if (treeNode.key == export_master_config_1.Export_Master_Config.ddiNodes.dataSets) {
if (metadata.datasets && metadata.datasets.fileDscr && metadata.datasets.fileDscr instanceof Array) {
let editorMapSchema = export_master_config_1.Export_Master_Config.fileDescSectionMap;
self.templateService.createTreeViewSchema(editorMapSchema, schema, form, (response) => {
formattedJson[export_master_config_1.Export_Master_Config.ddiNodes.fileDescription] = self.getFileDescriptionNode(metadata.datasets.fileDscr, response);
});
}
if (metadata.variables) {
if (metadata.variables instanceof Object) {
let variables = self.getVariablesFromMetadata(metadata);
let editorMapSchema = export_master_config_1.Export_Master_Config.variableDocSectionMap;
self.templateService.createTreeViewSchema(editorMapSchema, schema, form, (response) => {
formattedJson[export_master_config_1.Export_Master_Config.codeBookNodes.DataDescription] = {};
formattedJson[export_master_config_1.Export_Master_Config.codeBookNodes.DataDescription][export_master_config_1.Export_Master_Config.codeBookNodes.varGroups] = self.generateVariableGroupsInfo(metadata);
formattedJson[export_master_config_1.Export_Master_Config.codeBookNodes.DataDescription][export_master_config_1.Export_Master_Config.codeBookNodes.variable] = self.getVariableDescriptionNode(variables, response, metadata, options);
});
}
}
}
else {
formattedJson = self.getDDIObject(treeNode, metadata, formattedJson);
if (treeNode.key == export_master_config_1.Export_Master_Config.ddiNodes.docDscr) {
self.setProductInfo(formattedJson, "docDscr.citation.prodStmt");
}
else if (treeNode.key == export_master_config_1.Export_Master_Config.ddiNodes.stdyDscr) {
self.setProductInfo(formattedJson, "stdyDscr.citation.prodStmt");
}
}
});
}
catch (e) {
app_repo_utility_1.App_Repository_Utility.LogText('Export > DDI > formatMetadata > ' + e, 3);
}
return formattedJson;
}
getVariablesFromMetadata(metadata) {
let variables = metadata.variables;
let result = [];
let fileDscr = metadata.datasets.fileDscr;
for (let fd of fileDscr) {
result = [...result, ...variables[fd.ID]];
}
return result;
}
getHeaderAttributes() {
let headeAttribute = {
version: export_master_config_1.Export_Master_Config.ddiHeaderAttr.version,
ID: '',
"xml-lang": export_master_config_1.Export_Master_Config.ddiHeaderAttr.xml_lang,
"xmlns": export_master_config_1.Export_Master_Config.ddiHeaderAttr.xmlns,
"xmlns:xsi": export_master_config_1.Export_Master_Config.ddiHeaderAttr.xmlns_xsi,
"xsi:schemaLocation": export_master_config_1.Export_Master_Config.ddiHeaderAttr.xsi_schemaLoc
};
return headeAttribute;
}
getDDIObject(form, data, outData) {
let subNodes = new Array();
try {
if (form.nodes && form.nodes instanceof Array) {
let self = this;
_.forEach(form.nodes, function (__node) {
if (__node.nodes && __node.nodes instanceof Array) {
self.getDDIObject(__node, data, outData);
}
else {
let keys = __node.key.split('.');
let nodeVal = _.get(data, keys);
if (nodeVal) {
if (__node.formschema.exportMapFn) {
self.helpers[__node.formschema.exportMapFn](export_master_config_1.Export_Master_Config.actions.export, nodeVal, __node.formschema.items, __node["exportKey"] || __node["key"], outData, __node.key);
}
else if (__node.formschema.type === export_master_config_1.Export_Master_Config.formSchemaTypes.table) {
let tableValue = self.formatTableVal(nodeVal, __node.formschema.items);
if (tableValue && !_.isEmpty(tableValue)) {
if (__node.formschema["splArray"] && __node["exportKey"]) {
var tempData = _.cloneDeep(outData) || {};
var tempJson = {};
app_repo_utility_1.App_Repository_Utility.setNestedProperty(outData, __node["exportKey"], tableValue);
outData = _.merge(outData, tempData);
}
else if (__node["exportKey"]) {
app_repo_utility_1.App_Repository_Utility.setNestedProperty(outData, __node["exportKey"], tableValue);
}
else {
app_repo_utility_1.App_Repository_Utility.setNestedProperty(outData, __node["key"], tableValue);
}
}
}
else {
if (nodeVal) {
if (__node["exportKey"]) {
let exportKeys = __node["exportKey"].split(",");
_.forEach(exportKeys, function (__key) {
app_repo_utility_1.App_Repository_Utility.setNestedProperty(outData, __key, nodeVal);
});
}
else {
app_repo_utility_1.App_Repository_Utility.setNestedProperty(outData, __node["key"], nodeVal);
}
}
}
}
}
});
}
}
catch (e) {
app_repo_utility_1.App_Repository_Utility.LogText('Export > DDI > getDDIObject > ' + e, 3);
}
return outData;
}
getfundAg(fundAgencies) {
let lstAgencies = new Array();
for (let agency of fundAgencies) {
let obj = {};
obj[export_master_config_1.Export_Master_Config.xmlNodeProps.headerAttribute] = {};
if (agency.name) {
obj[export_master_config_1.Export_Master_Config.xmlNodeProps.elementProp] = agency.name;
}
if (agency.abbr) {
obj[export_master_config_1.Export_Master_Config.xmlNodeProps.headerAttribute]["abbr"] = agency.abbr;
}
if (agency.role) {
obj[export_master_config_1.Export_Master_Config.xmlNodeProps.headerAttribute]["role"] = agency.role;
}
lstAgencies.push(obj);
}
return lstAgencies;
}
getGrandNumber(fundAgencies) {
let lstAgencies = new Array();
for (let agency of fundAgencies) {
if (agency.grantNumber) {
let obj = {};
obj[export_master_config_1.Export_Master_Config.xmlNodeProps.headerAttribute] = {};
obj[export_master_config_1.Export_Master_Config.xmlNodeProps.elementProp] = agency.grantNumber;
if (agency.abbr) {
obj[export_master_config_1.Export_Master_Config.xmlNodeProps.headerAttribute]["agency"] = agency.abbr;
}
if (agency.role) {
obj[export_master_config_1.Export_Master_Config.xmlNodeProps.headerAttribute]["role"] = agency.role;
}
lstAgencies.push(obj);
}
}
return lstAgencies;
}
getFileDescriptionNode(files, Schema) {
let fileDescription = new Array();
try {
for (let file of files) {
let fileInfo = {};
fileInfo[export_master_config_1.Export_Master_Config.xmlNodeProps.headerAttribute] = {};
_.forEach(export_master_config_1.Export_Master_Config.headerAttributeProps.fileDescr, (key) => {
if (file[key]) {
fileInfo[export_master_config_1.Export_Master_Config.xmlNodeProps.headerAttribute][key] = file[key];
}
});
fileInfo[export_master_config_1.Export_Master_Config.fileDescriptionProps.fileText] = {};
_.forEach(export_master_config_1.Export_Master_Config.staticProps.fileText, (key) => {
if (file[export_master_config_1.Export_Master_Config.fileDescriptionProps.fileText][key]) {
if (key === export_master_config_1.Export_Master_Config.fileDescriptionProps.fileStrc) {
let keyVars = file[export_master_config_1.Export_Master_Config.fileDescriptionProps.fileText][key][export_master_config_1.Export_Master_Config.fileDescriptionProps.recGrp][export_master_config_1.Export_Master_Config.fileDescriptionProps.keyvar];
let recGrps = file[export_master_config_1.Export_Master_Config.fileDescriptionProps.fileText][key][export_master_config_1.Export_Master_Config.fileDescriptionProps.recGrp][export_master_config_1.Export_Master_Config.fileDescriptionProps.recGrp];
if (keyVars || recGrps) {
fileInfo[export_master_config_1.Export_Master_Config.fileDescriptionProps.fileText][key] = {};
fileInfo[export_master_config_1.Export_Master_Config.fileDescriptionProps.fileText][key][export_master_config_1.Export_Master_Config.xmlNodeProps.headerAttribute] = {};
fileInfo[export_master_config_1.Export_Master_Config.fileDescriptionProps.fileText][key][export_master_config_1.Export_Master_Config.xmlNodeProps.headerAttribute][export_master_config_1.Export_Master_Config.fileDescriptionProps.fileStrcType]
= file[export_master_config_1.Export_Master_Config.fileDescriptionProps.fileText][key].type;
fileInfo[export_master_config_1.Export_Master_Config.fileDescriptionProps.fileText][key][export_master_config_1.Export_Master_Config.fileDescriptionProps.recGrp] = {};
fileInfo[export_master_config_1.Export_Master_Config.fileDescriptionProps.fileText][key][export_master_config_1.Export_Master_Config.fileDescriptionProps.recGrp][export_master_config_1.Export_Master_Config.xmlNodeProps.headerAttribute] = {};
fileInfo[export_master_config_1.Export_Master_Config.fileDescriptionProps.fileText][key][export_master_config_1.Export_Master_Config.fileDescriptionProps.recGrp][export_master_config_1.Export_Master_Config.xmlNodeProps.headerAttribute][export_master_config_1.Export_Master_Config.fileDescriptionProps.keyvar] = keyVars;
fileInfo[export_master_config_1.Export_Master_Config.fileDescriptionProps.fileText][key][export_master_config_1.Export_Master_Config.fileDescriptionProps.recGrp][export_master_config_1.Export_Master_Config.xmlNodeProps.headerAttribute][export_master_config_1.Export_Master_Config.fileDescriptionProps.recGrp] = recGrps;
}
}
else {
fileInfo[export_master_config_1.Export_Master_Config.fileDescriptionProps.fileText][key] = file[export_master_config_1.Export_Master_Config.fileDescriptionProps.fileText][key];
}
}
});
this.getFileTemplateData(Schema, file, fileInfo);
fileDescription.push(fileInfo);
}
}
catch (e) {
app_repo_utility_1.App_Repository_Utility.LogText('Export > DDI > getFileDescriptionNode > ' + e, 3);
}
return fileDescription;
}
getFileTemplateData(form, data, outData) {
form = form[0];
if (form.nodes && form.nodes instanceof Array) {
let self = this;
_.forEach(form.nodes, function (__node) {
let keys = __node.key.split('.');
if (keys.length == 2) {
let nodeVal = data[keys[1]];
if (nodeVal) {
let exportKey = __node.exportKey || keys[1];
app_repo_utility_1.App_Repository_Utility.setNestedProperty(outData, exportKey, nodeVal);
}
}
});
}
}
generateVariableGroupsInfo(metadata) {
let allGroupsData = [];
let variableInfo = {};
let groups = metadata.variableGroups || [];
for (let group of groups) {
variableInfo = {};
variableInfo[export_master_config_1.Export_Master_Config.xmlNodeProps.headerAttribute] = {};
variableInfo[export_master_config_1.Export_Master_Config.xmlNodeProps.headerAttribute]['ID'] = group.ID;
if (group.type) {
variableInfo[export_master_config_1.Export_Master_Config.xmlNodeProps.headerAttribute]['type'] = group.type;
}
if (group.variables && group.variables.length > 0) {
variableInfo[export_master_config_1.Export_Master_Config.xmlNodeProps.headerAttribute]['var'] = group.variables.join(' ');
}
let keys = _.keys(group);
for (let key of keys) {
if (['ID', 'type', 'variables'].indexOf(key) === -1 && group[key]) {
variableInfo[key] = group[key];
}
}
allGroupsData.push(variableInfo);
}
return allGroupsData;
}
getVariableDescriptionNode(vars, treeNodes, metadata, options) {
try {
if (treeNodes.length == 1) {
let variableNode = treeNodes[0];
let parentNodeKey = "variables.";
let varDescription = new Array();
let excludedStatistics = [];
if (options && options.datasets) {
for (let dset of options.datasets) {
if (dset.includeStatistics === false) {
excludedStatistics.push(dset.id);
}
}
}
for (let variable of vars) {
let summaryStats = new Array();
let varStat = this.getVariableStat(metadata, variable);
let variableInfo = {};
if (excludedStatistics.indexOf(variable.files) !== -1) {
varStat = _.cloneDeep(varStat);
varStat.inclmin = false;
varStat.inclmax = false;
varStat.inclmean = false;
varStat.inclstdev = false;
varStat.inclvalid = false;
}
variableInfo[export_master_config_1.Export_Master_Config.xmlNodeProps.headerAttribute] = {};
_.forEach(variable, (item, key) => {
if (export_master_config_1.Export_Master_Config.headerAttributeProps.varDescr.indexOf(key) >= 0) {
if (item) {
variableInfo[export_master_config_1.Export_Master_Config.xmlNodeProps.headerAttribute][key] = item;
}
}
else if (key == export_master_config_1.Export_Master_Config.variableDescriptionProps.label) {
if (item) {
variableInfo[key] = item;
}
}
else if (key == export_master_config_1.Export_Master_Config.variableDescriptionProps.internalName) {
if (item) {
variableInfo[key] = item;
}
}
else if (key == export_master_config_1.Export_Master_Config.variableDescriptionProps.location) {
if (item) {
variableInfo[key] = {};
variableInfo[key][export_master_config_1.Export_Master_Config.xmlNodeProps.headerAttribute] = {};
_.forEach(item, (locVal, locKey) => {
if (locVal) {
variableInfo[key][export_master_config_1.Export_Master_Config.xmlNodeProps.headerAttribute][locKey] = locVal;
}
});
}
}
else if (key == export_master_config_1.Export_Master_Config.variableDescriptionProps.validRange) {
variableInfo[export_master_config_1.Export_Master_Config.variableDescriptionProps.validRange] = {};
variableInfo[export_master_config_1.Export_Master_Config.variableDescriptionProps.validRange][export_master_config_1.Export_Master_Config.variableDescriptionProps.validRange_range] = {};
variableInfo[export_master_config_1.Export_Master_Config.variableDescriptionProps.validRange][export_master_config_1.Export_Master_Config.variableDescriptionProps.validRange_range][export_master_config_1.Export_Master_Config.xmlNodeProps.headerAttribute] = {};
if (item.range) {
if (item.range.UNITS) {
variableInfo[export_master_config_1.Export_Master_Config.variableDescriptionProps.validRange][export_master_config_1.Export_Master_Config.variableDescriptionProps.validRange_range][export_master_config_1.Export_Master_Config.xmlNodeProps.headerAttribute]["UNITS"] = item.range.UNITS;
}
if (isNaN(parseFloat(item.range.min)) === false && varStat.inclmin !== false) {
variableInfo[export_master_config_1.Export_Master_Config.variableDescriptionProps.validRange][export_master_config_1.Export_Master_Config.variableDescriptionProps.validRange_range][export_master_config_1.Export_Master_Config.xmlNodeProps.headerAttribute]["min"] = item.range.min;
summaryStats.push({ type: "min", val: item.range.min });
}
if (item.range.max && varStat.inclmax !== false) {
variableInfo[export_master_config_1.Export_Master_Config.variableDescriptionProps.validRange][export_master_config_1.Export_Master_Config.variableDescriptionProps.validRange_range][export_master_config_1.Export_Master_Config.xmlNodeProps.headerAttribute]["max"] = item.range.max;
summaryStats.push({ type: "max", val: item.range.max });
}
if (item.range.mean && varStat.inclmean !== false) {
summaryStats.push({ type: "mean", val: item.range.mean });
}
if (item.range.stdev && varStat.inclstdev !== false) {
summaryStats.push({ type: "stdev", val: item.range.stdev });
}
}
}
else if (key == export_master_config_1.Export_Master_Config.variableDescriptionProps.invalidRange) {
variableInfo[export_master_config_1.Export_Master_Config.variableDescriptionProps.invalidRange] = {};
let invlItems = item.item;
let itemsArray = [];
let invlItem;
if (invlItems && invlItems.length > 0) {
for (let i = 0; i < invlItems.length; i++) {
invlItem = {};
invlItem[export_master_config_1.Export_Master_Config.xmlNodeProps.headerAttribute] = invlItems[i];
itemsArray.push(invlItem);
}
}
let invlRanges = item.range;
let rangeArray = [];
let invlRange;
if (invlRanges && invlRanges.length > 0) {
for (let i = 0; i < invlRanges.length; i++) {
invlRange = {};
invlRange[export_master_config_1.Export_Master_Config.xmlNodeProps.headerAttribute] = invlRanges[i];
rangeArray.push(invlRange);
}
}
variableInfo[export_master_config_1.Export_Master_Config.variableDescriptionProps.invalidRange][export_master_config_1.Export_Master_Config.variableDescriptionProps.validRange_range] = rangeArray;
variableInfo[export_master_config_1.Export_Master_Config.variableDescriptionProps.invalidRange][export_master_config_1.Export_Master_Config.variableDescriptionProps.invalidRange_item] = itemsArray;
}
else if (key == export_master_config_1.Export_Master_Config.variableDescriptionProps.summaryStatus) {
variableInfo[export_master_config_1.Export_Master_Config.variableDescriptionProps.summaryStatus] = new Array();
if (item && item instanceof Array) {
for (let sumstat of item) {
if (varStat.inclvalid === false && ['vald', 'invd'].indexOf(sumstat.type) !== -1) {
continue;
}
let summaryStatus = {};
summaryStatus[export_master_config_1.Export_Master_Config.xmlNodeProps.headerAttribute] = {};
_.forEach(sumstat, (sum_val, sum_key) => {
if (sum_val) {
if (sum_key == "text") {
summaryStatus[export_master_config_1.Export_Master_Config.xmlNodeProps.elementProp] = sum_val;
}
else {
summaryStatus[export_master_config_1.Export_Master_Config.xmlNodeProps.headerAttribute][sum_key] = sum_val;
}
}
});
variableInfo[export_master_config_1.Export_Master_Config.variableDescriptionProps.summaryStatus].push(summaryStatus);
}
}
for (let summary of summaryStats) {
if (summary.val !== undefined) {
let __summary = {};
__summary[export_master_config_1.Export_Master_Config.xmlNodeProps.headerAttribute] = {};
if (summary.type)
__summary[export_master_config_1.Export_Master_Config.xmlNodeProps.headerAttribute]["type"] = summary.type;
__summary[export_master_config_1.Export_Master_Config.xmlNodeProps.elementProp] = summary.val;
variableInfo[export_master_config_1.Export_Master_Config.variableDescriptionProps.summaryStatus].push(__summary);
}
}
}
else if (key == export_master_config_1.Export_Master_Config.variableDescriptionProps.category) {
variableInfo[key] = new Array();
if (item && item instanceof Array) {
if (varStat.inclfreeq === false) {
item = item.filter(x => x.labl);
}
for (let category of item) {
let catgryInfo = {};
_.forEach(category, (cat_val, cat_key) => {
if (export_master_config_1.Export_Master_Config.hiddenKeys.category.indexOf(cat_key) === -1) {
if (cat_key == "catStat") {
if (cat_val.type === 'freq' && varStat.inclfreeq === false)
return;
let __category = {};
__category[export_master_config_1.Export_Master_Config.xmlNodeProps.headerAttribute] = {};
if (cat_val.type)
__category[export_master_config_1.Export_Master_Config.xmlNodeProps.headerAttribute]["type"] = cat_val.type;
if (cat_val.text != undefined)
__category[export_master_config_1.Export_Master_Config.xmlNodeProps.elementProp] = cat_val.text;
catgryInfo[cat_key] = __category;
}
else if (cat_key === "catValu" && cat_val === "NA") {
catgryInfo[cat_key] = export_master_config_1.Export_Master_Config.xmlNodeProps.missing;
catgryInfo[export_master_config_1.Export_Master_Config.xmlNodeProps.headerAttribute] = {};
catgryInfo[export_master_config_1.Export_Master_Config.xmlNodeProps.headerAttribute]['missing'] = 'Y';
}
else {
if (cat_val != undefined)
catgryInfo[cat_key] = cat_val;
}
}
});
variableInfo[key].push(catgryInfo);
}
}
}
else if (key == export_master_config_1.Export_Master_Config.variableDescriptionProps.format) {
variableInfo[key] = {};
if (item) {
variableInfo[key][export_master_config_1.Export_Master_Config.xmlNodeProps.headerAttribute] = {};
_.forEach(item, (fmVal, fmKey) => {
if (fmVal) {
variableInfo[key][export_master_config_1.Export_Master_Config.xmlNodeProps.headerAttribute][fmKey] = fmVal;
}
});
}
}
else if (key.startsWith(parentNodeKey)) {
variableInfo[key.replace(parentNodeKey, "")] = undefined;
}
});
variableInfo = this.sortVariableProps(this.getVariableProps(variableNode, variable, variableInfo, parentNodeKey));
varDescription.push(variableInfo);
}
return varDescription;
}
else {
return;
}
}
catch (e) {
app_repo_utility_1.App_Repository_Utility.LogText('Export > DDI > getVariableDescriptionNode > ' + e, 3);
return;
}
}
getVariableStat(metadata, variable) {
let statistics;
let varStat = metadata.varStat || {};
if (varStat[variable.files]) {
let item = _.find(varStat[variable.files], (stat) => {
return stat.id === variable.ID;
});
if (item) {
statistics = new model_1.VariableStatistics(item);
}
else {
statistics = this.defaultVariableStat(variable.ID, variable.files);
}
}
else {
statistics = this.defaultVariableStat(variable.ID, variable.files);
}
return statistics;
}
defaultVariableStat(variableId, fileName) {
return new model_1.VariableStatistics({
id: variableId,
files: fileName,
inclfreeq: true,
listmiss: true,
freqsoart: String(""),
inclvalid: true,
inclmin: true,
inclmax: true,
inclmean: true,
inclstdev: true
});
}
getVariableProps(form, data, outData, parentKey) {
try {
let subNodes = new Array();
if (form.nodes && form.nodes instanceof Array) {
let self = this;
_.forEach(form.nodes, function (__node) {
if (__node.nodes && __node.nodes instanceof Array) {
self.getVariableProps(__node, data, outData, parentKey);
}
else {
let keys = __node.key.replace('[]', '').split('.');
let nodeVal = _.get(data, keys);
if (nodeVal) {
if (__node.formschema.type === export_master_config_1.Export_Master_Config.formSchemaTypes.table) {
if (nodeVal["-"]) {
nodeVal = nodeVal["-"];
}
let tableValue = self.formatTableVal(nodeVal, __node.formschema.items);
if (tableValue && !_.isEmpty(tableValue)) {
if (__node["exportKey"]) {
app_repo_utility_1.App_Repository_Utility.setNestedProperty(outData, __node["exportKey"].replace(parentKey, ''), tableValue);
}
else {
app_repo_utility_1.App_Repository_Utility.setNestedProperty(outData, __node["key"].replace(parentKey, ''), tableValue);
}
}
}
else {
if (nodeVal) {
if (__node["exportKey"]) {
let exportKeys = __node["exportKey"].split(",");
_.forEach(exportKeys, function (__key) {
app_repo_utility_1.App_Repository_Utility.setNestedProperty(outData, __key.replace(parentKey, ''), nodeVal);
});
}
else {
app_repo_utility_1.App_Repository_Utility.setNestedProperty(outData, __node["key"].replace(parentKey, ''), nodeVal);
}
}
}
}
}
});
}
return outData;
}
catch (e) {
app_repo_utility_1.App_Repository_Utility.LogText('Export > DDI > getVariableProps > ' + e, 3);
}
}
sortVariableProps(varInfo) {
let sortedVariable = {};
if (varInfo) {
if (varInfo[export_master_config_1.Export_Master_Config.xmlNodeProps.headerAttribute]) {
sortedVariable[export_master_config_1.Export_Master_Config.xmlNodeProps.headerAttribute] = varInfo[export_master_config_1.Export_Master_Config.xmlNodeProps.headerAttribute];
}
if (varInfo[export_master_config_1.Export_Master_Config.variableDescriptionProps.label]) {
sortedVariable[export_master_config_1.Export_Master_Config.variableDescriptionProps.label] = varInfo[export_master_config_1.Export_Master_Config.variableDescriptionProps.label];
}
if (varInfo[export_master_config_1.Export_Master_Config.variableDescriptionProps.location]) {
sortedVariable[export_master_config_1.Export_Master_Config.variableDescriptionProps.location] = varInfo[export_master_config_1.Export_Master_Config.variableDescriptionProps.location];
}
if (varInfo[export_master_config_1.Export_Master_Config.variableTemplateNodes.imputation]) {
sortedVariable[export_master_config_1.Export_Master_Config.variableTemplateNodes.imputation] = varInfo[export_master_config_1.Export_Master_Config.variableTemplateNodes.imputation];
}
if (varInfo[export_master_config_1.Export_Master_Config.variableTemplateNodes.security]) {
sortedVariable[export_master_config_1.Export_Master_Config.variableTemplateNodes.security] = varInfo[export_master_config_1.Export_Master_Config.variableTemplateNodes.security];
}
if (varInfo[export_master_config_1.Export_Master_Config.variableTemplateNodes.respUnit]) {
sortedVariable[export_master_config_1.Export_Master_Config.variableTemplateNodes.respUnit] = varInfo[export_master_config_1.Export_Master_Config.variableTemplateNodes.respUnit];
}
if (varInfo[export_master_config_1.Export_Master_Config.variableTemplateNodes.qstn]) {
sortedVariable[export_master_config_1.Export_Master_Config.variableTemplateNodes.qstn] = varInfo[export_master_config_1.Export_Master_Config.variableTemplateNodes.qstn];
}
if (varInfo[export_master_config_1.Export_Master_Config.variableDescriptionProps.validRange]) {
sortedVariable[export_master_config_1.Export_Master_Config.variableDescriptionProps.validRange] = varInfo[export_master_config_1.Export_Master_Config.variableDescriptionProps.validRange];
}
if (varInfo[export_master_config_1.Export_Master_Config.variableDescriptionProps.invalidRange]) {
sortedVariable[export_master_config_1.Export_Master_Config.variableDescriptionProps.invalidRange] = varInfo[export_master_config_1.Export_Master_Config.variableDescriptionProps.invalidRange];
}
if (varInfo[export_master_config_1.Export_Master_Config.variableTemplateNodes.universe]) {
sortedVariable[export_master_config_1.Export_Master_Config.variableTemplateNodes.universe] = varInfo[export_master_config_1.Export_Master_Config.variableTemplateNodes.universe];
}
if (varInfo[export_master_config_1.Export_Master_Config.variableDescriptionProps.summaryStatus]) {
sortedVariable[export_master_config_1.Export_Master_Config.variableDescriptionProps.summaryStatus] = varInfo[export_master_config_1.Export_Master_Config.variableDescriptionProps.summaryStatus];
}
if (varInfo[export_master_config_1.Export_Master_Config.variableDescriptionProps.category]) {
sortedVariable[export_master_config_1.Export_Master_Config.variableDescriptionProps.category] = varInfo[export_master_config_1.Export_Master_Config.variableDescriptionProps.category];
}
if (varInfo[export_master_config_1.Export_Master_Config.variableTemplateNodes.notes]) {
sortedVariable[export_master_config_1.Export_Master_Config.variableTemplateNodes.notes] = varInfo[export_master_config_1.Export_Master_Config.variableTemplateNodes.notes];
}
if (varInfo[export_master_config_1.Export_Master_Config.variableTemplateNodes.txt]) {
sortedVariable[export_master_config_1.Export_Master_Config.variableTemplateNodes.txt] = varInfo[export_master_config_1.Export_Master_Config.variableTemplateNodes.txt];
}
if (varInfo[export_master_config_1.Export_Master_Config.variableTemplateNodes.recording]) {
sortedVariable[export_master_config_1.Export_Master_Config.variableTemplateNodes.recording] = varInfo[export_master_config_1.Export_Master_Config.variableTemplateNodes.recording];
}
if (varInfo[export_master_config_1.Export_Master_Config.variableTemplateNodes.concept]) {
sortedVariable[export_master_config_1.Export_Master_Config.variableTemplateNodes.concept] = varInfo[export_master_config_1.Export_Master_Config.variableTemplateNodes.concept];
}
if (varInfo[export_master_config_1.Export_Master_Config.variableDescriptionProps.format]) {
sortedVariable[export_master_config_1.Export_Master_Config.variableDescriptionProps.format] = varInfo[export_master_config_1.Export_Master_Config.variableDescriptionProps.format];
}
}
return sortedVariable;
}
}
exports.ExportDDI = ExportDDI;