首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用Google Cloud Healthcare API HttpBody类?

如何使用Google Cloud Healthcare API HttpBody类?
EN

Stack Overflow用户
提问于 2021-07-06 19:48:30
回答 1查看 52关注 0票数 0

我在使用HttpBody类的方法setData()时遇到了困难。我将参数作为对象传递给该方法,但收到一条错误消息。

如何传递参数:

代码语言:javascript
复制
public function create(string $resource, $body)
{

        $client   = $this->googleClient();
        $service  = new CloudHealthcare($client);

        $parent   = "projects/my_project_id/locations/my_location/datasets/my_dataset/fhirStores/repository";

        $httpBody = new HttpBody();
        $httpBody->setContentType('application/fhir+json;charset=utf-8');
        $httpBody->setData([
            "resourceType" => "Patient",
            "id" => "23434",
            "meta" => [
                "versionId" => "12",
                "lastUpdated" => "2014-08-18T15:43:30Z"
            ],
            "text" => [
                "status" => "generated",
                "div" => "<!-- Snipped for Brevity -->"
            ],
            "extension" => [
                [
                    "url" => "http://example.org/consent#trials",
                    "valueCode" => "renal"
                ]
            ],
            "identifier" => [
                [
                    "use" => "usual",
                    "label" => "MRN",
                    "system" => "http://www.goodhealth.org/identifiers/mrn",
                    "value" => "123456"
                ]
            ],
            "name" => [
                [
                    "family" => [
                        "Levin"
                    ],
                    "given" => [
                        "Henry"
                    ],
                    "suffix" => [
                        "The 7th"
                    ]
                ]
            ],
            "gender" => [
                "text" => "Male"
            ],
            "birthDate" => "1932-09-24",
            "active" => true
        ]);

        $data     = $service->projects_locations_datasets_fhirStores_fhir->create($parent, $resource, $httpBody);

        return $data;
}

按照我得到的错误消息。错误提示我没有传递resourceType字段,但它被传递了:

代码语言:javascript
复制
Google\Service\Exception: {
"issue": [
{
  "code": "structure",
  "details": {
    "text": "unparseable_resource"
  },
  "diagnostics": "missing required field \"resourceType\"",
  "expression": [
    ""
  ],
  "severity": "error"
}
],
 "resourceType": "OperationOutcome"
 } in file /usr/share/nginx/vendor/google/apiclient/src/Http/REST.php on line 128

如何传递参数才能收到成功消息?Tkanks!

EN

回答 1

Stack Overflow用户

发布于 2021-07-09 01:35:05

我没有专门尝试过PHP客户端库,但是对于大多数语言,您不希望使用HttpBody类-它表明方法从方法签名的角度来看,接受了请求体中的文本内容。我会尝试直接传递JSON字符串。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68270013

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档