Set-up Medbackend
Prerequisites
1. Azure CLI Installation
Official Documentation: Install Azure CLI
# Authenticate with Azure
az login
- Why needed: Required for managing Azure resources and deployments
- Troubleshooting:
- If experiencing permission issues, run
az account get-access-tokento verify authentication
- If experiencing permission issues, run
2. Azure Health Data Services Workspace
Setup Guide: Create Workspace
- Required components:
- FHIR Service (R4 version)
- DICOM Service (if processing imaging data) (to be defined)
- IoT Connector (if ingesting device data)
- Important: Ensure your account has "Health Data Services Contributor" role
3. Azure AD B2C Instance
Configuration Reference: B2C Setup Guide
- Required configurations:
- User flows for authentication
- Application registration with proper redirect URIs
- Token encryption keys (preferably using Azure Key Vault)
Local Development Setup
1. Dependency Installation
Best Practice: Use a virtual environment
python -m venv .venv
source .venv/bin/activate # Linux/MacOS
.\.venv\Scripts\activate # Windows
pip install -r requirements.txt
Key Dependencies:
azure-identity: For Azure authenticationfhir.resources: FHIR data handlingdjango: Web framework (v4.2+ recommended)
2. Azure Credential Configuration
Configure the settings.json file:
3. FHIR Definition Scraping
Purpose: Generates FHIR resource models from specification
# Run with verbose output
python scripts/run_scrapers.py
# Expected output:
✔ Generated 142 FHIR resource models in ./fhir_models/
Troubleshooting:
- Ensure network access to
hl7.org(firewall may block requests) - Verify Python version = 3.11
4. Local Server Execution
# Run with development settings
python manage.py runserver
Development Tips:
- Use
--noreloadflag when debugging - Set
DEBUG=Truein local settings for detailed error pages - Consider using Azure Storage Emulator for local blob storage
Deployment
1. App Service Deployment
Command Breakdown:
az webapp up \
--name <app-name> \
--resource-group <resource-group> \
--runtime PYTHON:3.11 \
--sku B1 \
--os-type Linux \
--location westus2
SKU Options:
| SKU | vCPUs | Memory | Recommended Use |
|---|---|---|---|
| B1 | 1 | 1.75GB | Development |
| S1 | 1 | 2GB | Small workloads |
| P2V3 | 2 | 8GB | Production |
Post-Deployment Steps:
- Configure authentication:
az webapp auth update \
--resource-group <rg-name> \
--name <app-name> \
--enabled true \
--action LoginWithAzureActiveDirectory \
--aad-allowed-token-audiences https://<app-name>.azurewebsites.net \
--aad-client-id <client-id> \
--aad-token-issuer-url https://login.microsoftonline.com/<tenant-id>
- Set environment variables:
az webapp config appsettings set \
--settings FHIR_SERVER="https://<workspace-name>.fhir.azurehealthcareapis.com"
2. Continuous Deployment (Recommended)
GitHub Actions Example (.github/workflows/deploy.yml):
name: Deploy to Azure
on: [push]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- run: az webapp up --resource-group MyResourceGroup --name MyApp