-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 3c29927
Showing
2 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
cachetools==4.2.2 | ||
certifi==2021.5.30 | ||
cffi==1.14.6 | ||
chardet==4.0.0 | ||
google-api-core==1.31.0 | ||
google-auth==1.32.1 | ||
google-cloud-bigquery==2.20.0 | ||
google-cloud-core==1.7.1 | ||
google-crc32c==1.1.2 | ||
google-resumable-media==1.3.1 | ||
googleapis-common-protos==1.53.0 | ||
grpcio==1.38.1 | ||
idna==2.10 | ||
packaging==21.0 | ||
proto-plus==1.19.0 | ||
protobuf==3.17.3 | ||
pyasn1==0.4.8 | ||
pyasn1-modules==0.2.8 | ||
pycparser==2.20 | ||
pyparsing==2.4.7 | ||
pytz==2021.1 | ||
requests==2.25.1 | ||
rsa==4.7.2 | ||
six==1.16.0 | ||
urllib3==1.26.6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
from google.cloud import bigquery | ||
from datetime import date | ||
import json | ||
|
||
|
||
##fill in path to SA JSON key | ||
my_json_key = "" | ||
|
||
def healthcare_prediction(request): | ||
client = bigquery.Client.from_service_account_json( | ||
my_json_key) | ||
request_json = request.get_json(silent=True) | ||
print("request_json: ", request_json) | ||
# check to make sure all params are filled | ||
patient_id = request_json["data"]["patient_id"] | ||
# first_name = request_json["form_params"]["First Name"] | ||
# last_name = request_json["form_params"]["Last Name"] | ||
age_tier = request_json["form_params"]["Age Tier"] | ||
gender = request_json["form_params"]["Gender"] | ||
race = request_json["form_params"]["Race"] | ||
wellness_screened = request_json["form_params"]["Wellness Screened in the Past Year"] | ||
# city = request_json["form_params"]["City"] | ||
state = request_json["form_params"]["State"] | ||
encounter_type = request_json["form_params"]["Encounter Type"] | ||
procedure_type = request_json["form_params"]["Procedure Type"] | ||
practictioner_investigator = request_json["form_params"]["Practictioner Examiner"] | ||
length_of_stay = request_json["form_params"]["Length of Stay"] | ||
admission_date = request_json["form_params"]["Admission Date"] | ||
discharge_date = request_json["form_params"]["Discharge Date"] | ||
last_discharge_date = request_json["form_params"]["Last Discharge Date"] | ||
curr_date = date.today() | ||
# insert record into sql table | ||
sql_string = f""" | ||
INSERT INTO | ||
looker-private-demo.healthcare_demo_live.new_patient_visits( | ||
patient_id, | ||
patient_name, | ||
patient_age_tier__sort_, | ||
patient_age_tier, | ||
patient_us_core_ethnicity, | ||
patient_gender, | ||
patient_us_core_race, | ||
patient_is_wellness_screened_in_the_past_year, | ||
patient_birth_place__city, | ||
patient_birth_place__state, | ||
encounter_type_coding_display, | ||
observation__category__coding_display, | ||
practitioner_investigator, | ||
encounter_length_of_stay, | ||
admission_date, | ||
discharge_date, | ||
last_discharge_date | ||
) | ||
VALUES ( | ||
'0fd0ae11-7a98-4b18-8246-b41fd3cbd38a', | ||
'Chong Torp', | ||
"4", | ||
'{age_tier}', | ||
"White", | ||
'{gender}', | ||
'{race}', | ||
'{wellness_screened}', | ||
'Beverly', | ||
'{state}', | ||
'{encounter_type}', | ||
'{procedure_type}', | ||
'{practictioner_investigator}', | ||
CAST('{length_of_stay}' as INT64), | ||
DATE('{curr_date}), | ||
DATE('{discharge_date}'), | ||
DATE('{last_discharge_date}') | ||
) | ||
""" | ||
query_job = client.query(sql_string) | ||
results = query_job.result() | ||
|
||
return (json.dumps({ | ||
"looker": { | ||
"success": True, | ||
"refresh_query": True | ||
} | ||
}), 200) |