This repository was archived by the owner on Sep 13, 2022. It is now read-only.
forked from drkreddy/ocb-lab-data-migration-formatter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvertFuchiaLabData.js
84 lines (76 loc) · 2.86 KB
/
convertFuchiaLabData.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
const lib = require("./lib.js");
const getVisitType = (visitTypeSynonym) => {
switch (visitTypeSynonym) {
case 'Hospitalisation':
return 'IPD';
case 'Consultation':
return 'OPD';
default:
return '';
}
};
const mapHepBValue = (synonym) => {
switch (synonym) {
case 'Positive':
return 'Positif';
case 'Negative':
return 'Négatif';
default:
return '';
}
};
const mapGlucoseValue = (synonym) => {
switch (synonym) {
case '0':
return 'Négatif';
case '1+':
return '+';
case '2+':
return '++';
case '3+':
return '++';
default:
return '';
}
};
const mapProteinValue = (synonym) => mapGlucoseValue(synonym);
const writeAsCSV = function (lines, destFileName) { //Need to make it generic
const contents = lines.filter((line) => {
return !!line["Sample Date"];
}).map((line) => {
const hepBValue = mapHepBValue(line['Hep B(Positive, Negative, Not specified)']);
const glucoseValue = mapGlucoseValue(line['Glucose(urine)(0, 1+, 2+, 3+, Non spécifié)']);
const proteinValue = mapProteinValue(line["Proteine(urine)(0, 1+, 2+, 3+, Non spécifié)"]);
return [
lib.getIdentifier(line["Patient ID"]), lib.getDate(line["Sample Date"]), getVisitType(line['Visit Type']),
lib.getTestName("Hépatite B", hepBValue), hepBValue,
lib.getTestName("GPT", line["GPT"]), line["GPT"],
lib.getTestName("Creatinine", line["Creatinine"]), line["Creatinine"],
lib.getTestName("Hemoglobine", line["Hemoglobine"]), line["Hemoglobine"],
lib.getTestName("Glucose", glucoseValue), glucoseValue,
lib.getTestName("LYM%", line["LYM%(sang)"]), line["LYM%(sang)"],
lib.getTestName("CD4", line["CD4"]), line["CD4"],
lib.getTestName("CD4 % (enfants de - 5 ans)", line["CD4 %"]), line["CD4 %"],
lib.getTestName("Charge Virale HIV - Value", line["Viral Load"]), line["Viral Load"],
lib.getTestName("Protéines", proteinValue), proteinValue
].map(el => el ? el.split(',').join('.') : "")
.join(",");
});
contents.unshift(["Registration Number", "Date", "Visit Type",
"Test", "Result",
"Test", "Result",
"Test", "Result",
"Test", "Result",
"Test", "Result",
"Test", "Result",
"Test", "Result",
"Test", "Result",
"Test", "Result",
"Test", "Result"].join(","));
return lib.writeToDestFile(contents.join("\r\n"), destFileName);
};
module.exports = (sourceFileName, destFileName) => {
lib.convertCSVToJSON(sourceFileName).then(function (data) {
writeAsCSV(data, lib.getDestFileName(sourceFileName, destFileName))
});
};