Skip to content

Commit

Permalink
openHealth data siphoning (see .sodas and .sodaAll)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasalmeida committed Oct 5, 2014
1 parent 1bb5ab9 commit 401c08b
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 1 deletion.
65 changes: 65 additions & 0 deletions jobs/pqiSuffolk.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
console.log("pqiSuffolk.js")

// https://health.data.ny.gov/Health/Hospital-Inpatient-Prevention-Quality-Indicators-P/5q8c-d6xq
// get all data with a set of zip codes

// start with the dependencies
openHealth.getScript(["//cdnjs.cloudflare.com/ajax/libs/d3/3.4.11/d3.min.js","https://www.google.com/jsapi","//square.github.io/crossfilter/crossfilter.v1.min.js","//dc-js.github.io/dc.js/js/dc.js","//dc-js.github.io/dc.js/css/dc.css"],function(){ // after satisfying d3 dependency


pqi=(function(){
var zipSuffolk=["501","544","6390","11701","11702","11703","11704","11705","11706","11707","11708","11713","11715","11716","11717","11718","11719","11720","11721","11722","11724","11725","11726","11727","11729","11730","11731","11733","11738","11739","11740","11741","11742","11743","11745","11746","11747","11749","11750","11751","11752","11754","11755","11757","11760","11763","11764","11766","11767","11768","11769","11770","11772","11775","11776","11777","11778","11779","11780","11782","11784","11786","11787","11788","11789","11790","11792","11794","11795","11796","11798","11805","11901","11930","11931","11932","11933","11934","11935","11937","11939","11940","11941","11942","11944","11946","11947","11948","11949","11950","11951","11952","11953","11954","11955","11956","11957","11958","11959","11960","11961","11962","11963","11964","11965","11967","11968","11969","11970","11971","11972","11973","11975","11976","11977","11978","11980","STATEWIDE"];
var urls = zipSuffolk.map(function(z){return "https://health.data.ny.gov/resource/5q8c-d6xq.json?patient_zipcode="+z});
openHealth.sodas(urls,undefined,function(dt){
document.getElementById('openHealthJob').innerHTML='<span style="color:green"> > <b style="color:blue">'+dt.length+'</b> PQI Suffolk records found in <a href="https://health.data.ny.gov/Health/Hospital-Inpatient-Prevention-Quality-Indicators-P/5q8c-d6xq" target=_blank>https://health.data.ny.gov</a> (ref# 5q8c-d6xq)<br> > Hospital Inpatient Prevention Quality Indicators (PQI) for Adult Discharges by Zip Code (SPARCS): Beggining 2009 <br><span style="color:red" id="jobMsg">Assembling visualization ...</span></span>';
document.getElementById('openHealthJob').innerHTML+='<table><tr><td id="suffolkChoropleth">map goes here</td></tr></table><table><tr><td id="suffolkYearPie">year</td><td id="suffolkObservedPqi">pqi</td><td id="suffolkExpectedPqi">predicted vs observed</td></tr></table>';

openHealth.getJSON("jobs/zips_suffolk_HD_geo.json",function(zipMap){
console.log("map loaded");
var C_Map = dc.geoChoroplethChart("#suffolkYearPie");
var C_Pie = dc.pieChart("#suffolkChoropleth");
var C_Obs = dc.barChart("#suffolkObservedPqi");
var C_Exp = dc.barChart("#suffolkExpectedPqi");


var cf=crossfilter(dt);
var zips = cf.dimension(function(d){return d.patient_zipcode});
var G_zips = zips.group().reduceSum(
function(d){return Math.random()*1000}
)

/*zips.group().reduce(
// reduce in
function(p,v){return Math.random()*1000},
// reduce out
function(p,v){return Math.random()*1000},
// ini
function(){return Math.random()*1000}
)*/

var year = cf.dimension(function(d){return d.year});
var pqi = cf.dimension(function(d){return d.pqi_name});

C_Map.width(990)
.height(500)
.dimension(zips)
.projection(d3.geo.albersUsa().scale(28000).translate([-8200,2400]))
.group(G_zips)
.overlayGeoJson(zipMap.features, "zips", function (d) {
return d.properties.ZCTA5CE10;
})
dc.renderAll();

document.getElementByID("jobMsg").textContent="";

4

})



})
})()

})
17 changes: 17 additions & 0 deletions jobs/sparcsSuffolk2012.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
console.log("sparcsSuffolk2012.js")

// https://health.data.ny.gov/Health/Hospital-Inpatient-Discharges-SPARCS-De-Identified/u4ud-w55t

// Hospital Inpatient Discharges (SPARCS De-Identified): 2012
//The Statewide Planning and Research Cooperative System (SPARCS) Inpatient De-identified dataset
//contains discharge level detail on patient characteristics, diagnoses, treatments, services, and charges.
// This data contains basic record level detail regarding the discharge; however the data does not contain
// protected health information (PHI) under Health Insurance Portability and Accountability Act (HIPAA).
//The health information is not individually identifiable; all data elements considered identifiable have been redacted.
//For example, the direct identifiers regarding a date have the day and month portion of the date removed.
// A downloadable file with this data is available for ease of download at:
// https://health.data.ny.gov/Health/Hospital-Inpatient-Discharges-SPARCS-De-Identified/3m9u-ws8e.
//For more information check out: http://www.health.ny.gov/statistics/sparcs/ or go to the “About” tab.


// openHealth.sodaAll("https://health.data.ny.gov/resource/u4ud-w55t.json?hospital_county=Suffolk",false,function(x){y=x;console.log("done")}
2 changes: 1 addition & 1 deletion jobs/suffolk.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ console.log("suffolk.js :-)")
// for a quick fix http://leafletjs.com/ definetely worth a look
// ["http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.js","http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.css"]

openHealth.getScript(["//cdnjs.cloudflare.com/ajax/libs/d3/3.4.11/d3.min.js","https://www.google.com/jsapi","//square.github.io/crossfilter/crossfilter.v1.min.js","//dc-js.github.io/dc.js/js/dc.js","//dc-js.github.io/dc.js/css/dc.css","http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.js","http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.css"],function(){ // after satisfying d3 dependency
openHealth.getScript(["//cdnjs.cloudflare.com/ajax/libs/d3/3.4.11/d3.min.js","https://www.google.com/jsapi","//square.github.io/crossfilter/crossfilter.v1.min.js","//dc-js.github.io/dc.js/js/dc.js","//dc-js.github.io/dc.js/css/dc.css"],function(){ // after satisfying d3 dependency
// after dependencies satisfied
(function(){
var divJob=document.getElementById('openHealthJob');
Expand Down
14 changes: 14 additions & 0 deletions openHealth.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,20 @@ this.sodaAll=function(url,q,fun,xx,fun0){ // version of soda2 that keeps reading
return this.soda2(url,q,moreFun)
}

this.sodas=function(urls,q,fun,xx){ // version of sodaAll with multiple urls, for example, to load from a list of zip codes
console.log(urls[0]);
//var urlsi = urls;
if(!xx){xx=[]}
if(urls.length>0){ // keep going
var funLater=function(x){
openHealth.sodas(urls.slice(1),q,fun,x)
}
this.sodaAll(urls[0],q,funLater,xx)
}else{
fun(xx);
}
}

this.docs2tab=function(docs){ // convert array of docs into table
var F = Object.getOwnPropertyNames(docs[0]);
var m = F.length; // number of fields
Expand Down

0 comments on commit 401c08b

Please sign in to comment.