如何使用 Google Cloud Healthcare API HttpBody 类?

问题描述

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

如何传递参数:

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 字段,但它通过了:

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

我应该如何传递参数来接收成功消息? 坦克!

解决方法

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

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...