-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrecord_epicenter.js
507 lines (455 loc) · 18.3 KB
/
record_epicenter.js
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
var logger = require('winston');
var utils = require('./toolbox');
/***************************************
* HeaderRecord *
****************************************
* Sample header record text:
* H|\^&| | |Becton Dickinson| | | | | | | |V1.00|19981019184200
*
**/
function HeaderRecord(){
this.buildFromRecord = function(record){
// Not implemented as is not needed
}
this.toASTM = function (){
return [
'H',
[ [null], [null,'&'] ],
null,
null,
'Becton Dickinson',
null,
null,
null,
null,
null,
null,
null,
'V1.00',
'20170510183000' // Not used in dowloaded messages
];
}
}
/***************************************
* TerminationRecord *
****************************************
* Sample termination record text:
* L|1|N
*
**/
function TerminationRecord(){
this.type = 'N'
this.buildFromRecord = function(record){
// Not implemented as is not needed
}
this.toASTM = function (){
return [ 'L', '1', this.type];
}
}
/***************************************
* PatientRecord *
****************************************
* Sample patient record text:
*
* P|1| |PatId123| |Doe^John^R^Jr.^Dr.| |19651029|M| |2 Main
* St.^Baltimore^ MD^21211^USA| |(410) 316 - 4000|JSMITH| | |
* | |PNEU|P\AM\AMX| | | |19981015120000| |324| | | | | | |ER|St.
* Josephs Hospital
*
**/
function PatientRecord(){
this.adress = '';
this.phone = '';
this.physicianId = '';
this.diagnosis = '';
this.admissionDate = '';
this.roomNumber = '' ;
this.hospitalService = '';
this.hospitalClient= '';
this.buildFromRecord = function(record){
// TODO Check if pacient uploaded data is neccesary in LIS
}
this.toASTM = function (){
return [
'P',
'1',
null,
this.id, // max_lenght=16
null,
[this.name,null,null,null,null], // max_lenght=40
null,
this.birthdate, // YYYYMMDDHHMMSS
this.sex,
null,
[this.adress,null,null,null,null], // max_lenght = 255
null,
this.phone , // max_lenght = 25
this.physicianId,
null,
null,
null,
null,
this.diagnosis,
this.toASTMComponent(this.therapy), // therapy must be an array up to 5 antibiotics Ej. ['P','AM','AMX']. This must be encoded to P\AM\AMX
null,
null,
null,
this.admissionDate, // YYYYMMDDHHMMSS
null,
this.roomNumber, // max_lenght = 10
null, // User Defined Patient Fields.
null,
null,
null,
null,
null,
this.hospitalService,
this.hospitalClient,
];
}
this.toASTMComponent = function (component){
if(typeof component === 'undefined' || component === null){
return [];
}
else{
var antibiotic = [component[0]];
if (component.length == 1){
return antibiotic;
}
else{
return [antibiotic, this.toASTMComponent(component.slice(1))]
}
}
}
}
/***************************************
* ResultRecord *
****************************************
* Sample result record text:
* R|1|^^^458/|55|mg/dl||N||F|||||P1
*
* BACTEC MGIT 960 growth and detection test level result example
* R|1| ^ ^ ^GND_MGIT^430100001234|INST_POSITIVE ^87| | | | |P| | |19981019153400|19981020145000| MGIT960^^42^3^B/A12
* R|1| ^ ^ ^AST_MGIT^439400005678^P^0.5^ug/ml| INST_COMPLETE^105^^S| | | | |P| | |19981019153400| 19981020145000|MGIT960^^42^3^ B/A12
* BACTEC MGIT 960 AST test level result example:
* R|1| ^ ^ ^AST_MGIT^439400005678^P^0.5^ug/ml| INST_COMPLETE^105^^S| | | | |P| | |19981019153400| 19981020145000|MGIT960^^42^3^ B/A12
*
* AST Result records contain antibiotic and susceptibility information.
* ID Result records contain organism and Resistance Marker information.
* Growth and Detection result records contain a Positive or Negative status.
* For AST sets, several result records may be sent to the LIS in a single message.
* Each result record would report the results for a single drug in the AST set.
* For ID/AST combo tests, an ID result record is sent as the first result record,
* and the AST result records follow. An example AST set result message is shown
* in the Appendix A of this document.
*
**/
function ResultRecord(){
this.buildFromRecord = function(record){
try{
this.type = record[0];
this.seq = record[1];
// this.code = record[2][3];
// switch (this.code){
// case "GND": handleResultGND(record); break;
// case "GND_MGIT": handleResultGND_MGIT(record); break;
// case "GND_PROBETEC": handleResultGND_PROBETEC(record); break;
// case "AST": handleResultAST(record); break;
// case "AST_MGIT": handleResultAST_MGIT(record); break;
// case "AST_MIC": handleResultAST_MIC(record); break;
// case "AST_DIA": handleResultAST_DIA(record); break;
// case "ID": handleResultID(record); break;
// case "OTHER": handleResultOTHER(record); break;
// }
if (this.fieldHasValue(record[2])) {
this.code = this.getFieldValue(record[2],3);
this.testSeqNumber = this.getFieldValue(record[2],4);
this.antibiotic = this.getFieldValue(record[2],5);
this.concentration = this.getFieldValue(record[2],6);
this.concentrationUnit = this.getFieldValue(record[2],7);
}
if (this.fieldHasValue(record[3])) {
this.testStatus = this.getFieldValue(record[3],0);
// Result Data Field 1
this.growthUnits = this.getFieldValue(record[3],1); // Bactec results only
this.probeTecETAlgorithmicResult = this.getFieldValue(record[3],1); // BDProbeTec ET/Viper SP Result Onlyactec results only
this.minimumInhibitoryConcentration = this.getFieldValue(record[3],1); // MIC based AST results
this.diameter = this.getFieldValue(record[3],1); // Diameter based AST results
this.organism = this.getFieldValue(record[3],1); // ID results only
// Result Data Field 2
this.ASTsusceptibilityFinal = this.getFieldValue(record[3],2); // Isolate AST results only
this.profileNumber = this.getFieldValue(record[3],2); // ID results and Isolate ID results
// Result Data Field 3
this.ASTsusceptibilityInterpreted = this.getFieldValue(record[3],3);// All AST Results
this.resistanceMarker1 = this.getFieldValue(record[3],3); // Isolate ID results
// Result Data Field 4
this.ASTsusceptibilityExpert = this.getFieldValue(record[3],4); // Isolate AST results only
this.resistanceMarker2 = this.getFieldValue(record[3],5); // Isolate ID Results
// Result Data Field 5
this.ASTsourceTest = this.getFieldValue(record[3],5); // Isolate AST Results
this.resistanceMarker3 = this.getFieldValue(record[3],5); // Isolate ID Results
// Result Data Field 6
this.resistanceMarker4 = this.getFieldValue(record[3],6); // Isolate ID Results
// Result Data Field 7
this.resistanceMarker5 = this.getFieldValue(record[3],7); // Isolate ID Results
}
this.preliminaryFinalStatus = record[8];
this.startDate = record[11];
if (this.fieldHasValue(record[12])) {
this.resultStatusDate = this.getFieldValue(record[12],0);
this.testCompleteDate = this.getFieldValue(record[12],1);
}
if (this.fieldHasValue(record[13])) {
this.instrumentType = this.getFieldValue(record[13],0);
this.mediaType = this.getFieldValue(record[13],1);
this.protocolLength = this.getFieldValue(record[13],2);
this.instrumentNumber = this.getFieldValue(record[13],3);
this.instrumentLocation = this.getFieldValue(record[13],4);
this.BDProbeTecETQCYype = this.getFieldValue(record[13],5);
this.BDProbeTecETQCKitLotNumber = this.getFieldValue(record[13],6);
}
if (this.fieldHasValue(record[14])) {
this.additionalResultsQuantity = this.getFieldValue(record[14],0);
this.additionalResults= this.getFieldValue(record[14],1);
}
}
catch(err){
logger.error('Cannot build ResultRecord.' + err);
throw new Error(err);
}
}
this.fieldHasValue= function(field) {
return (typeof field !== 'undefined' && field !== null);
}
this.getFieldValue= function(field, index) {
var value = '';
if (Object.prototype.toString.call(field) === '[object Array]'){
if (field.length > index){
value = field[index];
}
}
else{
if (index === 0){
value = field;
}
}
return value;
}
/*
* Identification test level result example:
* R|1| ^ ^ ^ID^Seq123|Complete^MYCBTUB^45678^RM_VRE| | | | |F| | |19981019153400|19981020145000
*/
// this.handleResultID = function(record){
// this.testSeqNumber = record[2][4];
// this.testStatus = record[3][0];
// this.organism = record[3][1];
// this.profileNumber = record[3][2];
// this. = record[3][3]; // TODO Chequear si no es necesario por nulos o fuera de indices
// this.preliminaryFinalStatus = record[8];
// this.startDate = record[11];
// this.resultDate = record[12]; // TODO Chequear si viene como un componente este valor
// }
// /*
// * Isolate level result example:
// * R|1| ^^^AST^^P^100.0^ug/mL| ^^R^R^^MGIT_960_AST92| | | | |F
// */
// this.handleResultAST = function(record){
// this.testSeqNumber = record[2][4];
// this.antibiotic = record[2][5];
// this.concentration = record[2][6];
// this.concentrationUnit = record[2][7];
// this.testStatus = record[3][0];
// this.susceptibilityFinal = record[3][2];
// this.susceptibilityInterpreted = record[3][3];
// this.susceptibilityExpert = record[3][4];
// this.sourceTest = record[3][5];
// this.preliminaryFinalStatus = record[8];
// this.startDate = record[11];
// this.resultDate = record[12]; // TODO Chequear si viene como un componente este valor
// }
}
/****************************
* OrderRecord *
*****************************
* Sample order record text:
* O|1|Acc123^1^MYCBTUB | | ^ ^ ^ MGIT_960_GND ^Seq123|
* | |19981019023300| | |SJB^MMF|A| | |19981019045200
* |Blood^Arm|MJones|(410) 555 – 1234^(410) 555 – 9876^(410) 555 – 7777
* | | | | |19981020053400|62| |O| | |Nos
*
*
* Sample order record decoded
*
**/
function OrderRecord(){
this.seq = '1';
this.isolateNumber = '';
this.organism = '';
this.excludeIsolate = '';
this.testId = '';
this.testConsumableSeq = '';
this.priority = '';
this.collectionDate = utils.formatDate(new Date(),'yyyyMMddHHmmss');
this.collectedBy = '';
this.receivedBy = '';
this.specimenActionCode = '';
this.receiptDate = utils.formatDate(new Date(),'yyyyMMddHHmmss');
this.specimenType = '';
this.bodySite = '';
this.orderingPhysician = '';
this.orderingPhysicianPhone = '';
this.orderingPhysicianFax = '';
this.orderingPhysicianPager = '';
this.userDefinedFields = '';
this.finalizedDate = '';
this.specimenRebursementValue = '';
this.reportType = '';
this.isolateClassification = '';
this.buildFromRecord = function(record){
try{
this.type = record[0];
this.seq = record[1];
if (this.fieldHasValue(record[2])) {
this.accessionNumber = this.getFieldValue(record[2], 0); // max_lenght = 20. ProtocolID
this.isolateNumber = this.getFieldValue(record[2],1);
this.organism = this.getFieldValue(record[2],2);
this.excludeIsolate = this.getFieldValue(record[2],3);
}
if (this.fieldHasValue(record[4])) {
this.testId = this.getFieldValue(record[4],3);
this.testConsumableSeq = this.getFieldValue(record[4],4);
}
this.priority = record[5];
this.collectionDate = record[7];
if (this.fieldHasValue(record[10])) {
this.collectedBy = this.getFieldValue(record[10],0);
this.receivedBy = this.getFieldValue(record[10],1);
}
this.specimenActionCode = record[11];
if (this.fieldHasValue(record[13])) {
this.isolateSourceTest = this.getFieldValue(record[13],0);// [[[],[],[]],[[],[],[]]]
this.isolateSourceTestStartTime = this.getFieldValue(record[13],1);
}
this.receiptDate = record[14];
if (this.fieldHasValue(record[15])) {
this.specimenType = this.getFieldValue(record[15],0);
this.bodySite = this.getFieldValue(record[15],1);
}
this.orderingPhysician = record[16];
if (this.fieldHasValue(record[17])) {
this.orderingPhysicianPhone = this.getFieldValue(record[17],0)
this.orderingPhysicianFax = this.getFieldValue(record[17],1)
this.orderingPhysicianPager = this.getFieldValue(record[17],2)
}
// this.userDefinedFields = record[18];
this.finalizedDate = record[22];
this.specimenRebursementValue = record[23]; // TODO check with real values from Epicenter
// this.testReimbursementValue = record[23][1];
this.reportType = record[25];
this.isolateClassification = record[28];
}
catch(err){
logger.error('Cannot build OrderRecord.' + err)
throw new Error(err);
}
}
this.toASTM = function (){
var timestamp = utils.formatDate(new Date(),'yyyyMMddHHmmss');
return [
'O',
this.seq,
[this.accessionNumber, this.isolateNumber, this.organism, this.excludeIsolate],
null,
[null, null, null, this.testId,this.testConsumableSeq],
this.priority,
null,
this.collectionDate,
null,
null,
[this.collectedBy, this.receivedBy],
this.specimenActionCode,
null,
this.toASTMComponent(this.isolateSourceTest,this.isolateSourceTestStartTime),
this.receiptDate,
[this.specimenType, this.bodySite],
this.orderingPhysician,
[this.orderingPhysicianPhone,this.orderingPhysicianFax,this.orderingPhysicianPager],
this.userDefinedFields,
null,
null,
null,
this.finalizedDate,
this.specimenRebursementValue, //this.testReimbursementValue
null,
this.reportType,
null,
null,
this.isolateClassification
];
}
this.toASTMComponent = function (isolateSourceTest, isolateSourceTestStartTime){
// Should return [[[],[],[]],[[],[],[]]]
return null;
// var antibiotic = [component[0]];
// if (component.length == 1){
// return antibiotic;
// }
// else{
// return [antibiotic, this.toASTMComponent(component.slice(1))]
// }
}
this.fieldHasValue= function(field) {
return (typeof field !== 'undefined' && field !== null);
}
this.getFieldValue= function(field, index) {
var value = '';
if (Object.prototype.toString.call(field) === '[object Array]'){
if (field.length >= index){
value = field[index];
}
}
else{
if (index === 0){
value = field;
}
}
return value;
}
}
/***************************************
* CommentRecord *
****************************************
* Sample comment record text:
* C|1| | Special message text.(AM, CAZ)|T
*
**/
function CommentRecord(){
this.buildFromRecord = function(record){
try{
this.type = record[0];
this.seq = record[1];
this.comment = record[4];
this.commentType = record[5];
}
catch(err){
logger.error('Cannot build CommentRecord.' + err)
throw new Error(err);
}
}
this.toASTM = function (){
return [
'C',
'1',
null,
this.comment,
this.commentType]; // This field should be a P, S, I, E, or T for patient, specimen, isolate, chartables rule, or special message comments respectively
}
}
module.exports = {
ResultRecord: ResultRecord,
OrderRecord : OrderRecord,
HeaderRecord : HeaderRecord,
TerminationRecord : TerminationRecord,
CommentRecord : CommentRecord,
PatientRecord : PatientRecord,
};