Last active
May 24, 2018 21:04
-
-
Save jschappet/85d96ae60082b3a155ffcaf48ec8a5d5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var patList = {}; | |
var fs = require('fs'); | |
var myRequest = require('request'); | |
function saveFile(patId, obj) { | |
fs.writeFile(patId+".json", JSON.stringify(obj), function(err) { | |
if(err) { | |
return console.log(err); | |
} | |
//console.log("The file was saved: %s" , patId+".json"); | |
}); | |
} | |
function getDoc(docid) { | |
var urlString = "http://localhost:9292/clinicnote?noteid=" + docid; | |
var options = { | |
url: urlString, | |
}; | |
myRequest(options, function (error, res, body) { | |
//console.log("getting url"); | |
if (!error && res.statusCode == 200) { | |
var bodyObj = JSON.parse(body); | |
//console.log(bodyObj); | |
//dbInfo = bodyObj; | |
console.log(bodyObj); | |
} else { | |
//response.writeHead(403, {'Content-Type': 'application/json'}); | |
console.log("error"); | |
//console.log(error); | |
console.log(res); | |
console.log(body); | |
} | |
}); | |
} | |
function writeFiles() { | |
for (var key in patList) { | |
getDoc(142855548) | |
//console.log(JSON.stringify(patList[key])) | |
saveFile(key,patList[key]); | |
} | |
} | |
function updateTumor() { | |
const csvTumor=require('csvtojson') | |
csvTumor() | |
.fromFile('tumor_properties_1523643565883.csv') | |
.on('json',(jsonTumor)=>{ | |
// combine csv header row and csv line to a json object | |
pat = patList[jsonTumor['Patient ID']]; | |
if (pat != undefined ) { | |
console.log("Tumor Pat: %s", pat.patId); | |
var dx = { | |
"tumorCode": jsonTumor['Tumor Property Code'] , | |
"description": jsonTumor['Tumor Property Description'] , | |
"date": jsonTumor['Observation Date'] , | |
"docId": jsonTumor['Document ID'] , | |
"negated": jsonTumor['Negated'] , | |
}; | |
pat.info.tumor.push(dx); | |
} | |
}).on('done',(error)=>{ | |
updateOncology() | |
} ); | |
} | |
function updateOncology() { | |
console.log("starting oncology") | |
const csvOnc=require('csvtojson') | |
csvOnc() | |
.fromFile('oncology_1523643565883.csv') | |
.on('json',(jsonOnc)=>{ | |
// combine csv header row and csv line to a json object | |
console.log("Checking pat: %s", jsonOnc['Patient ID']); | |
pat = patList[jsonOnc['Patient ID']]; | |
if (pat != undefined ) { | |
console.log("Oncology Pat: %s", pat.patId); | |
var dx = { | |
"tumorSiteCode": jsonOnc['Tumor Site Code'] , | |
"morphologyCode": jsonOnc['Morphology Code'] , | |
"date": jsonOnc['Observation Date'] , | |
"docId": jsonOnc['Document ID'] , | |
"grade": jsonOnc['Grade Code'] , | |
"stage": jsonOnc['Stage Code'] , | |
"T": jsonOnc['T'] , | |
"N": jsonOnc['N'] , | |
"M": jsonOnc['M'] , | |
"laterality": jsonOnc['laterality'] , | |
"negated": jsonOnc['Negated'] , | |
}; | |
pat.info.oncology.push(dx); | |
} | |
}).on('done',(error)=>{ writeFiles() } ); | |
} | |
const idMRNList = 'ID_MRN_List.csv'; | |
const idMap=require('csvtojson') | |
idMap().fromFile(idMRNList) | |
.on('json',(jsonObj)=>{ | |
// combine csv header row and csv line to a json object | |
var patient = {"dx" : [] , "tumor" : [] , "oncology": [] }; | |
patList[""+jsonObj.patient_ir_id] = { "patId": jsonObj.patient_ir_id, "patmrn": jsonObj.PAT_MRN_ID, "info": patient }; | |
}) | |
.on('done',(error)=>{ | |
const csvFilePath='diagnosis_1523643565883.csv' | |
const csv=require('csvtojson') | |
csv() | |
.fromFile(csvFilePath) | |
.on('json',(json)=>{ | |
// combine csv header row and csv line to a json object | |
pat = patList[json['Patient ID']]; | |
if (pat != undefined ) { | |
var dx = { | |
"icd10": json['Diagnosis Code'] , | |
"description": json['Diagnosis Description'] , | |
"date": json['Diagnosis Date'] , | |
"docId": json['Document ID'] , | |
"negated": json['Negated'] , | |
}; | |
pat.info.dx.push(dx); | |
//console.log(patList[json['Patient ID']].patId + ": " + pat.info.dx) ; | |
} | |
}) | |
.on('done',(error) => { | |
updateTumor(); | |
}) | |
.on('done',(error1) => { | |
//writeFiles(); | |
} ) | |
console.log('end') | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment