Skip to content

Instantly share code, notes, and snippets.

@jschappet
Last active April 26, 2018 15:52
Show Gist options
  • Save jschappet/e4f4902c65a61c065f5e469422170cbd to your computer and use it in GitHub Desktop.
Save jschappet/e4f4902c65a61c065f5e469422170cbd to your computer and use it in GitHub Desktop.
Does what I'm trying to do here make sense?
var patList = {};
var fs = require('fs');
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 writeFiles() {
for (var key in patList) {
//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'] ,
"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')
})
@chrisortman
Copy link

I think so, but I'm not sure why you have my_hash & ids ...

my_hash = {}
#first loop
my_hash.put(row[0], {:dx => empty, :tumor => empty})
#second loop
my_hash.has_key? row[0]

Depending on how big these files are you might also want lazy
http://blog.honeybadger.io/using-lazy-enumerators-to-work-with-large-files-in-ruby/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment