|
|
@ -5,7 +5,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
/** @type { Object.<string, Client> } */
|
|
|
|
/** @type { Object.<string, Client> } */
|
|
|
|
|
|
|
|
|
|
|
|
/** @type {{ name: string, province: string, ccaa: string, city: string, }} */
|
|
|
|
/** @type {Object.<string,{ name: string, province: string, ccaa: string, city: string}>} */
|
|
|
|
const codetoNameEquivalences = {
|
|
|
|
const codetoNameEquivalences = {
|
|
|
|
"AAA": { name: "Hospital Son Espases", province: "Baleares", ccaa: "Islas Baleares", city: "Palma", },
|
|
|
|
"AAA": { name: "Hospital Son Espases", province: "Baleares", ccaa: "Islas Baleares", city: "Palma", },
|
|
|
|
"BBB": { name: "Hospital Sant Joan Reus", province: "Tarragona", ccaa: "Cataluña", city: "Reus", },
|
|
|
|
"BBB": { name: "Hospital Sant Joan Reus", province: "Tarragona", ccaa: "Cataluña", city: "Reus", },
|
|
|
@ -226,6 +226,7 @@ const TARGET_VIEW_NAME = "Default View";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Helper functions
|
|
|
|
// Helper functions
|
|
|
|
|
|
|
|
|
|
|
|
const cleanTable = (name) => { // Removes all rows from a table
|
|
|
|
const cleanTable = (name) => { // Removes all rows from a table
|
|
|
|
const table = base.getTableByName(name);
|
|
|
|
const table = base.getTableByName(name);
|
|
|
|
if (table) {
|
|
|
|
if (table) {
|
|
|
@ -236,6 +237,7 @@ const cleanTable = (name) => { // Removes all rows from a table
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const clientCodeToName = (code) => { // Normalizes names according to client Code
|
|
|
|
const clientCodeToName = (code) => { // Normalizes names according to client Code
|
|
|
|
const clientCode = code.toString();
|
|
|
|
const clientCode = code.toString();
|
|
|
|
let clientName = "";
|
|
|
|
let clientName = "";
|
|
|
@ -245,6 +247,7 @@ const clientCodeToName = (code) => { // Normalizes names according to client Cod
|
|
|
|
return clientName;
|
|
|
|
return clientName;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const removeDoubleSpace = (str) => { // Removes double spaces in string
|
|
|
|
const removeDoubleSpace = (str) => { // Removes double spaces in string
|
|
|
|
if (typeof str !== "string") {
|
|
|
|
if (typeof str !== "string") {
|
|
|
|
return str;
|
|
|
|
return str;
|
|
|
@ -252,22 +255,21 @@ const removeDoubleSpace = (str) => { // Removes double spaces in string
|
|
|
|
return str.replace(/\s\s+/g, ' ');
|
|
|
|
return str.replace(/\s\s+/g, ' ');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Remove leading and ending spaces in string
|
|
|
|
const removeLeadingAndTrailingSpaces = (str) => { // Remove leading and ending spaces in string
|
|
|
|
const removeLeadingAndTrailingSpaces = (str) => {
|
|
|
|
|
|
|
|
if (typeof str !== "string") {
|
|
|
|
if (typeof str !== "string") {
|
|
|
|
return str;
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return str.trim();
|
|
|
|
return str.trim();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const MaterialCodeToDose = (str) => {
|
|
|
|
const materialCodeToDose = (str) => { // Converts material code to a string with the dosage
|
|
|
|
if (str === 211354) {
|
|
|
|
if (str === 211354) {
|
|
|
|
return "50mg";
|
|
|
|
return "50mg";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return "100mg";
|
|
|
|
return "100mg";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// get tables and views
|
|
|
|
// Activate tables and views
|
|
|
|
const originTable = base.getTableByName(ORIGIN_TABLE_NAME);
|
|
|
|
const originTable = base.getTableByName(ORIGIN_TABLE_NAME);
|
|
|
|
const originView = base.getViewByName(originTable, ORIGIN_VIEW_NAME);
|
|
|
|
const originView = base.getViewByName(originTable, ORIGIN_VIEW_NAME);
|
|
|
|
|
|
|
|
|
|
|
@ -275,7 +277,7 @@ const targetTable = base.getTableByName(TARGET_TABLE_NAME);
|
|
|
|
const targetView = base.getViewByName(targetTable, TARGET_VIEW_NAME);
|
|
|
|
const targetView = base.getViewByName(targetTable, TARGET_VIEW_NAME);
|
|
|
|
|
|
|
|
|
|
|
|
// List of the columns I want to replicate
|
|
|
|
// List of the columns I want to replicate
|
|
|
|
const selectedColumns = [
|
|
|
|
const columnsForImport = [
|
|
|
|
"Material",
|
|
|
|
"Material",
|
|
|
|
"Solic.",
|
|
|
|
"Solic.",
|
|
|
|
"Present.Concentr.",
|
|
|
|
"Present.Concentr.",
|
|
|
@ -283,6 +285,9 @@ const selectedColumns = [
|
|
|
|
"Nom Dest.",
|
|
|
|
"Nom Dest.",
|
|
|
|
"FechaFact.",
|
|
|
|
"FechaFact.",
|
|
|
|
"Cantidad UMB",
|
|
|
|
"Cantidad UMB",
|
|
|
|
|
|
|
|
"Lote-prov.",
|
|
|
|
|
|
|
|
"N.I.F. comunitario",
|
|
|
|
|
|
|
|
"Población Solic.",
|
|
|
|
]
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
const dataMatrix = []
|
|
|
|
const dataMatrix = []
|
|
|
@ -294,20 +299,16 @@ originRows.forEach(row => {
|
|
|
|
|
|
|
|
|
|
|
|
// Create new element with only the selected columns
|
|
|
|
// Create new element with only the selected columns
|
|
|
|
const element = {};
|
|
|
|
const element = {};
|
|
|
|
selectedColumns.forEach(column => {
|
|
|
|
columnsForImport.forEach(column => {
|
|
|
|
element[column] = removeLeadingAndTrailingSpaces(row[column]);
|
|
|
|
element[column] = removeLeadingAndTrailingSpaces(row[column]);
|
|
|
|
element[column] = removeDoubleSpace(element[column]);
|
|
|
|
element[column] = removeDoubleSpace(element[column]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// Material to Abarax
|
|
|
|
// Material to Abarax
|
|
|
|
element["Material"] = MaterialCodeToDose(element["Material"]);
|
|
|
|
element["Material"] = materialCodeToDose(element["Material"]);
|
|
|
|
|
|
|
|
|
|
|
|
// Add element to dataMatrix
|
|
|
|
// Add element to dataMatrix
|
|
|
|
dataMatrix.push(element);
|
|
|
|
dataMatrix.push(element);
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
console.log(dataMatrix);
|
|
|
|
console.log(dataMatrix);
|
|
|
|
|
|
|
|
|
|
|
|
// Funciones para limpiar los DATOS
|
|
|
|
|
|
|
|
// Remove double space
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|