IBM Watson Assistant 自定义扩展变量分配

问题描述 投票:0回答:2

我正在创建一个概念验证聊天机器人,它将接受患者查询(例如“我的医生的名字是什么?”),通过 FHIR API 检索请求的信息,并返回请求的信息(例如“您的医生是史密斯博士。”)。我能够使用 HAPI FHIR 提供的开放 API 文档创建自定义扩展,它允许我在 HAPI FHIR 沙箱中查找数据,但我无法将该 JSON 响应传递到离散变量中以填充我的聊天机器人。

目前,我构建了聊天机器人,以便它利用扩展 HAPI FHIR API 来检索与“CareTeam”相关的信息。它使用以下 CURL 成功检索到与“CareTeam”相关的信息:

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

JSON 响应是:

{
    "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"
                }
            }
        ]
    }
}

我现在正在尝试提取

display
(“弗朗西斯博士”)之后的信息,将其分配给一个名为
careTeamMD
的变量,并将该结果显示给用户。我没有多少运气来阅读 Watson Assistant 文档以更好地理解语法。我有两个主要问题:

  1. 我应该在哪里为变量赋值?它应该在我使用扩展程序的步骤(步骤 1)中,还是在我将该信息返回给用户的步骤中(步骤 3)?
  2. 如何将
    display
    中的内容分配给
    careTeamMD

目前,当我尝试使用“插入变量”选项时,我从第 1 步中的 API 调用中得到的唯一变量是“成功运行”。 “集成变量”下提供的唯一变量是时区、区域设置和频道名称。我怎样才能让 Watson Assistant “看到”JSON 响应中返回的其余数据?

ibm-cloud watson-assistant hapi-fhir
2个回答
0
投票
  1. 您应该在调用扩展后的任何步骤将值分配给变量,因为此时应该填充来自扩展的数据。

  2. 您可能没有看到

    display
    属性,因为现在必须正确键入变量。例如,如果您尝试将
    string
    类型的
    display
    值分配给
    boolean
    类型的变量,您将看不到
    display
    作为可能的选项。您分配
    display
    的变量必须是
    any
    free text (string)
    类型。如果不是这种情况,那么我的下一个最佳猜测是自定义扩展设置不正确。


0
投票

通过对我的 API 文档进行一些更改,我能够让自定义扩展按预期运行。

原文件阅读:

"/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
          }
        }
      }
    }
  },

最初,我将部分修改为以下内容:

    "/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
              }
            }
          }
        }

但仍然无法获得识别离散变量的扩展。感谢 Dudi 的帮助,我能够更正 OpenAPI 文档,以便只需将

application/fhir+json
更改为
application/json
即可将返回内容的各个组件识别为变量。

© www.soinside.com 2019 - 2024. All rights reserved.