-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpacienteMpi.ts
More file actions
87 lines (83 loc) · 2.97 KB
/
pacienteMpi.ts
File metadata and controls
87 lines (83 loc) · 2.97 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
82
83
84
85
86
87
import * as http from 'http';
import * as config from './config';
export class PacienteMpi {
cargarUnPacienteMpi(paciente: any, token: any) {
return new Promise((resolve: any, reject: any) => {
let options = {
host: config.hostApi,
port: config.portApi,
path: config.pathPacienteMpi,
Authentication: token,
method: 'POST',
headers: {
'Authorization': token,
'Content-Type': 'application/json',
}
};
let req = http.request(options, function(res) {
res.on('data', function(body) {
resolve(body);
});
});
req.on('error', function(e) {
console.log('Problemas API en insert: ' + e.message + ' ----- ', e);
reject(e.message);
});
/*write data to request body*/
req.write(JSON.stringify(paciente));
req.end();
});
};
actualizaUnPacienteMpi(paciente: any, token: any) {
return new Promise((resolve: any, reject: any) => {
let id = paciente._id;
let options = {
host: config.hostApi,
port: config.portApi,
path: config.pathPacienteMpi + '/' + id,
method: 'PUT',
headers: {
'Authorization': token,
'Content-Type': 'application/json',
}
};
let req = http.request(options, function(res) {
res.on('data', function(body) {
resolve(body);
});
});
req.on('error', function(e) {
console.log('Problemas API en update : ' + e.message + ' ----- ', e);
reject(e.message);
});
/*write data to request body*/
req.write(JSON.stringify(paciente));
req.end();
});
};
/*No debería borrarse un paciente de mpi pero dejamos implementado el método por las dudas*/
borraUnPacienteMpi(paciente: any, token: any) {
return new Promise((resolve: any, reject: any) => {
let options = {
host: config.hostApi,
port: config.portApi,
path: config.pathPacienteMpi + '/' + paciente._id,
method: 'DELETE',
headers: {
'Authorization': token,
'Content-Type': 'application/json',
}
};
let req = http.request(options, function(res) {
res.on('data', function(body) {
resolve(body);
});
});
req.on('error', function(e) {
console.log('Problemas API : ' + e.message + ' ----- ', e);
reject(e.message);
});
req.end();
});
}
}