4.3 Introduction to APIs and Requests
Key Concepts:
What is an API? (Application Programming Interface)
HTTP methods: GET, POST, PUT, DELETE
The structure of JSON responses
Library:
Example:
python
CopyEdit
import requests
response = requests.get("https://api.fda.gov/drug/event.json?limit=5")
data = response.json()
print(data["results"])
Practice:
4.4 Parsing and Using API Data
Key Concepts:
Navigating nested JSON structures
Converting JSON to a Pandas DataFrame
Handling errors and response codes
Example:
python
CopyEdit
import pandas as pd
results = data['results']
df = pd.json_normalize(results)
print(df[['patient.reaction.reactionmeddrapt', 'receivedate']])
Practice:
Convert a JSON API response to a clean DataFrame
Filter events that involve a specific drug or symptom
Save the final output to a CSV file for further analysis
4.5 Case Study: Automating a Healthcare Dashboard Pipeline
Scenario:
You are asked to automate a reporting pipeline that:
Downloads patient vitals from an API daily
Cleans and formats the data
Saves a summary to a shared folder
Sends a notification if abnormal readings are detected
Steps:
Call a mock API endpoint or use a static JSON
Filter for critical BP or glucose values
Generate summary stats and save to Excel
Send a notification (via print/log, or smtplib for email in advanced setups)
4.6 Summary and Assessment
Summary:
In this module, you have learned to:
Automate repetitive file and reporting tasks
Schedule and manage timed data workflows
Use Python to access and parse data from public APIs
Integrate automation and APIs into healthcare analytics projects
Assessment Tasks:
Write a script that reads patient files every morning, filters high-risk cases, and saves a summary
Use the openFDA or another public API to extract drug-related data and generate a trend report
Automate the entire workflow using schedule and simulate it with print/logs