|
| 1 | +# CaasIntegration API Documentation |
| 2 | + |
| 3 | +This documentation covers two Azure Functions services that handle CAAS (Clinical Audit & Analytics Service) file integration. |
| 4 | + |
| 5 | +--- |
| 6 | + |
| 7 | +## RetrieveMeshFile Service |
| 8 | + |
| 9 | +### RetrieveMeshFile Overview |
| 10 | + |
| 11 | +Service that polls the MESH mailbox for incoming CAAS files and transfers them to Azure Blob Storage for processing. |
| 12 | + |
| 13 | +**Function App URL:** <https://env-uks-retrieve-mesh-file.azurewebsites.net> |
| 14 | + |
| 15 | +### RetrieveMeshFile Functions |
| 16 | + |
| 17 | +#### 1. **Timer Trigger** `RetrieveMeshFile` |
| 18 | + |
| 19 | +**Type:** Background timer-triggered function (not an HTTP endpoint) |
| 20 | + |
| 21 | +**Purpose:** Polls the MESH mailbox every 5 minutes for new files and transfers them to Azure Blob Storage |
| 22 | + |
| 23 | +**Trigger Schedule:** `0 */5 * * * *` (every 5 minutes) |
| 24 | + |
| 25 | +**Behavior:** |
| 26 | + |
| 27 | +- Connects to MESH mailbox using configured credentials and certificates |
| 28 | +- Retrieves list of messages from mailbox |
| 29 | +- Downloads files from MESH |
| 30 | +- Uploads files to Azure Blob Storage container `inbound` |
| 31 | +- Files are named: `{MessageId}_-_{WorkflowID}.parquet` |
| 32 | +- Performs MESH handshake every 23 hours 54 minutes |
| 33 | +- Stores handshake state in blob storage (`config/MeshState.json`) |
| 34 | + |
| 35 | +**Configuration Requirements:** |
| 36 | + |
| 37 | +- `BSSMailBox` - MESH mailbox ID |
| 38 | +- `MeshPassword` - MESH mailbox password |
| 39 | +- `MeshSharedKey` - MESH shared key |
| 40 | +- `MeshApiBaseUrl` - MESH API endpoint |
| 41 | +- `caasfolder_STORAGE` - Blob storage connection string |
| 42 | +- Certificate authentication (from Key Vault or local file) |
| 43 | + |
| 44 | +**Error Handling:** |
| 45 | + |
| 46 | +- Logs errors if file transfer fails |
| 47 | +- Does not throw exceptions (continues on next timer trigger) |
| 48 | + |
| 49 | +**Location:** RetrieveMeshFile.cs:43 |
| 50 | + |
| 51 | +--- |
| 52 | + |
| 53 | +## ReceiveCaasFile Service |
| 54 | + |
| 55 | +### ReceiveCaasFile Overview |
| 56 | + |
| 57 | +Service that processes CAAS Parquet files from blob storage and loads participant data into the system. |
| 58 | + |
| 59 | +**Function App URL:** <https://env-uks-receive-caas-file.azurewebsites.net> |
| 60 | + |
| 61 | +### ReceiveCaasFile Functions |
| 62 | + |
| 63 | +#### 1. **Blob Trigger** `ReceiveCaasFile` |
| 64 | + |
| 65 | +**Type:** Background blob-triggered function (not an HTTP endpoint) |
| 66 | + |
| 67 | +**Purpose:** Processes Parquet files containing participant data when they arrive in blob storage |
| 68 | + |
| 69 | +**Trigger:** Blob creation in container `inbound` with connection `caasfolder_STORAGE` |
| 70 | + |
| 71 | +**Blob Path Pattern:** `inbound/{name}` |
| 72 | + |
| 73 | +**File Format:** Parquet file with participant records |
| 74 | + |
| 75 | +**File Naming Convention:** |
| 76 | + |
| 77 | +- Must contain screening workflow ID |
| 78 | +- Format parsed by `FileNameParser` |
| 79 | +- Example: `{MessageId}_-_{WorkflowID}.parquet` |
| 80 | + |
| 81 | +**Processing Flow:** |
| 82 | + |
| 83 | +1. Validates file name format |
| 84 | +2. Extracts screening workflow ID from filename |
| 85 | +3. Retrieves screening service configuration from database |
| 86 | +4. Downloads Parquet file from blob to temp storage |
| 87 | +5. Reads Parquet file row groups sequentially |
| 88 | +6. Processes records in configurable batch sizes (default: 5000) |
| 89 | +7. Batches are processed in parallel (up to processor count) |
| 90 | +8. Each batch calls demographic processing functions |
| 91 | +9. Cleans up temp files after processing |
| 92 | + |
| 93 | +**Batch Processing:** |
| 94 | + |
| 95 | +- Configurable batch size via `BatchSize` configuration |
| 96 | +- Recommended: 5000 records per batch for optimal performance |
| 97 | +- Parallel processing: `MaxDegreeOfParallelism = Environment.ProcessorCount` |
| 98 | + |
| 99 | +**Error Handling:** |
| 100 | + |
| 101 | +- Invalid file names throw `ArgumentException` |
| 102 | +- Unknown screening workflow IDs throw `ArgumentException` |
| 103 | +- System exceptions are logged to exception handler |
| 104 | +- Failed files are moved to poison blob container |
| 105 | +- Temp files always cleaned up in finally block |
| 106 | + |
| 107 | +**Configuration Requirements:** |
| 108 | + |
| 109 | +- `BatchSize` - Number of records per batch (recommended: 5000) |
| 110 | +- `caasfolder_STORAGE` - Blob storage connection string |
| 111 | +- `inboundBlobName` - Name of inbound blob container |
| 112 | +- `DemographicDataServiceURL` - Demographic data service URL |
| 113 | +- `ScreeningLkpDataServiceURL` - Screening lookup data service URL |
| 114 | +- `ServiceBusConnectionString_client_internal` - Service Bus connection |
| 115 | + |
| 116 | +**Dependencies:** |
| 117 | + |
| 118 | +- Database connection for screening lookup |
| 119 | +- Demographic data service |
| 120 | +- Service Bus for queuing |
| 121 | +- Blob storage for file operations |
| 122 | + |
| 123 | +**Location:** receiveCaasFile.cs:42 |
| 124 | + |
| 125 | +--- |
| 126 | + |
| 127 | +## Architecture Flow |
| 128 | + |
| 129 | +### Complete CAAS File Processing Flow |
| 130 | + |
| 131 | +1. **MESH Polling (RetrieveMeshFile)** |
| 132 | + - Timer triggers every 5 minutes |
| 133 | + - Checks MESH mailbox for new messages |
| 134 | + - Downloads Parquet files from MESH |
| 135 | + - Uploads to blob storage `inbound` container |
| 136 | + |
| 137 | +2. **File Processing (receiveCaasFile)** |
| 138 | + - Blob trigger activates on new file in `inbound` |
| 139 | + - Validates file name and extracts screening workflow |
| 140 | + - Downloads file to temp storage |
| 141 | + - Reads Parquet file row groups |
| 142 | + - Splits into configurable batches (5000 records) |
| 143 | + - Processes batches in parallel |
| 144 | + - Sends to demographic processing |
| 145 | + - Cleans up temp files |
| 146 | + |
| 147 | +3. **Error Handling** |
| 148 | + - Invalid files moved to poison container |
| 149 | + - Errors logged to exception handler |
| 150 | + - System continues processing next files |
| 151 | + |
| 152 | +--- |
| 153 | + |
| 154 | +## Monitoring & Observability |
| 155 | + |
| 156 | +### Logging |
| 157 | + |
| 158 | +Both services use structured logging with Application Insights integration: |
| 159 | + |
| 160 | +- File processing progress |
| 161 | +- MESH handshake timing |
| 162 | +- Error details |
| 163 | +- Performance metrics |
| 164 | + |
| 165 | +--- |
| 166 | + |
| 167 | +## Configuration Summary |
| 168 | + |
| 169 | +### RetrieveMeshFile Configuration |
| 170 | + |
| 171 | +```json |
| 172 | +{ |
| 173 | + "BSSMailBox": "MESH mailbox ID", |
| 174 | + "MeshPassword": "MESH password", |
| 175 | + "MeshSharedKey": "MESH shared key", |
| 176 | + "MeshApiBaseUrl": "https://mesh-api-url", |
| 177 | + "caasfolder_STORAGE": "blob connection string", |
| 178 | + "KeyVaultConnectionString": "https://keyvault-url", |
| 179 | + "MeshKeyName": "certificate name", |
| 180 | + "MeshCertName": "MESH CA cert name", |
| 181 | + "BypassServerCertificateValidation": false |
| 182 | +} |
| 183 | +``` |
| 184 | + |
| 185 | +### ReceiveCaasFile Configuration |
| 186 | + |
| 187 | +```json |
| 188 | +{ |
| 189 | + "BatchSize": 5000, |
| 190 | + "caasfolder_STORAGE": "blob connection string", |
| 191 | + "inboundBlobName": "inbound", |
| 192 | + "DemographicDataServiceURL": "https://demographic-service-url", |
| 193 | + "ScreeningLkpDataServiceURL": "https://screening-lookup-url", |
| 194 | + "ServiceBusConnectionString_client_internal": "service bus connection" |
| 195 | +} |
| 196 | +``` |
0 commit comments