-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNrdmWs.py
More file actions
201 lines (159 loc) · 9.67 KB
/
NrdmWs.py
File metadata and controls
201 lines (159 loc) · 9.67 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
import datetime
import sys
from requests import Session
from requests.auth import HTTPBasicAuth # or HTTPDigestAuth, or OAuth1, etc.
from zeep import Client
from zeep.transports import Transport
# NRDM WebService Python Client API
# Utilizes NRDM SOAP Webservice
# Jeremy Espino MD 2020/03/25
# juest4@pitt.edu
class NrdmWs:
username = ""
password = ""
endpoint = "http://localhost:8888/nrdm-jax-ws?wsdl"
category = {'Antifever adult': 1,
'Antifever pediatric': 2,
'Bronchial remedies': 3,
'Chest rubs': 4,
'Cold relief adult liquid': 5,
'Cold relief adult tablet': 6,
'Cold relief pediatric liquid': 7,
'Cold relief pediatric tablet': 8,
'Cough syrup adult liquid': 9,
'Cough adult tablet': 10,
'Cough syrup pediatric liquid': 11,
'Diarrhea remedies': 12,
'Electrolytes pediatric': 13,
'Hydrocortisones': 14,
'Nasal product internal': 15,
'Thermometer adult': 16,
'Thermometer pediatric': 17,
'Throat Lozenges': 18,
'Baby/Child Electrolytes': 19,
'Cough/Cold': 20,
'Internal Analgesics': 21,
'Stomach Remedies': 22,
'Thermometers': 23}
region_type = {'state': 1, 'county': 2, 'zipcode': 3}
def __init__(self, username, password, endpoint):
if endpoint is not None:
self.endpoint = endpoint
self.username = username
self.password = password
self.client = None
self.initClient()
def initClient(self):
session = Session()
session.auth = HTTPBasicAuth(self.username, self.password)
self.client = Client(self.endpoint, transport=Transport(session=session))
def isAlive(self):
return self.client.service.isAlive()
def getZipLevelCompletion(self, zipcode):
return self.client.service.getZipLevelCompletion(zipcode)
def getCountyLevelCompletion(self, county_fips):
return self.client.service.getCountyLevelCompletion(county_fips)
def getStateLevelCompletion(self, state_abbrev):
return self.client.service.getStateLevelCompletion(state_abbrev)
def getZipLevelCount(self, startDate, endDate, zipcode, category, normalize):
return self.client.service.getZipLevelCount(startDate, endDate, zipcode, category, normalize, self.username)
def getCountyLevelCount(self, startDate, endDate, county_fips, category, normalize):
return self.client.service.getCountyLevelCount(startDate, endDate, county_fips, category,
normalize, self.username)
def getJurisdictionLevelCount(self, startDate, endDate, jurisdiction, category, normalize):
return self.client.service.getJurisdictionLevelCount(startDate, endDate, jurisdiction, category,
normalize, self.username)
def getStateLevelCount(self, startDate, endDate, state_abbrev, category, normalize):
return self.client.service.getStateLevelCount(startDate, endDate, state_abbrev, category, normalize,
self.username)
def getCountMultiRegions(self, startDate, endDate, regions, regionType, categories, normalize):
return self.client.service.getCountMultiRegions(startDate, endDate, regions, regionType, categories,
normalize, self.username)
def getZipcodeSeries(self, date, regionType, regionID, category, promotionOption):
return self.client.service.getZipcodeSeries(date, regionType, regionID, category, promotionOption,
self.username)
def getAlgorithmOutput(self, startDate, endDate, regions, regionType, categoryIDs):
return self.client.service.getAlgorithmOutput(startDate, endDate, regions, regionType, categoryIDs,
self.username)
def getZipcodesInCounty(self, countyFips):
return self.client.service.getZipcodesInCounty(countyFips)
def getZipcodesInState(self, stateAbbrev):
return self.client.service.getZipcodesInState(stateAbbrev);
def getFipsInState(self, stateAbbrev):
return self.client.service.getFipsInState(stateAbbrev)
def main():
if len(sys.argv) < 2:
print("Usage: NrdmWs.py <username> <password> [<endpoint>]")
exit()
username = sys.argv[1]
password = sys.argv[2]
endpoint = None
if len(sys.argv) == 4:
endpoint = sys.argv[3]
nrdmWs = NrdmWs(username, password, endpoint)
# use two letter state abbreviation for states
# use county fips for counties
# use zipcode for zipcodes
state_abbrev_to_test = "PA"
county_fips_to_test = "42001"
zipcode_to_test = "15228"
counties_fips_to_test = "42001,42003"
zipcodes_to_test = "15228,15206"
states_to_test = "PA,OH"
print("nrdmWs.isAlive()")
print(nrdmWs.isAlive())
print("nrdmWs.getStateLevelCompletion(state_abbrev_to_test)")
print(nrdmWs.getStateLevelCompletion(state_abbrev_to_test))
print("nrdmWs.getCountyLevelCompletion(county_fips_to_test)")
print(nrdmWs.getCountyLevelCompletion(county_fips_to_test))
print("nrdmWs.getZipLevelCompletion(zipcode_to_test)")
print(nrdmWs.getZipLevelCompletion(zipcode_to_test))
print(
"nrdmWs.getStateLevelCount(datetime.date(2020, 3, 1), datetime.date(2020, 3, 1), state_abbrev_to_test, nrdmWs.category['Cough/Cold'], False)")
print(nrdmWs.getStateLevelCount(datetime.date(2020, 3, 1), datetime.date(2020, 3, 1), state_abbrev_to_test,
nrdmWs.category['Cough/Cold'], False))
print(
"nrdmWs.getCountyLevelCount(datetime.date(2020, 3, 1), datetime.date(2020, 3, 1), county_fips_to_test, nrdmWs.category['Cough/Cold'], False)")
print(nrdmWs.getCountyLevelCount(datetime.date(2020, 3, 1), datetime.date(2020, 3, 1), county_fips_to_test,
nrdmWs.category['Cough/Cold'], False))
print(
"nrdmWs.getZipLevelCount(datetime.date(2020, 3, 1), datetime.date(2020, 3, 1), zipcode_to_test, nrdmWs.category['Cough/Cold'], False)")
print(nrdmWs.getZipLevelCount(datetime.date(2020, 3, 1), datetime.date(2020, 3, 1), zipcode_to_test,
nrdmWs.category['Cough/Cold'], False))
print(
"nrdmWs.getCountMultiRegions(datetime.date(2020, 3, 1), datetime.date(2020, 3, 1), zipcodes_to_test, nrdmWs.region_type['zipcode'], nrdmWs.category['Cough/Cold'], False)")
print(nrdmWs.getCountMultiRegions(datetime.date(2020, 3, 1), datetime.date(2020, 3, 1), zipcodes_to_test,
nrdmWs.region_type['zipcode'], nrdmWs.category['Cough/Cold'], False))
print(
"nrdmWs.getCountMultiRegions(datetime.date(2020, 3, 1), datetime.date(2020, 3, 1), counties_fips_to_test, nrdmWs.region_type['county'], nrdmWs.category['Cough/Cold'], False)")
print(nrdmWs.getCountMultiRegions(datetime.date(2020, 3, 1), datetime.date(2020, 3, 1), counties_fips_to_test,
nrdmWs.region_type['county'], nrdmWs.category['Cough/Cold'], False))
print(
"nrdmWs.getCountMultiRegions(datetime.date(2020, 3, 1), datetime.date(2020, 3, 1), states_to_test, nrdmWs.region_type['state'], str(nrdmWs.category['Cough/Cold']) + ',' + str(nrdmWs.category['Thermometer adult']), False)")
print(nrdmWs.getCountMultiRegions(datetime.date(2020, 3, 1), datetime.date(2020, 3, 1), states_to_test,
nrdmWs.region_type['state'], str(nrdmWs.category['Cough/Cold']) + ',' + str(
nrdmWs.category['Thermometer adult']), False))
print(
"nrdmWs.getZipcodeSeries(datetime.date(2020, 3, 1), county_fips_to_test, nrdmWs.region_type['county'], nrdmWs.category['Cough/Cold'], 'N')")
print(nrdmWs.getZipcodeSeries(datetime.date(2020, 3, 1), county_fips_to_test, nrdmWs.region_type['county'],
nrdmWs.category['Cough/Cold'], 'N'))
print(
"nrdmWs.getZipcodeSeries(datetime.date(2020, 3, 1), state_abbrev_to_test, nrdmWs.region_type['state'], nrdmWs.category['Cough/Cold'], 'N')")
print(nrdmWs.getZipcodeSeries(datetime.date(2020, 3, 1), state_abbrev_to_test, nrdmWs.region_type['state'],
nrdmWs.category['Cough/Cold'], 'N'))
print(
"nrdmWs.getAlgorithmOutput(datetime.date(2020, 3, 1), datetime.date(2020, 3, 1), county_fips_to_test, nrdmWs.region_type['county'], nrdmWs.category['Cough/Cold'])")
print(nrdmWs.getAlgorithmOutput(datetime.date(2020, 3, 1), datetime.date(2020, 3, 1), county_fips_to_test,
nrdmWs.region_type['county'], nrdmWs.category['Cough/Cold']))
print(
"nrdmWs.getAlgorithmOutput(datetime.date(2020, 3, 1), datetime.date(2020, 3, 1), county_fips_to_test, nrdmWs.region_type['county'], nrdmWs.category['Cough/Cold'])")
print(nrdmWs.getAlgorithmOutput(datetime.date(2020, 3, 1), datetime.date(2020, 3, 1), zipcode_to_test,
nrdmWs.region_type['zipcode'], nrdmWs.category['Cough/Cold']))
print("nrdmWs.getZipcodesInCounty(county_fips_to_test)")
print(nrdmWs.getZipcodesInCounty(county_fips_to_test))
print("nrdmWs.getZipcodesInState(state_abbrev_to_test)")
print(nrdmWs.getZipcodesInState(state_abbrev_to_test))
print("nrdmWs.getFipsInState(state_abbrev_to_test)")
print(nrdmWs.getFipsInState(state_abbrev_to_test))
if __name__ == '__main__':
main()