LinuxForHealth / fhir-resources

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

whpa-cdp-fhir-resources-services

This project provides fhir cdp resources service. This includes creating and returning FHIR resource bundles that can be sent to a FHIR server.

Deployment

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.


Development

Setup

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.

How to Create the Image for this Project

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.

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.

  1. Open a terminal window and navigate to the whpa-cdp-fhir-resources-service project parent directory.

  2. 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.

  3. 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 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.

OpenApi/Swagger URL

http://localhost:5000/docs

An alternative view: http://localhost:5000/redoc

Adding Dependency

Update the build.gradle and local.build.gradle file to add dependencies.


Formatting

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>

Testing

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

Example test flow with local MinIO after services started with docker-compose.

  1. Put test data in MinIO (http://localhost:9001/minio)
  2. Issue the POST http://localhost:5000/patient_bundle (see OpenAPI/Swagger for payload and curl examples)
  3. Verify response from POST

VSCODE PYTHON

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

Changelog

mm/dd/yyyy -- version 0.0.x

  • ...

About


Languages

Language:Python 95.2%Language:Dockerfile 4.8%