Skip to content

Commit

Permalink
Update FHIR converter API docs (#521)
Browse files Browse the repository at this point in the history
  • Loading branch information
emmastephenson authored May 11, 2023
1 parent 05358b5 commit c149815
Show file tree
Hide file tree
Showing 4 changed files with 409 additions and 43 deletions.
73 changes: 65 additions & 8 deletions containers/fhir-converter/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,40 @@
import uuid
from enum import Enum
from fastapi import FastAPI, Response, status
from pydantic import BaseModel

# Instantiate FastAPI via PHDI's BaseService class
app = FastAPI()
from pydantic import BaseModel, Field

# Reading sample request & response files for docs
raw_sample_response = json.load(
open(
Path(__file__).parent.parent
/ "assets"
/ "sample_vxu_fhir_conversion_response.json"
)
)
sample_response = {200: raw_sample_response}

sample_request = open(
Path(__file__).parent.parent / "assets" / "sample_request.hl7"
).read()

description = (Path(__file__).parent.parent / "description.md").read_text(
encoding="utf-8"
)

app = FastAPI(
title="PHDI FHIR Converter Service",
version="0.0.1",
contact={
"name": "CDC Public Health Data Infrastructure",
"url": "https://cdcgov.github.io/phdi-site/",
"email": "dmibuildingblocks@cdc.gov",
},
license_info={
"name": "Creative Commons Zero v1.0 Universal",
"url": "https://creativecommons.org/publicdomain/zero/1.0/",
},
description=description,
)


class InputType(str, Enum):
Expand Down Expand Up @@ -92,18 +122,45 @@ class FhirConverterInput(BaseModel):
Input parameters for the FHIR Converter.
"""

input_data: str
input_type: InputType
root_template: RootTemplate
input_data: str = Field(
description="The message to be converted as a string.",
example=sample_request,
)
input_type: InputType = Field(
description="The type of message to be converted.", example="vxu"
)
root_template: RootTemplate = Field(
description="Name of the liquid template within to be used for conversion.",
example="VXU_V04",
)


@app.get("/")
async def health_check():
"""
Check service status. If an HTTP 200 status code is returned along with
'{"status": "OK"}' then the FHIR conversion service is available and running
properly.
"""
return {"status": "OK"}


@app.post("/convert-to-fhir", status_code=200)
@app.post(
"/convert-to-fhir",
status_code=200,
responses=sample_response,
)
async def convert(input: FhirConverterInput, response: Response):
"""
Converts an HL7v2 or C-CDA message to FHIR format using the Microsoft FHIR
Converter CLI tool. When conversion is successful, a dictionary containing the
response from the FHIR Converter is returned.
In order to successfully call this function, the Microsoft FHIR Converter tool
must be installed. For information on how to do this, please refer to the
description.md file. The source code for the converter can be found at
https://github.com/microsoft/FHIR-Converter.
"""
result = convert_to_fhir(**dict(input))
if "original_request" in result.get("response"):
response.status_code = status.HTTP_400_BAD_REQUEST
Expand Down
6 changes: 6 additions & 0 deletions containers/fhir-converter/assets/sample_request.hl7
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
MSH|^~\&|WIR11.3.2^^|WIR^^||WIRPH^^|20200514010000-0400||VXU^V04|2020051411020600|P^|2.4^^|||ER
PID|||3054790^^^^SR^~^^^^PI^||ZTEST^PEDIARIX^^^^^^|HEPB^DTAP^^^^^^|20180808|M|||||||||||||||||||||
PD1|||||||||||02^^^^^|Y||||A
NK1|1||BRO^BROTHER^HL70063^^^^^|^^NEW GLARUS^WI^^^^^^^|
PV1||R||||||||||||||||||
RXA|0|999|20180809|20180809|08^HepB pediatric^CVX^90744^HepB pediatric^CPT|1.0|||01^^^^^~38193939^WIR immunization id^IMM_ID^^^|||||||||||NA
Original file line number Diff line number Diff line change
@@ -0,0 +1,273 @@
{"description": "Success",
"content": {
"application/json": {
"examples": {
"elr": {
"value": {
"response": {
"Status": "OK",
"FhirResource": {
"resourceType": "Bundle",
"type": "batch",
"timestamp": "2020-05-14T01:00:00-04:00",
"identifier": {
"value": "2020051411020600"
},
"id": "945561fc-cf00-ebd7-5f1c-865ab4abfcb5",
"entry": [
{
"fullUrl": "urn:uuid:53d0ea89-a281-523f-f0fb-02e3ee1ef0a2",
"resource": {
"resourceType": "MessageHeader",
"id": "53d0ea89-a281-523f-f0fb-02e3ee1ef0a2",
"source": {
"name": "WIR11.3.2",
"_endpoint": {
"extension": [
{
"url": "http://hl7.org/fhir/StructureDefinition/data-absent-reason",
"valueCode": "unknown"
}
]
}
},
"destination": [
{
"_endpoint": {
"extension": [
{
"url": "http://hl7.org/fhir/StructureDefinition/data-absent-reason",
"valueCode": "unknown"
}
]
},
"receiver": {
"reference": "Organization/f51a22ef-628f-d014-5a33-da96b68ae53d"
}
}
],
"meta": {
"tag": [
{
"code": "P",
"system": "http://terminology.hl7.org/CodeSystem/v2-0103"
}
]
},
"eventCoding": {
"code": "V04",
"system": "http://terminology.hl7.org/CodeSystem/v2-0003",
"display": "VXU^V04"
},
"sender": {
"reference": "Organization/b727354b-9ca6-74fd-6b6b-ae0851c7998a"
}
},
"request": {
"method": "PUT",
"url": "MessageHeader/53d0ea89-a281-523f-f0fb-02e3ee1ef0a2"
}
},
{
"fullUrl": "urn:uuid:d24c7a73-ebcf-8f4f-51bc-e95f47452e80",
"resource": {
"resourceType": "Provenance",
"id": "d24c7a73-ebcf-8f4f-51bc-e95f47452e80",
"text": {
"status": "generated",
"div": "<div xmlns=\"http://www.w3.org/1999/xhtml\"><p><span>Resource bundle generated on 2023-05-03T19:07:14.523Z using Microsoft FHIR Converter.</span><span>Template Version: TEMPLATE_VERSION_PLACEHOLDER.</span><span>Template URL: https://github.com/microsoft/FHIR-Converter/releases/download/vTEMPLATE_VERSION_PLACEHOLDER/Hl7v2DefaultTemplates.tar.gz.</span><span>Root template: VXU_V04.</span></p></div>"
},
"occurredDateTime": "2020-05-14T01:00:00-04:00",
"recorded": "2020-05-14T01:00:00-04:00",
"agent": [
{
"type": {
"coding": [
{
"code": "author",
"system": "http://terminology.hl7.org/CodeSystem/provenance-participant-type"
}
]
},
"who": {
"reference": "Organization/b727354b-9ca6-74fd-6b6b-ae0851c7998a"
}
}
],
"activity": {
"coding": [
{
"display": "VXU^V04^"
}
]
},
"target": [
{
"reference": "Bundle/945561fc-cf00-ebd7-5f1c-865ab4abfcb5"
}
]
},
"request": {
"method": "PUT",
"url": "Provenance/d24c7a73-ebcf-8f4f-51bc-e95f47452e80"
}
},
{
"fullUrl": "urn:uuid:b727354b-9ca6-74fd-6b6b-ae0851c7998a",
"resource": {
"resourceType": "Organization",
"id": "b727354b-9ca6-74fd-6b6b-ae0851c7998a",
"identifier": [
{
"value": "WIR",
"system": "http://example.com/v2-to-fhir-converter/Identifier/WIR"
}
]
},
"request": {
"method": "PUT",
"url": "Organization/b727354b-9ca6-74fd-6b6b-ae0851c7998a"
}
},
{
"fullUrl": "urn:uuid:f51a22ef-628f-d014-5a33-da96b68ae53d",
"resource": {
"resourceType": "Organization",
"id": "f51a22ef-628f-d014-5a33-da96b68ae53d",
"identifier": [
{
"value": "WIRPH",
"system": "http://example.com/v2-to-fhir-converter/Identifier/WIRPH"
}
]
},
"request": {
"method": "PUT",
"url": "Organization/f51a22ef-628f-d014-5a33-da96b68ae53d"
}
},
{
"fullUrl": "urn:uuid:3f8fc2a0-1d50-42de-bfed-9c01a071c6b6",
"resource": {
"resourceType": "Patient",
"id": "3f8fc2a0-1d50-42de-bfed-9c01a071c6b6",
"identifier": [
{
"value": "3054790",
"type": {
"coding": [
{
"code": "SR",
"system": "http://terminology.hl7.org/CodeSystem/v2-0203",
"display": "State registry ID"
}
]
}
},
{
"type": {
"coding": [
{
"code": "PI",
"system": "http://terminology.hl7.org/CodeSystem/v2-0203",
"display": "Patient internal identifier"
}
]
}
}
],
"name": [
{
"family": "ZTEST",
"given": [
"PEDIARIX"
]
}
],
"birthDate": "2018-08-08",
"gender": "male",
"active": true,
"extension": [
{
"url": "http://hl7.org/fhir/StructureDefinition/patient-mothersMaidenName",
"valueString": "HEPB--DTAP"
}
],
"contact": [
{
"address": {
"city": "NEW GLARUS",
"state": "WI"
}
}
]
},
"request": {
"method": "PUT",
"url": "Patient/3f8fc2a0-1d50-42de-bfed-9c01a071c6b6"
}
},
{
"fullUrl": "urn:uuid:caeb94a6-281c-4bd0-1dad-4998a2f80c35",
"resource": {
"resourceType": "Encounter",
"id": "caeb94a6-281c-4bd0-1dad-4998a2f80c35",
"class": {
"code": "R",
"display": "Recurring patient",
"system": "http://terminology.hl7.org/CodeSystem/v2-0004"
},
"status": "in-progress",
"text": {
"status": "generated",
"div": "<div xmlns=\"http://www.w3.org/1999/xhtml\"><p><span>Visit Description: </span></p></div>"
},
"subject": {
"reference": "Patient/3f8fc2a0-1d50-42de-bfed-9c01a071c6b6"
}
},
"request": {
"method": "PUT",
"url": "Encounter/caeb94a6-281c-4bd0-1dad-4998a2f80c35"
}
},
{
"fullUrl": "urn:uuid:1b3b6f92-c3c9-7440-d08b-3023cd94c569",
"resource": {
"resourceType": "RelatedPerson",
"id": "1b3b6f92-c3c9-7440-d08b-3023cd94c569",
"relationship": [
{
"coding": [
{
"code": "BRO",
"display": "brother",
"system": "http://terminology.hl7.org/CodeSystem/v3-RoleCode"
}
]
}
],
"address": [
{
"city": "NEW GLARUS",
"state": "WI"
}
],
"patient": {
"reference": "Patient/3f8fc2a0-1d50-42de-bfed-9c01a071c6b6"
}
},
"request": {
"method": "PUT",
"url": "RelatedPerson/1b3b6f92-c3c9-7440-d08b-3023cd94c569"
}
}
]
}
}
}
}
}
}
}
}
Loading

0 comments on commit c149815

Please sign in to comment.