ibm-cloudwatson-assistanthapi-fhir

IBM Watson Assistant Custom Extension Variable Assignments


I am creating a proof-of-concept chatbot that will take patient queries (e.g. "What is the name of my doctor?"), retrieve the information requested through a FHIR API, and return the information requested (e.g. "Your doctor is Dr. Smith."). I was able to create a custom extension using an Open API document provided by HAPI FHIR that allows me to look up data in the HAPI FHIR sandbox, but I am unable to pass that JSON response into discrete variables to populate my chatbot.

Currently, I have the chatbot structured so that it utilizes the extension HAPI FHIR API to retrieve information related to "CareTeam". It successfully retrieves the information related to "CareTeam" using the following CURL:

curl -X GET -H 'Content-Type: application/json' -H 'accept: application/json' 'https://hapi.fhir.org/baseR4/CareTeam/va-team-visn6-vamc1-pc'

The JSON response is:

{
    "status": 200,
    "body":
    {
        "resourceType": "CareTeam",
        "id": "va-team-visn6-vamc1-pc",
        "meta":
        {
            "versionId": "1",
            "lastUpdated": "2019-11-01T17:59:48.291+00:00",
            "source": "#qsmu4cjPakjrXiTn"
        },
        "text":
        {
            "status": "additional",
            "div": "<div xmlns=\"http://www.w3.org/1999/xhtml\"><div>Hampton, VA, VAMC, Primary Care PACT</div></div>"
        },
        "name": "Primary Care PACT",
        "participant":
        [
            {
                "role":
                [
                    {
                        "coding":
                        [
                            {
                                "system": "http://snomed.info/sct",
                                "code": "446050000",
                                "display": "Primary care physician"
                            }
                        ],
                        "text": "Primary Care Physician"
                    }
                ],
                "member":
                {
                    "reference": "Practitioner/va-prac-visn6-francis",
                    "display": "Dr. Francis"
                }
            }
        ]
    }
}

I am now trying to extract the information after display ("Dr. Francis"), assign it to a variable called careTeamMD, and display that result to the user. I haven't had much luck reading through the Watson Assistant documentation to better understand the syntax. I have two main questions:

  1. Where should I be assigning the value to the variable? Should it be in the step where I use the extension (step 1), or in the step where I return that information to the user (step 3)?
  2. How do I assign whatever is in display to careTeamMD?

Currently, when I try to use the "Insert a variable" option, the only variable I am given from the API call in step 1 is "Ran successfully". The only variables offered under "Integration variables" are Timezone, Locale, and Channel Name. How can I get Watson Assistant to "see" the rest of the data returned in the JSON response?


Solution

  • I was able to get the custom extension to function as desired by making some changes to my API document.

    The original file read:

    "/CareTeam/{id}": {
      "get": {
        "tags": [
          "CareTeam"
        ],
        "summary": "read-instance: Read CareTeam instance",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "description": "The resource ID",
            "required": true,
            "style": "simple",
            "schema": {
              "minimum": 1,
              "type": "string",
              "example": null
            },
            "example": "123"
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FHIR-JSON-RESOURCE"
                },
                "example": null
              },
              "application/fhir+xml": {
                "schema": {
                  "$ref": "#/components/schemas/FHIR-XML-RESOURCE"
                },
                "example": null
              }
            }
          }
        }
      },
    

    Originally, I modified the section to the following:

        "/CareTeam/{id}": {
          "get": {
            "tags": [
              "CareTeam"
            ],
            "summary": "read-instance: Read CareTeam instance",
            "parameters": [
              {
                "name": "id",
                "in": "path",
                "description": "The resource ID",
                "required": true,
                "style": "simple",
                "schema": {
                  "minimum": 1,
                  "type": "string",
                  "example": null
                },
                "example": "123"
              }
            ],
            "responses": {
              "200": {
                "description": "Success",
                "content": {
                  "application/fhir+json": {
                    "schema": {
                      "type": "object",
                      "properties": {
                        "status": {
                          "type": "integer"
                        },
                        "body": {
                          "type": "object",
                          "properties": {
                            "resourceType": {
                              "type": "string"
                            },
                            "id": {
                              "type": "string"
                            },
                            "meta": {
                              "type": "object",
                              "properties": {
                                "versionId": {
                                  "type": "string"
                                },
                                "lastUpdated": {
                                  "type": "string",
                                  "format": "date-time"
                                },
                                "source": {
                                  "type": "string"
                                }
                              }
                            },
                            "text": {
                              "type": "object",
                              "properties": {
                                "status": {
                                  "type": "string"
                                },
                                "div": {
                                  "type": "string"
                                }
                              }
                            },
                            "name": {
                              "type": "string"
                            },
                            "participant": {
                              "type": "array",
                              "items": {
                                "type": "object",
                                "properties": {
                                  "role": {
                                    "type": "array",
                                    "items": {
                                      "type": "object",
                                      "properties": {
                                        "coding": {
                                          "type": "array",
                                          "items": {
                                            "type": "object",
                                            "properties": {
                                              "system": {
                                                "type": "string"
                                              },
                                              "code": {
                                                "type": "string"
                                              },
                                              "display": {
                                                "type": "string"
                                              }
                                            }
                                          }
                                        },
                                        "text": {
                                          "type": "string"
                                        }
                                      }
                                    }
                                  },
                                  "member": {
                                    "type": "object",
                                    "properties": {
                                      "reference": {
                                        "type": "string"
                                      },
                                      "display": {
                                        "type": "string"
                                      }
                                    }
                                  }
                                }
                              }
                            }
                          }
                        }
                      }
                    },
                    "example": null
                  },
                  "application/fhir+xml": {
                    "schema": {
                      "$ref": "#/components/schemas/FHIR-XML-RESOURCE"
                    },
                    "example": null
                  }
                }
              }
            }
    

    but was still unable to get the extension to recognize the discrete variables. Thanks to Dudi's assistance, I was able to correct the OpenAPI document so that the individual components of what was being returned could be recognized as variables simply by changing application/fhir+json to application/json.