0

我很难使用 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

我应该如何传递参数以接收成功消息?咳咳!

4

1 回答 1

0

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

于 2021-07-08T17:35:04.523 回答