You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
89 lines
2.1 KiB
JavaScript
89 lines
2.1 KiB
JavaScript
// Read Excel file and copy the relevant columns to the main table (with proper column types)
|
|
const codetoNameEquivalences = {
|
|
"AAA": "Hospital Son Espases",
|
|
"70007": "Area de Gestión Almería Norte",
|
|
"70008": "Consejería de Salud de La Rioja",
|
|
"70011": "Jefatura Territorial de Sanidad de Pontevedra",
|
|
}
|
|
// CONSTANTS
|
|
|
|
const ORIGIN_TABLE_NAME = "BASE DE DATOS";
|
|
const ORIGIN_VIEW_NAME = "Default View";
|
|
|
|
const TARGET_TABLE_NAME = "Brutos"
|
|
const TARGET_VIEW_NAME = "Default View";
|
|
|
|
// Helper functions
|
|
const clientCodeToName = (code) => {
|
|
const clientCode = code.toString();
|
|
let clientName = "";
|
|
|
|
|
|
}
|
|
const removeDoubleSpace = (str) => {
|
|
if (typeof str !== "string") {
|
|
return str;
|
|
}
|
|
return str.replace(/\s\s+/g, ' ');
|
|
}
|
|
|
|
// Remove leading and ending spaces in string
|
|
const removeLeadingAndTrailingSpaces = (str) => {
|
|
if (typeof str !== "string") {
|
|
return str;
|
|
}
|
|
return str.trim();
|
|
}
|
|
|
|
const matcodeToAbarax = (str) => {
|
|
if (str === 211354) {
|
|
return "50mg";
|
|
}
|
|
return "100mg";
|
|
}
|
|
|
|
// get tables and views
|
|
const originTable = base.getTableByName(ORIGIN_TABLE_NAME);
|
|
const originView = base.getViewByName(originTable, ORIGIN_VIEW_NAME);
|
|
|
|
const targetTable = base.getTableByName(TARGET_TABLE_NAME);
|
|
const targetView = base.getViewByName(targetTable, TARGET_VIEW_NAME);
|
|
|
|
// List of the columns I want to replicate
|
|
const selectedColumns = [
|
|
"Material",
|
|
"Solic.",
|
|
"Present.Concentr.",
|
|
"Nom.Solicitante",
|
|
"Nom Dest.",
|
|
"FechaFact.",
|
|
"Cantidad UMB",
|
|
]
|
|
|
|
const dataMatrix = []
|
|
|
|
// Get all rows and create new element with only the selected columns
|
|
const originRows = base.getRows(originTable, originView);
|
|
|
|
originRows.forEach(row => {
|
|
|
|
// Create new element with only the selected columns
|
|
const element = {};
|
|
selectedColumns.forEach(column => {
|
|
element[column] = removeLeadingAndTrailingSpaces(row[column]);
|
|
element[column] = removeDoubleSpace(element[column]);
|
|
});
|
|
|
|
// Material to Abarax
|
|
element["Material"] = matcodeToAbarax(element["Material"]);
|
|
|
|
// Add element to dataMatrix
|
|
dataMatrix.push(element);
|
|
})
|
|
|
|
console.log(dataMatrix);
|
|
|
|
// Funciones para limpiar los DATOS
|
|
// Remove double space
|
|
//
|