0

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?

C Chen
  • 25
  • 4
  • The solution tutorial with a database-driven Slackbot / chatbot also uses a custom extension with Watson Assistant. It uses variables to collect and display data. Its code is available on GitHub. Go over it https://cloud.ibm.com/docs/solution-tutorials?topic=solution-tutorials-slack-chatbot-database-watson – data_henrik Apr 28 '23 at 08:01
  • Thanks for the link! Unfortunately, one of the challenges is that the only action variable I am able to pull up is "Ran successfully". I have tried setting careTeamMD to an expression but only encounter errors when I do so. – C Chen Apr 28 '23 at 16:22
  • the answer on how to see the other parts of the response is here https://stackoverflow.com/questions/76134429/hapi-fhir-openapi-document-modifying-responses/76140535#76140535 if there are more problems, pls rephrase the question – Dudi Apr 30 '23 at 10:11
  • Can you show an example of your OpenAPI file? Also it's easier to read if you convert it to YAML. – Simon O'Doherty May 15 '23 at 14:20

2 Answers2

0
  1. You should be assigning the value to the variable at any step after calling the extension because at that point the data from the extension should be populated.

  2. It is possible you are not seeing the display property because variables must now be typed properly. For instance, if you are trying to assign the string type display value to a boolean type variable you will not see display as a possible option. The variable you assign display to must be either any or free text (string) type. If this is not the case, then my next best guess would be that the custom extension was not set up properly.

0

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.

C Chen
  • 25
  • 4