|
| 1 | +# API |
| 2 | + |
| 3 | +TORCH provides a FHIR REST API for extracting data based on the Clinical Resource Transfer Definition Language (CRTDL). |
| 4 | +It implements the FHIR [Asynchronous Bulk Data Request Pattern](http://hl7.org/fhir/R5/async-bulk.html). |
| 5 | + |
| 6 | +### Key Features of the API |
| 7 | + |
| 8 | +- **Asynchronous Requests**: Supports long-running data extraction tasks. |
| 9 | +- **FHIR Compliant**: Adheres to FHIR standards for resource representation. |
| 10 | +- **CRTDL Integration**: Uses CRTDL definitions to specify data extraction rules. |
| 11 | + |
| 12 | +### API Endpoints |
| 13 | + |
| 14 | +- **`/$extract-data`**: Initiates a data extraction job based on a CRTDL definition. |
| 15 | +- **`/status`**: Checks the status of an ongoing data extraction job. |
| 16 | +- **`/metadata`**: Provides metadata about the TORCH server and its capabilities. |
| 17 | + |
| 18 | +## TORCH REST API (based on FHIR Bulk Data Request) |
| 19 | + |
| 20 | +Torch implements the FHIR [Asynchronous Bulk Data Request Pattern][1]. |
| 21 | + |
| 22 | +### $extract-data |
| 23 | + |
| 24 | +The $extract-data endpoint implements the kick-off request in the Async Bulk Pattern. It receives a FHIR parameters |
| 25 | +resource with a **_crtdl_** parameter containing a |
| 26 | +valueBase64Binary [CRTDL](https://github.com/medizininformatik-initiative/clinical-resource-transfer-definition-language). |
| 27 | +All examples are with a torch configured with **`http://localhost:8080`**. |
| 28 | + |
| 29 | +```sh |
| 30 | +scripts/create-parameters.sh src/test/resources/CRTDL/CRTDL_observation.json | curl -s 'http://localhost:8080/fhir/$extract-data' -H "Content-Type: application/fhir+json" -d @- -v |
| 31 | +``` |
| 32 | + |
| 33 | +The Parameters resource created by `scripts/create-parameters.sh` look like this: |
| 34 | + |
| 35 | +``` |
| 36 | +{ |
| 37 | + "resourceType": "Parameters", |
| 38 | + "parameter": [ |
| 39 | + { |
| 40 | + "name": "crtdl", |
| 41 | + "valueBase64Binary": "<Base64 encoded CRTDL>" |
| 42 | + } |
| 43 | + ] |
| 44 | +} |
| 45 | +``` |
| 46 | + |
| 47 | +Optionally patient ids can be submitted for a known cohort, bypassing the cohort selection in the CRTDL: |
| 48 | + |
| 49 | +``` |
| 50 | +{ |
| 51 | + "resourceType": "Parameters", |
| 52 | + "parameter": [ |
| 53 | + { |
| 54 | + "name": "crtdl", |
| 55 | + "valueBase64Binary": "<Base64 encoded CRTDL>" |
| 56 | + }, |
| 57 | + { |
| 58 | + "name": "patient", |
| 59 | + "valueString": "<Patient Id 1>" |
| 60 | + }, |
| 61 | + { |
| 62 | + "name": "patient", |
| 63 | + "valueString": "<Patient Id 2>" |
| 64 | + } |
| 65 | + ] |
| 66 | +} |
| 67 | +``` |
| 68 | + |
| 69 | +#### Response - Error (e.g. unsupported search parameter) |
| 70 | + |
| 71 | +* HTTP Status Code of 4XX or 5XX |
| 72 | + |
| 73 | +#### Response - Success |
| 74 | + |
| 75 | +* HTTP Status Code of 202 Accepted |
| 76 | +* Content-Location header with the absolute URL of an endpoint for subsequent status requests (polling location) |
| 77 | + |
| 78 | +That location header can be used in the following status query: |
| 79 | +E.g. location:"/fhir/__status/1234" |
| 80 | + |
| 81 | +### Status Request |
| 82 | + |
| 83 | +Torch provides a Status Request Endpoint which can be called using the location from the extract Data Endpoint. |
| 84 | + |
| 85 | +```sh |
| 86 | +curl -s http://localhost:8080/fhir/__status/{location} |
| 87 | +``` |
| 88 | + |
| 89 | +#### Response - In-Progress |
| 90 | + |
| 91 | +* HTTP Status Code of 202 Accepted |
| 92 | + |
| 93 | +#### Response - Error |
| 94 | + |
| 95 | +* HTTP status code of 4XX or 5XX |
| 96 | +* Content-Type header of application/fhir+json |
| 97 | +* Operation Outcome with fatal issue |
| 98 | + |
| 99 | +#### Response - Complete |
| 100 | + |
| 101 | +* HTTP status of 200 OK |
| 102 | +* Content-Type header of application/fhir+json |
| 103 | +* A body containing a JSON file describing the file links to the batched transformation results |
| 104 | + |
| 105 | +```sh |
| 106 | +curl -s 'http://localhost:8080/fhir/$extract-data' -H "Content-Type: application/fhir+json" -d '<query>' |
| 107 | +``` |
| 108 | + |
| 109 | +the result is a looks something like this: |
| 110 | + |
| 111 | +```json |
| 112 | +{ |
| 113 | + "requiresAccessToken": false, |
| 114 | + "output": [ |
| 115 | + { |
| 116 | + "type": "Bundle", |
| 117 | + "url": "http://localhost:8080/da4a1c56-f5d9-468c-b57a-b8186ea4fea8/6c88f0ff-0e9a-4cf7-b3c9-044c2e844cfc.ndjson" |
| 118 | + }, |
| 119 | + { |
| 120 | + "type": "Bundle", |
| 121 | + "url": "http://localhost:8080/da4a1c56-f5d9-468c-b57a-b8186ea4fea8/a4dd907c-4d98-4461-9d4c-02d62fc5a88a.ndjson" |
| 122 | + }, |
| 123 | + { |
| 124 | + "type": "Bundle", |
| 125 | + "url": "http://localhost:8080/da4a1c56-f5d9-468c-b57a-b8186ea4fea8/f33634bd-d51b-463c-a956-93409d96935f.ndjson" |
| 126 | + } |
| 127 | + ], |
| 128 | + "request": "http://localhost:8080//fhir/$extract-data", |
| 129 | + "deleted": [], |
| 130 | + "transactionTime": "2024-09-05T12:30:32.711151718Z", |
| 131 | + "error": [] |
| 132 | +} |
| 133 | + |
| 134 | +``` |
| 135 | + |
| 136 | +[1]: <http://hl7.org/fhir/R5/async-bulk.html> |
0 commit comments