Skip to content

Commit

Permalink
starting NY DSRIP job
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasalmeida committed Sep 8, 2014
1 parent d6df14a commit e260219
Show file tree
Hide file tree
Showing 2 changed files with 210 additions and 22 deletions.
119 changes: 119 additions & 0 deletions jobs/dsrip.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
// https://www.health.ny.gov/health_care/medicaid/redesign/dsrip_performance_data/
// Generic Dashboar with real-time analytics of DSRIP data sources
// we'll use this exercise to advance the analytics environment

openHealth.getScript("https://cdnjs.cloudflare.com/ajax/libs/d3/3.4.11/d3.min.js",function(){ // after satisfying d3 dependency

dsrip=(function(){
var y={ // dsrip object returned at the end
dt:{},
}
//prepare stout
var println = openHealth.log;
var divLog = openHealth.createLog(); // creates div for html printout
var divD3 = document.createElement('div');divD3.id="openHealthD3";
document.getElementById("openHealth").appendChild(divD3);
println('<h4 style="color:blue">DSRIP dashboard<h4>');
println("Let's query all [SODA](http://dev.socrata.com/consumers/getting-started.html) data sources listed by [DSRIP](https://www.health.ny.gov/health_care/medicaid/redesign/dsrip_performance_data/) and see what we get.");
//list DSRIP data sources
var D = Object.getOwnPropertyNames(openHealth.sodaData);
var j=0;
for(var i=D.length-1;i>=0;i--){
if(!D[i].match('DSRIP')){
D.splice(i,1);
} else {
var Lid = String.fromCharCode(65+j);
println('<button style="color:navy" onclick="dsrip.dataButton(this)">'+Lid+'</button> ['+D[i]+']('+openHealth.sodaData[D[i]]+')');
y.dt[Lid]={
url:D[i],
selected:false
}
j++;
}
}

y.dataButton=function(bt){
var dt = dsrip.dt[bt.textContent];
if(dt.bt){dt.bt = bt}; // button just pressed
if(!dt.selected){dt.selected=true}else{dt.selected=false} // switch
if(dt.selected){ // data selected for processing?
bt.style.color="red";
bt.style.backgroundColor="yellow";
var fun = function (x){
dt.attr=Object.getOwnPropertyNames(x[0]); // attributes
dsrip.updateDash(bt.textContent); // update D3 forced graph dashboad
}
openHealth.soda2(dt.url,{limit:1},fun)
} else {
bt.style.color="green"
bt.style.backgroundColor="CCFF99";
}
}

y.updateDash=function(id){
var dt = dsrip.dt[id];
dsrip.graph={
nodes:[{name:id,group:1}],
links:[]
}
// add attributes and links
dt.attr.forEach(function(a,i){
dsrip.graph.nodes.push({name:a,group:2})
dsrip.graph.links.push({"source":0,"target":i+1,"value":1})
})
graph=dsrip.graph;
4
var width = 960,height = 500;
var color = d3.scale.category20();
var force = d3.layout.force()
.charge(-120)
.linkDistance(30)
.size([width, height]);
var svg = d3.select(document.getElementById("openHealthD3")).append("svg")
.attr("width", width)
.attr("height", height)
force
.nodes(graph.nodes)
.links(graph.links)
.start();

var link = svg.selectAll(".link")
.data(graph.links)
.enter().append("line")
.attr("class", "link")
.style("stroke-width", function(d) { return Math.sqrt(d.value); });

var node = svg.selectAll(".node")
.data(graph.nodes)
.enter().append("circle")
.attr("class", "node")
.attr("r", 5)
.style("fill", function(d) { return color(d.group); })
.call(force.drag);

node.append("title")
.text(function(d) { return d.name; });

force.on("tick", function() {
link.attr("x1", function(d) { return d.source.x; })
.attr("y1", function(d) { return d.source.y; })
.attr("x2", function(d) { return d.target.x; })
.attr("y2", function(d) { return d.target.y; });

node.attr("cx", function(d) { return d.x; })
.attr("cy", function(d) { return d.y; });
});

jQuery('.node').css('stroke','#fff')
jQuery('.node').css('stroke-width','1.5px')
jQuery('.link').css('stroke','#999')
jQuery('.link').css('stroke','.6')

4
}
4

return y
})();

});
113 changes: 91 additions & 22 deletions openHealth.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,27 +35,53 @@ this.getJSON=function(url,fun){
this.xhr(url,function(x){fun(JSON.parse(x.target.responseText))});
}

this.sodaData={ // some reference SODA data links
/*
Jonas,
https://www.health.ny.gov/health_care/medicaid/redesign/dsrip_performance_data/
The CSV format can be downloaded:
https://health.data.ny.gov/Health/Medicaid-Chronic-Conditions-Inpatient-Admissions-a/2yck-xisk
For each zip and year there should be two rows. You can add these rows together as they are two distinct sets of people. The Medicaid dual eligible with Medicare (usually over 65) and the straight Medicaid Members.
Janos
*/
this.sodaData={ // some reference SODA data links
"NY Medicare Inpatient":"http://health.data.ny.gov/resource/2yck-xisk.json",

// DSRIP NY
// Hospital Inpatient Prevention Quality Indicators
"NY DSRIP Hospital Inpatient Prevention Quality Indicators by Zip Code":"http://health.data.ny.gov/resource/5q8c-d6xq.json",
"NY DSRIP Hospital Inpatient Prevention Quality Indicators by County":"http://health.data.ny.gov/resource/iqp6-vdi4.json",
"NY DSRIP Medicaid Prevention Quality Indicators for Adult Hospital Discharges by Patient Zip Code: Beginning 2011":"http://health.data.ny.gov/resource/izyt-3msa.json",
"NY DSRIP Medicaid Inpatient Prevention Quality Indicators for Adult Discharges by Patient County: Beginning 2011":"http://health.data.ny.gov/resource/6kjt-7svn.json",
"NY DSRIP Medicaid Beneficiaries, Inpatient Admissions, and Emergency Room Visits by Zip Code: Beginning 2012":"http://health.data.ny.gov/resource/m2wt-pje4.json",
"NY DSRIP Medicaid Chronic Conditions, Inpatient Admissions and Emergency Room Visits by County: Beginning 2012":"http://health.data.ny.gov/resource/wybq-m39t.json",
"NY DSRIP Medicaid Chronic Conditions, Inpatient Admissions and Emergency Room Visits by Zip Code: Beginning 2012":"http://health.data.ny.gov/resource/2yck-xisk.json",
"NY DSRIP Medicaid Hospital Inpatient Potentially Preventable Readmission Rates by Hospital: Beginning 2011":"http://health.data.ny.gov/resource/ckvf-rbyn.json",
"NY DSRIP Medicaid Program Enrollment by Month: Beginning 2009":"http://health.data.ny.gov/resource/m4hz-kzn3.json",
// Medicaid Inpatient Admissions and Emergency Room Visits
// "NY DSRIP Medicaid Beneficiaries, Inpatient Admissions, and Emergency Room Visits by Zip Code: Beginning 2012":"http://health.data.ny.gov/resource/m2wt-pje4.json",
// "NY DSRIP Medicaid Chronic Conditions, Inpatient Admissions and Emergency Room Visits by Zip Code: Beginning 2012":"http://health.data.ny.gov/resource/2yck-xisk.json",
//"NY DSRIP Medicaid Chronic Conditions, Inpatient Admissions and Emergency Room Visits by County: Beginning 2012":"http://health.data.ny.gov/resource/wybq-m39t.json",
"NY DSRIP Medicaid Potentially Preventable Emergency Visit (PPV) Rates by Patient County: Beginning 2011":"http://health.data.ny.gov/resource/cr7a-34ka.json",
"NY DSRIP Medicaid Potentially Preventable Emergency Visits (PPV) by Patient Zip Code: Beginning 2011":"http://health.data.ny.gov/resource/khkm-zkp2.json",
"NY DSRIP Medicaid Inpatient Prevention Quality Indicators (PDI) for Pediatric Discharges by Patient County: Beginning 2011":"http://health.data.ny.gov/resource/64yg-akce.json",
// MIS
// "NY DSRIP Discharge":"http://health.data.ny.gov/resource/ckvf-rbyn.json"
}
this.soda=function(url,q,fun){ // operate Socrata Open Data API (SODA), http://dev.socrata.com/docs/endpoints.html
if(!url.match("http[s]{0,1}://")){ // if url is not a URL then assume it is an entry of openHealth.sodaData
url=this.sodaData[url];
}
if(!q){q=""}
if(typeof(q)=="function"){fun=q;q=""}
if(!fun){fun=function(x){console.log(x)}}
this.getJSON(url,fun);
this.getJSON(url+q,fun);
return url
}
this.soda2=function(url,q,fun){ // operate SODA2 services
if(!url.match("http[s]{0,1}://")){ // if url is not a URL then assume it is an entry of openHealth.sodaData
url=this.sodaData[url];
}
if(typeof(q)=="object"){
var qq="?";
var F = Object.getOwnPropertyNames(q);
F.forEach(function(fi){
qq+='$'+fi+'='+q[fi]+'&';
})
q=qq.slice(0,qq.length-1); // remove the last &
}
return this.soda(url,q,fun)
}
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 Expand Up @@ -83,40 +109,83 @@ this.crossdoc2html=function(d){ // create table from cross-document
var cols = [""].concat(Object.getOwnPropertyNames(d[rows[0]]));
// header
html +='<tr>';
for(j=0;j<cols.length;j++){
html+='<th>'+cols[j]+'</th>';
}
for(j=0;j<cols.length;j++){html+='<th>'+cols[j]+'</th>'};
html +='</tr>';
// body
for(i=0;i<rows.length;i++){
html +='<tr>';
html +='<th>'+rows[i]+'</th>'; // row label
for(j=1;j<cols.length;j++){
html+='<td>'+d[rows[i]][cols[j]]+'</td>';
}
for(j=1;j<cols.length;j++){html+='<td>'+d[rows[i]][cols[j]]+'</td>'}
html +='</tr>';
}
html += '</table>';
return html;
}

this.markdown=function(x){ // basic markdown2html
x = x.replace(/\[([^\]]+)\]\(([^\)]+)\)/g,'<a href="$2" target=_blank>$1</a>'); // links
x = x.replace(/\n/g,'<br>'); // new lines
return x;
}

this.log=function(x){

var div = document.getElementById("openHealthLog")
if(div){
var p = document.createElement('p');
p.innerHTML=x.replace(/\n/g,'<br>');
p.innerHTML=openHealth.markdown(x);
div.appendChild(p);
} else{
console.log(x);
}
}

this.startJobMsgURL=function(){ // post URL of job into the div.id="msg" if it exists
var divMsg=document.getElementById("msg")
if(divMsg){
divMsg.innerHTML='Processing ... : <a href="'+window.location.search.slice(1)+'" target=_blank>'+window.location.search.slice(1)+'</a>';
divMsg.style.color="red";
}
}

this.endJobMsgURL=function(){ // post URL of job into the div.id="msg" if it exists
var divMsg=document.getElementById("msg")
if(divMsg){
divMsg.style.color="blue";
divMsg.innerHTML='Processing ... done : <a href="'+window.location.search.slice(1)+'" target=_blank>'+window.location.search.slice(1)+'</a>';
setTimeout(function(){
divMsg.innerHTML='Script (<a href="'+window.location.search.slice(1)+'" target=_blank>'+window.location.search.slice(1)+'</a>) processed <i>'+new Date(Date.now())+'</i>:';
divMsg.style.color="green";
},1000)

}
}

this.createLog=function(){ // create log div, if posiible, within an existing openHealth div
var div0 = document.getElementById("openHealth");
if(!div0){
div0 = document.createElement('div');
document.body.appendChild(div0);
}
var divLog = document.createElement('div');
divLog.id="openHealthLog";
div0.appendChild(divLog);
return divLog;
}


}

// initiatize openHealth object
openHealth.ini();

// run external analysis if called as a search argument
if(window.location.search.length>0){
openHealth.getScript(window.location.search.slice(1))
// run external analysis if called with a search argument
window.onload=function(){
if(window.location.search.length>0){
console.log("window loaded");
openHealth.startJobMsgURL();
openHealth.getScript(window.location.search.slice(1),function(){
openHealth.endJobMsgURL();
});

}
}

0 comments on commit e260219

Please sign in to comment.