forked from RedTICS/extraccionDatos
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimportarDatos.ts
More file actions
81 lines (63 loc) · 3.11 KB
/
importarDatos.ts
File metadata and controls
81 lines (63 loc) · 3.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import {servicioMssql} from './servicioMssql'
import {servicioHeller} from './servicioHeller';
import { servicioMongo } from './servicioMongo';
import {servicioSips} from './servicioSips';
import {servicioHPN} from './servicioHPN';
import * as fs from 'fs';
var servMongo = new servicioMongo();
var servHeller = new servicioHeller();
var servSips = new servicioSips();
var servHPN = new servicioHPN();
export class importarDatos {
//servicio.obtenerDatosSql(1, 1500000, config.user, config.password,
// config.serverSql, config.databaseSql, config.consultaPaciente)
importarRegistros(efector, usuario, password, server, db, consulta, archivo) {
var servicio = new servicioMssql();
var file = fs.createWriteStream(archivo);
return new Promise((resolve, reject) => {
servicio.obtenerDatosSql2(usuario, password, server, db, consulta)
.then((resultado) => {
if (resultado == null) {
console.log('No encontrado');
} else {
var listaPacientes = resultado;
var paciente;
console.log("Total Pacientes", listaPacientes.length);
if (listaPacientes.length > 0) {
console.log(efector, server, db);
var file = fs.createWriteStream(archivo);
file.on('error', function(err) { console.log(err) });
switch (efector) {
case "SIPS": {
listaPacientes.forEach(function(elem) {
paciente = servSips.formatearDatosSips(elem);
file.write(JSON.stringify(paciente) + '\n');
});
break;
}
case "HELLER": {
listaPacientes.forEach(function(elem) {
paciente = servHeller.formatearDatosHeller(elem);
file.write(JSON.stringify(paciente) + '\n');
});
break;
}
case "HPN": {
listaPacientes.forEach(function(elem) {
paciente = servHPN.formatearDatosHPN(elem);
file.write(JSON.stringify(paciente) + '\n');
});
break;
}
}
file.end(); //Se cierra el archivo
}
}
})
.catch((err) => {
console.error('Error**:' + err)
reject(err);
});
})
}
}