mejoras en importarexcel

main
borja 1 year ago
parent 9a65f4d52c
commit 4f9aabbd9c

@ -5,7 +5,7 @@
/** @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 = {
"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", },
@ -226,6 +226,7 @@ const TARGET_VIEW_NAME = "Default View";
// Helper functions
const cleanTable = (name) => { // Removes all rows from a table
const table = base.getTableByName(name);
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 clientCode = code.toString();
let clientName = "";
@ -245,6 +247,7 @@ const clientCodeToName = (code) => { // Normalizes names according to client Cod
return clientName;
}
const removeDoubleSpace = (str) => { // Removes double spaces in string
if (typeof str !== "string") {
return str;
@ -252,22 +255,21 @@ const removeDoubleSpace = (str) => { // Removes double spaces in string
return str.replace(/\s\s+/g, ' ');
}
// Remove leading and ending spaces in string
const removeLeadingAndTrailingSpaces = (str) => {
const removeLeadingAndTrailingSpaces = (str) => { // Remove leading and ending spaces in string
if (typeof str !== "string") {
return str;
}
return str.trim();
}
const MaterialCodeToDose = (str) => {
const materialCodeToDose = (str) => { // Converts material code to a string with the dosage
if (str === 211354) {
return "50mg";
}
return "100mg";
}
// get tables and views
// Activate tables and views
const originTable = base.getTableByName(ORIGIN_TABLE_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);
// List of the columns I want to replicate
const selectedColumns = [
const columnsForImport = [
"Material",
"Solic.",
"Present.Concentr.",
@ -283,6 +285,9 @@ const selectedColumns = [
"Nom Dest.",
"FechaFact.",
"Cantidad UMB",
"Lote-prov.",
"N.I.F. comunitario",
"Población Solic.",
]
const dataMatrix = []
@ -294,20 +299,16 @@ originRows.forEach(row => {
// Create new element with only the selected columns
const element = {};
selectedColumns.forEach(column => {
columnsForImport.forEach(column => {
element[column] = removeLeadingAndTrailingSpaces(row[column]);
element[column] = removeDoubleSpace(element[column]);
});
// Material to Abarax
element["Material"] = MaterialCodeToDose(element["Material"]);
element["Material"] = materialCodeToDose(element["Material"]);
// Add element to dataMatrix
dataMatrix.push(element);
})
console.log(dataMatrix);
// Funciones para limpiar los DATOS
// Remove double space
//

Loading…
Cancel
Save