-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjavascript.js
More file actions
101 lines (90 loc) · 2.98 KB
/
javascript.js
File metadata and controls
101 lines (90 loc) · 2.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
function myMap() {
var mapCanvas = document.getElementById("map");
var mapOptions = {
center: new google.maps.LatLng(51.5, -0.2),
zoom: 10
};
var map = new google.maps.Map(mapCanvas, mapOptions);
}
function myFunction(arr) {
var npi [arr.results.length];
for (var i = 0; i < arr.results.length; i++) {
npi[i] = arr.results[i].number;
}
return npi;
}
function getLocation(){
var xmlhttp = new XMLHttpRequest();
var npiregistryUrl = "https://npiregistry.cms.hhs.gov/api?city=";
var tail = "pretty=true";
var npiList;
var city = document.getElementById('autocomplete'); // picked from search box;
var cityName = city.split(',');
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var myArr = jQuery.parseJSON(JSON.stringify(this.responseText));
npiList = myFunction(myArr);
return npiList;
}
};
xmlhttp.open("GET", npiregistryUrl +cityName[1]+ tail, true);
xmlhttp.send();
}
function generateTable(doctorData){
var body = document.getElementsByTagName('body')[0];
var tbl = document.createElement("table");
var tblBody = document.createElement("tbody");
// creating all cells
for (var i = 0; i < doctorData.length; i++) {
// creates a table row
var row = document.createElement("tr");
for (var j = 0; j < 6; j++) {
// Create a <td> element and a text node, make the text
// node the contents of the <td>, and put the <td> at
// the end of the table row
var cell = document.createElement("td");
var cellText = document.createTextNode(doctor[i][j]);
cell.appendChild(cellText);
row.appendChild(cell);
}
// add the row to the end of the table body
tblBody.appendChild(row);
}
// put the <tbody> in the <table>
tbl.appendChild(tblBody);
// appends <table> into <body>
body.appendChild(tbl);
// sets the border attribute of tbl to 2;
tbl.setAttribute("border", "2");
}
function getDoctorDetails(){
var npiList = getLocation();
//call to get Doctor Data
var doctorData;
var jasonObj;
var doctor;
for (var i =0;i<npiList.length;i++){
$.ajax({
type : "GET",
url : "https://api.propublica.org/doctors/"+npiList[i],
beforeSend: function(xhr){xhr.setRequestHeader('Authorization', 'P5hMshbs131RBxA2BfpXa4B3h2HhEGuN2PCQXSed');},
success : function(result) {
alert("success",result) ;
jsonObj = result;
},
error : function(result) {
//handle the error
alert("error", result);
}
});
alert();
doctor=jQuery.parseJSON(JSON.stringify(result));
doctorData[i][0]=doctor.provider_first_name;
doctorData[i][1]=doctor.provider_last_name_legal_name;
doctorData[i][2]=doctor.provider_business_practice_location_address_telephone_number;
doctorData[i][3]=doctor.provider_first_line_business_practice_location_address;
doctorData[i][4]=doctor.provider_business_practice_location_address_postal_code;
doctorData[i][5]=doctor.average_number_of_services;
}
createTable(doctorData);
}