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.
179 lines
6.4 KiB
JavaScript
179 lines
6.4 KiB
JavaScript
// Read Excel file and copy the relevant columns to the main table (with proper column types)
|
|
const codetoNameEquivalences = {
|
|
"AAA": "Hospital Son Espases",
|
|
"70000": "Hospital General Universitario de Elche",
|
|
"70001": "Hospital Universitario de San Juan de Alicante",
|
|
"70002": "Hospital Universitario de Valme",
|
|
"70003": "Institut Catala de Salut",
|
|
"70004": "Servicio Andaluz de Salud",
|
|
"70005": "Servei Balear de Salut",
|
|
"70006": "Sección Suministro de Medicamentos Extranjeros de Madrid",
|
|
"70007": "Area de Gestión Almería Norte (Hospital Inmaculada)",
|
|
"70008": "Consejería de Salud de La Rioja",
|
|
"70009": "Servicio Murciano de Salud",
|
|
"70010": "Servicios Periféricos de Sanidad y Asuntos Sociales Albacete",
|
|
"70011": "Jefatura Territorial de Sanidad de Pontevedra",
|
|
"70012": "Departamento de Sanidad de Guipuzcoa",
|
|
"70013": "Hospital Clínico San Carlos",
|
|
"70014": "Agencia Sanitaria Costa del Sol",
|
|
"70015": "Consorcio Hospital General Universitario de Valencia",
|
|
"70016": "Hospital Luis Alcañiz de Xátiva",
|
|
"70017": "Hospital Materno Infantil Vall d'Hebron",
|
|
"70018": "Hospital Sant Joan de Reus",
|
|
"70019": "Institut d'Assistencia Sanitaria",
|
|
"70020": "Corporación Sanitaria Parc Tauli",
|
|
"70021": "Hospital Can Misses",
|
|
"70022": "Hospital Universitario Insular de Gran Canaria",
|
|
"70023": "Delegación Territorial de Salud de Bizkaia",
|
|
"70024": "Fundación Sant Hospital - Seo Urgel",
|
|
"70025": "Distrito Sanitario Jerez-Costa Norte",
|
|
"70026": "Consorcio Sanitario del Maresme",
|
|
"70027": "Consorcio Sanitario del Garraf",
|
|
"70028": "Hospital Son Llatzer",
|
|
"70029": "Consorcio Mar Parc de Salut (Hospital del Mar)",
|
|
"70030": "Hospital de la Ribera",
|
|
"70031": "Hospital Severo Ochoa de Leganés",
|
|
"70032": "Area de Gestión Sanitaria Sur de Granada",
|
|
"70033": "Hospital Universitario de Bellvitge",
|
|
"70034": "Hospital General Vall d'Hebron",
|
|
"70035": "Distrito Sanitario de Granada - Metropolitano - Complejo Almanjayar",
|
|
"70036": "Fundación Hospital Asilo de Granollers",
|
|
"70037": "Hospital General de Requena",
|
|
"70038": "Fundación Asistencial Mutua Terrasa",
|
|
"70039": "Althaia Xarxa Assistencial Universitaria Manresa",
|
|
"70040": "Hospital Universitario San Cecilio de Granada",
|
|
"70041": "Hospital Universitario La Fé",
|
|
"70042": "Consorcio Sanitario de Terrasa",
|
|
"70043": "Delegación Provincial de Sanidad de Orense",
|
|
"70044": "Hospital Clínico Universitario Virgen de la Victoria",
|
|
"70045": "Plataforma Logística Sanitaria Almería",
|
|
"70046": "Hospital General Universitario de Alicante",
|
|
"70047": "Fundación de Gestión Sanitaria de L'Hospitalet",
|
|
"70048": "Hospital Universitario Virgen de la Macarena",
|
|
"70049": "Hospital Marina Baixa",
|
|
"70050": "Gerencia de Salud de Área de Ávila",
|
|
"70055": "Consorcio Hospitalario de Vic",
|
|
"70060": "Servicio Canario de Salud",
|
|
"70061": "Distrito Sanitario Costa del Sol - Hospital Costa del Sol",
|
|
"70062": "Hospital de Manises de Valencia",
|
|
"70063": "Hospital Clínico de Barcelona",
|
|
"70064": "Hospital Comarcal de Sant Bernabé",
|
|
"70065": "Fundacio Salut Emporda",
|
|
"70070": "Hospital Materno Infantil de Málaga",
|
|
"70071": "Hospital San Francisco de Borja",
|
|
"70072": "Hospital San Juan de Dios",
|
|
"70073": "Hospital Universitario Dr. Peset",
|
|
"70074": "Hospital Vega Baja de Orihuela",
|
|
"70075": "Hospital de Denia - Marina Salud",
|
|
"70076": "Hospital Regional Carlos Haya",
|
|
"70077": "Hospital de Manacor",
|
|
"70080": "Delegación Provincial de Salud de Albacete - Hospital General",
|
|
"70081": "Hospital Universitario Arnau de Vilanova",
|
|
"70082": "Osakidetza",
|
|
"70083": "Hospital Mateu Órfila",
|
|
"70085": "Hospital General Básico de la Axarquía",
|
|
"70090": "Servicio Territorial de Sanidad y Bienestar Social de Burgos",
|
|
"70091": "Servicio Territorial de Sanidad y Bienestar Social de Valladolid",
|
|
"70095": "Hospital General de La Línea",
|
|
"70100": "Hospital Universitario Puerta de Hierro",
|
|
"70101": "Hospital General Universitario de Elda",
|
|
"70102": "Consorci Sanitari Integral de Hospitalet",
|
|
"70103": "Hospital Universitario Dr. Negrín",
|
|
"70105": "Hospital de Navarra",
|
|
"70106": "Hospital Juan XXIII",
|
|
"70107": "Hospital Arnau de Vilanova en Lliria",
|
|
"70110": "Hospital Universitario Central de Asturias",
|
|
"70115": "Gerencia de Salud de Área de Valladolid",
|
|
"70116": "Consejería de Sanidad Universal y Salud Pública de C. Valenciana",
|
|
"70120": "Dirección Provincial de Sanidad de Ciudad Real",
|
|
"70125": "Hospital Txagorritxu de Vitoria",
|
|
"70130": "Hospital Comarcal de Vinaroz",
|
|
"70135": "Distrito Sanitario Metropolitano de Granada", // Acaso no es el mismo que 70035?
|
|
"70140": "Hospital General Obispo Polanco",
|
|
|
|
}
|
|
// 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 = "";
|
|
if (codetoNameEquivalences[clientCode]) {
|
|
clientName = codetoNameEquivalences[clientCode];
|
|
}
|
|
return 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
|
|
//
|