From 0279c8955ab25fa8aa89743da13b71e3d7c6e1d4 Mon Sep 17 00:00:00 2001 From: Jonas Almeida Date: Thu, 22 Jan 2015 21:02:30 -0500 Subject: [PATCH] npi.js --- jobs/npi.js | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++ openHealth.js | 30 +++++++++++++++++++++++---- 2 files changed, 83 insertions(+), 4 deletions(-) create mode 100644 jobs/npi.js diff --git a/jobs/npi.js b/jobs/npi.js new file mode 100644 index 0000000..433624f --- /dev/null +++ b/jobs/npi.js @@ -0,0 +1,57 @@ +console.log("npi.js job") + +getNpiInfoJob = function(){ + // it all happens here + if(document.getElementById('openHealthJob')){ + getNpiInfoJob.buildUI('openHealthJob') + } + +} + +getNpiInfoJob.buildUI=function(div0){ + if(typeof(div0)=='string'){div0=document.getElementById(div0)} + div0.innerHTML='NPI: source
... click or press enter ...
'; + var bt = document.getElementById('inputNpiButton') + bt.onclick=function(){ + openHealth.npi(inputNpi.value,function(x){ + var d = document.getElementById("getNpiInfoJobResults") + var n = x.length + if(n>0){ + x=openHealth.docs2tab(x) + // sort attributes and remove + var xx={} + Object.getOwnPropertyNames(x).forEach(function(a){ + console.log(a) + xx[a]={}; // to make sure it not be an Array + x[a].map(function(ai,i){ + xx[a][i]=ai + }) + }) + x=xx; + d.innerHTML=''+n+' entries were found with NPI '+inputNpi.value+':' + d.appendChild(openHealth.crossdoc2html(x,"NPI "+inputNpi.value+".csv",true)) + } else { + d.innerHTML='no entries were found with NPI '+inputNpi.value+':' + } + + }) + } + + + + 4 +} + + +if(!window.openHealth){ + var s = document.createElement('script') + s.src="https://mathbiol.github.io/openHealth/openHealth.js" + s.onload=function(){ + getNpiInfoJob() + } +}else{ + getNpiInfoJob() +} + + + diff --git a/openHealth.js b/openHealth.js index 8b96282..1353b45 100644 --- a/openHealth.js +++ b/openHealth.js @@ -190,6 +190,18 @@ this.sodas=function(urls,q,fun,xx){ // version of sodaAll with multiple urls, fo } } +this.object2query=function(q){ + 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 q +} + this.txt2docs=function(txt){ if (txt[0]=='['){ // txt is json var docs = JSON.parse(txt); @@ -450,10 +462,11 @@ this.crossdoc2csv=function(d,title){ return csv } -this.crossdoc2html=function(d,title){ // create table from cross-document +this.crossdoc2html=function(d,title,sort){ // create table from cross-document if(!title){title=Date()+'.csv'} var html = ''; var rows = Object.getOwnPropertyNames(d); + if(sort){rows.sort()} var cols = [""].concat(Object.getOwnPropertyNames(d[rows[0]])); // header html +=''; @@ -487,9 +500,6 @@ this.crossdoc2html=function(d,title){ // create table from cross-document return div; } - - - this.markdown=function(x){ // basic markdown2html x = x.replace(/\[([^\]]+)\]\(([^\)]+)\)/g,'$1'); // links x = x.replace(/\n/g,'
'); // new lines @@ -543,6 +553,18 @@ this.endJobMsgURL=function(){ // post URL of job into the div.id="msg" if it exi } } +this.npi=function(q,fun){ // retrieve data on a National Provider Identifier from CMS + if(!q){q=1548485139} // default example + if(!fun){fun = function(x){console.log(x)}} + var url = 'https://data.medicare.gov/resource/s63f-csi6.json?'; + // basic filtering + if(typeof(q)=="number"){q=""+q} // if number convert to string + q=openHealth.object2query(q) // if it is an object + if(q.match(/^[\d]+$/)){q='npi='+q} // if the query is an integer then assume it is the NPI + this.soda(url,q,fun) + return this +} + }