This project provides fhir cdp resources service. This includes creating and returning FHIR resource bundles that can be sent to a FHIR server.
Docker images manually pushed to cdp artifactory (for now).
Image Names:
wh-imaging-cdp-docker-local.artifactory.swg-devops.com/cdp/whpa-cdp-fhir-resources-service:0.0.1
This image can be used to test locally and avoid building the project via the py-service-wrapper.
Note: Awaiting updates on Jenkins pipeline that will allow us to build and push docker image via Jenkins, until then it is a manual step.
We are using Gradle through a python gradle plugin for the build environment.
A virtual env is created at location python.envPath
as per build.gradle
. By default your local python binary is used to create that virtual env, the gradle files mimic what we expect in Jenkins but you can provide python.pythonBinary
to override local python that will be used.
Note: refer the docs for more configuration options.
gradle tasks # will list all the available tasks
gradle build # will setup virtualenv and create all tests reports and distribution
Note: you will need the taasArtifactoryUsername
and taasArtifactoryPassword
variables in your gradle.properties
if it is not in you global Python setttings. Don't push this change to the repo.
Update gradle.properties as needed.
See LinuxForHealth py-service-wrapper for background and details about the py service wrapper.
See CDP Development setup Python section for details and two options to build the Python project.
- First option: Build the project using a "builder" image. [See link for details.] (https://pages.github.ibm.com/WH-Imaging/DevOps-CDP/docs/Dev_setup/Python.html)
- Second option: Gradle Setup with local.build.gradle.
The steps 1 and 2 below use the local.build.gradle. If you build with the first option (use builder image), skip steps 1 and 2 below.
-
Open a terminal window and navigate to the whpa-cdp-fhir-resources-service project parent directory.
-
Run the following command to create the python pip installable "wheel" file:
gradle clean build -b local.build.gradle # dist is under build/dist by default as per gradle.properties file
Note: on Windows the "clean" step will fail in Powershell because it needs the linux
rm
command. Windows "git bash" can be used instead. -
Create the container using the docker build command below. Add your artifactory id and key where specified:
docker build --build-arg USERNAME=<your artifactory email> --build-arg PASSWORD=<your artifactory api-key> -t whpa-cdp-fhir-resources-service:0.0.1 .
If the steps completed successfully, the image with the name of "IMAGE_NAME" value (whpa-cdp-fhir-resources-service:0.0.1) should now exist. Run the image:
docker run --rm --name whpa-cdp-fhir-resources-service -p 5000:5000 whpa-cdp-fhir-resources-service:0.0.1
To run the image with MinIO, use the docker-compose file in the test_helper directory. Before doing this, update the docker-compose.yml fhir-resources-service service image name to the one created above. Example:
fhir-resources-service:
#image: "wh-imaging-cdp-docker-local.artifactory.swg-devops.com/cdp/whpa-cdp-fhir-resources-service:0.0.1"
image: "whpa-cdp-fhir-resources-service:0.0.1"
Run the image with all services from the project directory using the edited docker-compose.yml:
cd test_helper
docker-compose up -d
OR from the project parent directory:
docker-compose -f test_helper/docker-compose.yml up -d
Browser UI URLs available after docker compose containers start:
- See OpenApi/Swagger section below.
- MinIO: http://localhost:9001/minio
See the project.yaml for the endpoints available. Examples:
http://localhost:5000/ping # http GET
http://localhost:5000/patient_bundle # http POST. See OpenApi for data payload and curl examples.
Possible http return codes returned by the fhir-resources-service:
- 200 Successful.
- 400 Bad request.
- 412 Precondition Failed. The tenant-id may be missing.
- 422 Validation Error. Data payload issue.
- 500 Internal server error.
An alternative view: http://localhost:5000/redoc
Update the build.gradle
and local.build.gradle
file to add dependencies.
We are using Python Black which is a python code formatter. If you are using vscode youcan set it up to use black
as default formatter for py files
Alternatively you can just run (from within the virtualenv):
$black <file or directory>
To run unittest, execute:
gradle clean test
For a manual integration test, you can leverage the docker-compose.yml
file to start MinIO as well as the fhir-resource-service. MinIO can be used to store example patient bundle data. The MinIO bucket name will be the tenant-id and the bucket's object storage id (OID) will be included in the POST payload (pat_batch_storage_id). See the OpenAPI/SwAGGER URL for the endpoint and the payload structure: http://localhost:5000/docs
To bring up services:
cd test_helper
docker-compose up -d
Note: to make sure you have latest images, execute:
cd test_helper
docker-compose down -v
docker-compose pull
docker-compose up -d
- Put test data in MinIO (http://localhost:9001/minio)
- Issue the POST http://localhost:5000/patient_bundle (see OpenAPI/Swagger for payload and curl examples)
- Verify response from POST
To setup vscode with the virtualenv and black
as default python formatter for the project, create a file .vscode/settings.json
, sample below:
#settings.json
{
"python.formatting.provider": "black",
"python.pythonPath": "/Users/ayush.garg/.local/share/virtualenvs/whpa-cdp-hl7-batch-receiver-fH1xTusc/bin/python"
}
Note: you can set editor.formatOnSave
to True to automatically formatting files on save
- ...