Skip to main content

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-token to verify authentication

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 authentication
  • fhir.resources: FHIR data handling
  • django: 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 --noreload flag when debugging
  • Set DEBUG=True in 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:

SKUvCPUsMemoryRecommended Use
B111.75GBDevelopment
S112GBSmall workloads
P2V328GBProduction

Post-Deployment Steps:

  1. 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>
  1. Set environment variables:
az webapp config appsettings set \
--settings FHIR_SERVER="https://<workspace-name>.fhir.azurehealthcareapis.com"

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

Next Steps