Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds GraphQL data client #81

Merged
merged 20 commits into from
Sep 5, 2024
Merged

Adds GraphQL data client #81

merged 20 commits into from
Sep 5, 2024

Conversation

jrwils
Copy link
Contributor

@jrwils jrwils commented Aug 22, 2024

https://canvasmedical.atlassian.net/browse/KOALA-1776

This PR adds a GraphQL client to be used to fetch data from home-app.

Example of how it can be used in a plugin:

from canvas_sdk.events import EventType
from canvas_sdk.protocols import BaseProtocol
from logger import log

from data_access_layer.client import GQL_CLIENT


class Protocol(BaseProtocol):
    RESPONDS_TO = [EventType.Name(EventType.PATIENT_UPDATED)]

    PATIENT_QUERY = """
        query PatientGet($patientKey: String!) {
          patient(patientKey: $patientKey) {
            firstName
            lastName
            birthDate
          }
        }
      """

    PATIENT_CONDITIONS_QUERY = """
        query GetPatientConditions($patientKey: String!) {
          conditions(patientKey: $patientKey) {
            edges {
              node {
                externallyExposableId
                onsetDate
                coding {
                  edges {
                    node {
		     display
                      code
                      system
                    }
                  }
                }
              }
            }
          }
        }
    """

    def compute(self):
        log.info(f"Received Patient Created Event for patient key {self.target}")
        log.info(f"Retrieving data about the patient")
        # Get Patient Data
        patient_data = GQL_CLIENT.query(self.PATIENT_QUERY, params={"patientKey": self.target})
        log.info(patient_data)

        # Get Patient's Conditions
        log.info("Getting patient conditions")
        patient_conditions = GQL_CLIENT.query(self.PATIENT_CONDITIONS_QUERY, params={"patientKey": self.target})
        log.info(patient_conditions)

        # Print condition info
        for condition in patient_conditions["conditions"]["edges"]:
            for condition_coding in condition["node"]["coding"]["edges"]:
                log.info(condition_coding["node"]["code"])
                log.info(condition_coding["node"]["system"])
                log.info(condition_coding["node"]["display"])
                log.info("")
        return []

@jrwils jrwils requested review from csande and beaugunderson August 22, 2024 21:32
Copy link
Contributor

@csande csande left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a couple small comments

data_access_layer/client.py Outdated Show resolved Hide resolved
data_access_layer/client.py Outdated Show resolved Hide resolved
data_access_layer/client.py Outdated Show resolved Hide resolved
Copy link
Member

@beaugunderson beaugunderson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only one small thing to add to Chris' comments

data_access_layer/client.py Outdated Show resolved Hide resolved
Copy link
Contributor

@csande csande left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved with one additional comment

settings.py Outdated Show resolved Hide resolved
settings.py Outdated Show resolved Hide resolved
canvas_sdk/protocols/base.py Outdated Show resolved Hide resolved
@jrwils jrwils merged commit db15859 into main Sep 5, 2024
4 checks passed
@jrwils jrwils deleted the feature/jw-koala-1776 branch September 5, 2024 01:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants