ๅปบ็ซ‹ๅŠ็ฎก็† FHIR ่ณ‡ๆบ

ๆœฌ้ ่ชชๆ˜Žๅฆ‚ไฝ•ๅปบ็ซ‹ใ€ๆ›ดๆ–ฐใ€ไฟฎ่ฃœใ€ๆŸฅ็œ‹ใ€ๅˆ—ๅ‡บใ€ๆ“ทๅ–ๅŠๅˆช้™ค FHIR ่ณ‡ๆบใ€‚

FHIR ่ณ‡ๆบๅฏๅŒ…ๅซ็—…ๆ‚ฃใ€่ฃ็ฝฎใ€่ง€ๅฏŸ็ตๆžœ็ญ‰่ณ‡ๆ–™ใ€‚ๅฆ‚้œ€ๅฎŒๆ•ด็š„ FHIR ่ณ‡ๆบๆธ…ๅ–ฎ๏ผŒ่ซ‹ๅƒ้–ฑ FHIR ่ณ‡ๆบ็ดขๅผ• (DSTU2ใ€STU3ใ€R4 ๆˆ– R5)ใ€‚

ๆœฌ้ ็š„ REST ็ฏ„ไพ‹้ฉ็”จๆ–ผ R4 FHIR ๅ„ฒๅญ˜ๅบซ๏ผŒๅฆ‚ๆžœๆ‚จไฝฟ็”จ DSTU2 ๆˆ– STU3 FHIR ๅ„ฒๅญ˜ๅบซ๏ผŒๅ‰‡ไธไฟ่ญ‰่ƒฝๆญฃๅธธ้‹ไฝœใ€‚ๅฆ‚ๆžœๆ‚จไฝฟ็”จ DSTU2 ๆˆ– STU3 FHIR ๅญ˜ๆ”พๅ€๏ผŒ่ซ‹ๅƒ้–ฑๅฎ˜ๆ–น FHIR ่ชชๆ˜Žๆ–‡ไปถ๏ผŒ็žญ่งฃๅฆ‚ไฝ•ๅฐ‡็ฏ„ไพ‹่ฝ‰ๆ›็‚บๆ‚จไฝฟ็”จ็š„ FHIR ็‰ˆๆœฌใ€‚

Goใ€Javaใ€Node.js ๅ’Œ Python ็ฏ„ไพ‹้ฉ็”จๆ–ผ STU3 FHIR ๅญ˜ๆ”พๅ€ใ€‚

ๅปบ็ซ‹ FHIR ่ณ‡ๆบ

ๆ‚จๅฟ…้ ˆๅ…ˆๅปบ็ซ‹ FHIR ๅ„ฒๅญ˜ๅบซ๏ผŒๆ‰่ƒฝๅปบ็ซ‹ FHIR ่ณ‡ๆบใ€‚

REST ๅ’Œ Python ็ฏ„ไพ‹่ชชๆ˜Žๅฆ‚ไฝ•ๅปบ็ซ‹ไธ‹ๅˆ— FHIR ่ณ‡ๆบ๏ผš

  1. ็—…ๆ‚ฃ (DSTU2ใ€STU3ใ€R4 ๅ’Œ R5) ่ณ‡ๆบ
  2. ็—…ๆ‚ฃ็š„ Encounter (DSTU2ใ€ STU3ใ€ R4 ๅ’Œ R5) ่ณ‡ๆบ
  3. Encounter ็š„ Observation (DSTU2ใ€STU3ใ€R4 ๅ’Œ R5) ่ณ‡ๆบ

ๅ…ถไป–ๆ‰€ๆœ‰่ชž่จ€็š„็ฏ„ไพ‹ๅ‰‡่ชชๆ˜Žๅฆ‚ไฝ•ๅปบ็ซ‹ไธ€่ˆฌ FHIR ่ณ‡ๆบใ€‚

่ฉณๆƒ…่ซ‹ๅƒ้–ฑ projects.locations.datasets.fhirStores.fhir.createใ€‚

ไธ‹ๅˆ— REST ็ฏ„ไพ‹้ฉ็”จๆ–ผ R4 FHIR ๅ„ฒๅญ˜ๅบซใ€‚Goใ€Javaใ€Node.js ๅ’Œ Python ็ฏ„ไพ‹้ฉ็”จๆ–ผ STU3 FHIR ๅญ˜ๆ”พๅ€ใ€‚

REST

ไฝฟ็”จไปปไฝ•่ฆๆฑ‚่ณ‡ๆ–™ไน‹ๅ‰๏ผŒ่ซ‹ๅ…ˆๆ›ฟๆ›ไปฅไธ‹้ …็›ฎ๏ผš

  • PROJECT_ID๏ผšๆ‚จ็š„ Google Cloud ๅฐˆๆกˆ ID
  • LOCATION๏ผš่ณ‡ๆ–™้›†ไฝ็ฝฎ
  • DATASET_ID๏ผšFHIR ๅ„ฒๅญ˜ๅบซ็š„็ˆถ้ …่ณ‡ๆ–™้›†
  • FHIR_STORE_ID๏ผšFHIR ๅ„ฒๅญ˜ๅบซ ID

JSON ่ฆๆฑ‚ไธป้ซ”๏ผš

{
  "name": [
    {
      "use": "official",
      "family": "Smith",
      "given": [
        "Darcy"
      ]
    }
  ],
  "gender": "female",
  "birthDate": "1970-01-01",
  "resourceType": "Patient"
}

ๅฆ‚่ฆๅ‚ณ้€่ฆๆฑ‚๏ผŒ่ซ‹้ธๆ“‡ไปฅไธ‹ๅ…ถไธญไธ€ๅ€‹้ธ้ …๏ผš

curl

ๅฐ‡่ฆๆฑ‚ไธป้ซ”ๅ„ฒๅญ˜ๅœจๅ็‚บ request.json ็š„ๆช”ๆกˆไธญใ€‚ ๅœจ็ต‚็ซฏๆฉŸไธญๅŸท่กŒไธ‹ๅˆ—ๆŒ‡ไปค๏ผŒๅœจ็›ฎๅ‰็›ฎ้Œ„ไธญๅปบ็ซ‹ๆˆ–่ฆ†ๅฏซ้€™ๅ€‹ๆช”ๆกˆ๏ผš

cat > request.json << 'EOF'
{
  "name": [
    {
      "use": "official",
      "family": "Smith",
      "given": [
        "Darcy"
      ]
    }
  ],
  "gender": "female",
  "birthDate": "1970-01-01",
  "resourceType": "Patient"
}
EOF

ๆŽฅ่‘—๏ผŒ่ซ‹ๅŸท่กŒไธ‹ๅˆ—ๆŒ‡ไปคไพ†ๅ‚ณ้€ REST ่ฆๆฑ‚๏ผš

curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/fhir+json" \
-d @request.json \
"https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/fhirStores/FHIR_STORE_ID/fhir/Patient"

PowerShell

ๅฐ‡่ฆๆฑ‚ไธป้ซ”ๅ„ฒๅญ˜ๅœจๅ็‚บ request.json ็š„ๆช”ๆกˆไธญใ€‚ ๅœจ็ต‚็ซฏๆฉŸไธญๅŸท่กŒไธ‹ๅˆ—ๆŒ‡ไปค๏ผŒๅœจ็›ฎๅ‰็›ฎ้Œ„ไธญๅปบ็ซ‹ๆˆ–่ฆ†ๅฏซ้€™ๅ€‹ๆช”ๆกˆ๏ผš

@'
{
  "name": [
    {
      "use": "official",
      "family": "Smith",
      "given": [
        "Darcy"
      ]
    }
  ],
  "gender": "female",
  "birthDate": "1970-01-01",
  "resourceType": "Patient"
}
'@  | Out-File -FilePath request.json -Encoding utf8

ๆŽฅ่‘—๏ผŒ่ซ‹ๅŸท่กŒไธ‹ๅˆ—ๆŒ‡ไปคไพ†ๅ‚ณ้€ REST ่ฆๆฑ‚๏ผš

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/fhir+json" `
-InFile request.json `
-Uri "https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/fhirStores/FHIR_STORE_ID/fhir/Patient" | Select-Object -Expand Content

ๆ‚จๆ‡‰่ฉฒๆœƒๆ”ถๅˆฐๅฆ‚ไธ‹็š„ JSON ๅ›žๆ‡‰๏ผš

Go

import (
	"bytes"
	"context"
	"encoding/json"
	"fmt"
	"io"

	healthcare "google.golang.org/api/healthcare/v1"
)

// createFHIRResource creates an FHIR resource.
func createFHIRResource(w io.Writer, projectID, location, datasetID, fhirStoreID, resourceType string) error {
	ctx := context.Background()

	healthcareService, err := healthcare.NewService(ctx)
	if err != nil {
		return fmt.Errorf("healthcare.NewService: %w", err)
	}

	fhirService := healthcareService.Projects.Locations.Datasets.FhirStores.Fhir

	payload := map[string]interface{}{
		"resourceType": resourceType,
		"language":     "FR",
	}
	jsonPayload, err := json.Marshal(payload)
	if err != nil {
		return fmt.Errorf("json.Encode: %w", err)
	}

	parent := fmt.Sprintf("projects/%s/locations/%s/datasets/%s/fhirStores/%s", projectID, location, datasetID, fhirStoreID)

	call := fhirService.Create(parent, resourceType, bytes.NewReader(jsonPayload))
	call.Header().Set("Content-Type", "application/fhir+json;charset=utf-8")
	resp, err := call.Do()
	if err != nil {
		return fmt.Errorf("Create: %w", err)
	}
	defer resp.Body.Close()

	respBytes, err := io.ReadAll(resp.Body)
	if err != nil {
		return fmt.Errorf("could not read response: %w", err)
	}

	if resp.StatusCode > 299 {
		return fmt.Errorf("Create: status %d %s: %s", resp.StatusCode, resp.Status, respBytes)
	}
	fmt.Fprintf(w, "%s", respBytes)

	return nil
}

Java

import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.gson.GsonFactory;
import com.google.api.services.healthcare.v1.CloudHealthcare;
import com.google.api.services.healthcare.v1.CloudHealthcareScopes;
import com.google.auth.http.HttpCredentialsAdapter;
import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.Collections;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.client.methods.RequestBuilder;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.HttpClients;

public class FhirResourceCreate {
  private static final String FHIR_NAME = "projects/%s/locations/%s/datasets/%s/fhirStores/%s";
  private static final JsonFactory JSON_FACTORY = new GsonFactory();
  private static final NetHttpTransport HTTP_TRANSPORT = new NetHttpTransport();

  public static void fhirResourceCreate(String fhirStoreName, String resourceType)
      throws IOException, URISyntaxException {
    // String fhirStoreName =
    //    String.format(
    //        FHIR_NAME, "your-project-id", "your-region-id", "your-dataset-id", "your-fhir-id");
    // String resourceType = "Patient";

    // Initialize the client, which will be used to interact with the service.
    CloudHealthcare client = createClient();
    HttpClient httpClient = HttpClients.createDefault();
    String uri = String.format("%sv1/%s/fhir/%s", client.getRootUrl(), fhirStoreName, resourceType);
    URIBuilder uriBuilder = new URIBuilder(uri).setParameter("access_token", getAccessToken());
    StringEntity requestEntity =
        new StringEntity("{\"resourceType\": \"" + resourceType + "\", \"language\": \"en\"}");

    HttpUriRequest request =
        RequestBuilder.post()
            .setUri(uriBuilder.build())
            .setEntity(requestEntity)
            .addHeader("Content-Type", "application/fhir+json")
            .addHeader("Accept-Charset", "utf-8")
            .addHeader("Accept", "application/fhir+json; charset=utf-8")
            .build();

    // Execute the request and process the results.
    HttpResponse response = httpClient.execute(request);
    HttpEntity responseEntity = response.getEntity();
    if (response.getStatusLine().getStatusCode() != HttpStatus.SC_CREATED) {
      System.err.print(
          String.format(
              "Exception creating FHIR resource: %s\n", response.getStatusLine().toString()));
      responseEntity.writeTo(System.err);
      throw new RuntimeException();
    }
    System.out.print("FHIR resource created: ");
    responseEntity.writeTo(System.out);
  }

  private static CloudHealthcare createClient() throws IOException {
    // Use Application Default Credentials (ADC) to authenticate the requests
    // For more information see https://cloud.google.com/docs/authentication/production
    GoogleCredentials credential =
        GoogleCredentials.getApplicationDefault()
            .createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));

    // Create a HttpRequestInitializer, which will provide a baseline configuration to all requests.
    HttpRequestInitializer requestInitializer =
        request -> {
          new HttpCredentialsAdapter(credential).initialize(request);
          request.setConnectTimeout(60000); // 1 minute connect timeout
          request.setReadTimeout(60000); // 1 minute read timeout
        };

    // Build the client for interacting with the service.
    return new CloudHealthcare.Builder(HTTP_TRANSPORT, JSON_FACTORY, requestInitializer)
        .setApplicationName("your-application-name")
        .build();
  }

  private static String getAccessToken() throws IOException {
    GoogleCredentials credential =
        GoogleCredentials.getApplicationDefault()
            .createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));

    return credential.refreshAccessToken().getTokenValue();
  }
}

Node.js

const google = require('@googleapis/healthcare');
const healthcare = google.healthcare({
  version: 'v1',
  auth: new google.auth.GoogleAuth({
    scopes: ['https://www.googleapis.com/auth/cloud-platform'],
  }),
  headers: {'Content-Type': 'application/fhir+json'},
});

async function createFhirResource() {
  // Replace the following body with the data for the resource you want to
  // create.
  const body = {
    name: [{use: 'official', family: 'Smith', given: ['Darcy']}],
    gender: 'female',
    birthDate: '1970-01-01',
    resourceType: 'Patient',
  };

  // TODO(developer): uncomment these lines before running the sample
  // const cloudRegion = 'us-central1';
  // const projectId = 'adjective-noun-123';
  // const datasetId = 'my-dataset';
  // const fhirStoreId = 'my-fhir-store';
  // const resourceType = 'Patient';
  const parent = `projects/${projectId}/locations/${cloudRegion}/datasets/${datasetId}/fhirStores/${fhirStoreId}`;

  const request = {parent, type: resourceType, requestBody: body};
  const resource =
    await healthcare.projects.locations.datasets.fhirStores.fhir.create(
      request
    );
  console.log(`Created FHIR resource with ID ${resource.data.id}`);
  console.log(resource.data);
}

createFhirResource();

Python

# Imports the types Dict and Any for runtime type hints.
from typing import Any, Dict  # noqa: E402


def create_patient(
    project_id: str,
    location: str,
    dataset_id: str,
    fhir_store_id: str,
) -> Dict[str, Any]:
    """Creates a new Patient resource in a FHIR store.

    See
    https://github.com/GoogleCloudPlatform/python-docs-samples/tree/main/healthcare/api-client/v1/fhir
    before running the sample.
    See
    https://googleapis.github.io/google-api-python-client/docs/dyn/healthcare_v1.projects.locations.datasets.fhirStores.fhir.html#create
    for the Python API reference.

    Args:
      project_id: The project ID or project number of the Cloud project you want
        to use.
      location: The name of the parent dataset's location.
      dataset_id: The name of the parent dataset.
      fhir_store_id: The name of the FHIR store that holds the Patient resource.

    Returns:
      A dict representing the created Patient resource.
    """
    # Imports the Google API Discovery Service.
    from googleapiclient import discovery

    api_version = "v1"
    service_name = "healthcare"

    # Returns an authorized API client by discovering the Healthcare API
    # and using GOOGLE_APPLICATION_CREDENTIALS environment variable.
    client = discovery.build(service_name, api_version)

    # TODO(developer): Uncomment these lines and replace with your values.
    # project_id = 'my-project'
    # location = 'us-central1'
    # dataset_id = 'my-dataset'
    # fhir_store_id = 'my-fhir-store'
    fhir_store_parent = (
        f"projects/{project_id}/locations/{location}/datasets/{dataset_id}"
    )
    fhir_store_name = f"{fhir_store_parent}/fhirStores/{fhir_store_id}"

    patient_body = {
        "name": [{"use": "official", "family": "Smith", "given": ["Darcy"]}],
        "gender": "female",
        "birthDate": "1970-01-01",
        "resourceType": "Patient",
    }

    request = (
        client.projects()
        .locations()
        .datasets()
        .fhirStores()
        .fhir()
        .create(parent=fhir_store_name, type="Patient", body=patient_body)
    )
    # Sets required application/fhir+json header on the googleapiclient.http.HttpRequest.
    request.headers["content-type"] = "application/fhir+json;charset=utf-8"
    response = request.execute()

    print(f"Created Patient resource with ID {response['id']}")
    return response

ๅปบ็ซ‹ Patient ่ณ‡ๆบๅพŒ๏ผŒ่ซ‹ๅปบ็ซ‹ Encounter ่ณ‡ๆบ๏ผŒ่ชชๆ˜Ž็—…ๆ‚ฃ่ˆ‡้†ซ่ญทไบบๅ“กไน‹้–“็š„ไบ’ๅ‹•ใ€‚

ๅœจ PATIENT_ID ๆฌ„ไฝไธญ๏ผŒไปฃๅ…ฅๆ‚จๅปบ็ซ‹ Patient ่ณ‡ๆบๆ™‚๏ผŒไผบๆœๅ™จๅ‚ณๅ›ž็š„ๅ›žๆ‡‰ IDใ€‚

ไธ‹ๅˆ— REST ็ฏ„ไพ‹้ฉ็”จๆ–ผ R4 FHIR ๅ„ฒๅญ˜ๅบซใ€‚Python ็ฏ„ไพ‹้ฉ็”จๆ–ผ STU3 FHIR ๅ„ฒๅญ˜ๅบซใ€‚

REST

ไฝฟ็”จไปปไฝ•่ฆๆฑ‚่ณ‡ๆ–™ไน‹ๅ‰๏ผŒ่ซ‹ๅ…ˆๆ›ฟๆ›ไปฅไธ‹้ …็›ฎ๏ผš

  • PROJECT_ID๏ผšๆ‚จ็š„ Google Cloud ๅฐˆๆกˆ ID
  • LOCATION๏ผš่ณ‡ๆ–™้›†ไฝ็ฝฎ
  • DATASET_ID๏ผšFHIR ๅ„ฒๅญ˜ๅบซ็š„็ˆถ้ …่ณ‡ๆ–™้›†
  • FHIR_STORE_ID๏ผšFHIR ๅ„ฒๅญ˜ๅบซ ID
  • PATIENT_ID๏ผšๅปบ็ซ‹ Patient ่ณ‡ๆบๆ™‚๏ผŒไผบๆœๅ™จๅ‚ณๅ›ž็š„ๅ›žๆ‡‰

JSON ่ฆๆฑ‚ไธป้ซ”๏ผš

{
  "status": "finished",
  "class": {
    "system": "http://hl7.org/fhir/v3/ActCode",
    "code": "IMP",
    "display": "inpatient encounter"
  },
  "reasonCode": [
    {
      "text": "The patient had an abnormal heart rate. She was concerned about this."
    }
  ],
  "subject": {
    "reference": "Patient/PATIENT_ID"
  },
  "resourceType": "Encounter"
}

ๅฆ‚่ฆๅ‚ณ้€่ฆๆฑ‚๏ผŒ่ซ‹้ธๆ“‡ไปฅไธ‹ๅ…ถไธญไธ€ๅ€‹้ธ้ …๏ผš

curl

ๅฐ‡่ฆๆฑ‚ไธป้ซ”ๅ„ฒๅญ˜ๅœจๅ็‚บ request.json ็š„ๆช”ๆกˆไธญใ€‚ ๅœจ็ต‚็ซฏๆฉŸไธญๅŸท่กŒไธ‹ๅˆ—ๆŒ‡ไปค๏ผŒๅœจ็›ฎๅ‰็›ฎ้Œ„ไธญๅปบ็ซ‹ๆˆ–่ฆ†ๅฏซ้€™ๅ€‹ๆช”ๆกˆ๏ผš

cat > request.json << 'EOF'
{
  "status": "finished",
  "class": {
    "system": "http://hl7.org/fhir/v3/ActCode",
    "code": "IMP",
    "display": "inpatient encounter"
  },
  "reasonCode": [
    {
      "text": "The patient had an abnormal heart rate. She was concerned about this."
    }
  ],
  "subject": {
    "reference": "Patient/PATIENT_ID"
  },
  "resourceType": "Encounter"
}
EOF

ๆŽฅ่‘—๏ผŒ่ซ‹ๅŸท่กŒไธ‹ๅˆ—ๆŒ‡ไปคไพ†ๅ‚ณ้€ REST ่ฆๆฑ‚๏ผš

curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/fhir+json" \
-d @request.json \
"https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/fhirStores/FHIR_STORE_ID/fhir/Encounter"

PowerShell

ๅฐ‡่ฆๆฑ‚ไธป้ซ”ๅ„ฒๅญ˜ๅœจๅ็‚บ request.json ็š„ๆช”ๆกˆไธญใ€‚ ๅœจ็ต‚็ซฏๆฉŸไธญๅŸท่กŒไธ‹ๅˆ—ๆŒ‡ไปค๏ผŒๅœจ็›ฎๅ‰็›ฎ้Œ„ไธญๅปบ็ซ‹ๆˆ–่ฆ†ๅฏซ้€™ๅ€‹ๆช”ๆกˆ๏ผš

@'
{
  "status": "finished",
  "class": {
    "system": "http://hl7.org/fhir/v3/ActCode",
    "code": "IMP",
    "display": "inpatient encounter"
  },
  "reasonCode": [
    {
      "text": "The patient had an abnormal heart rate. She was concerned about this."
    }
  ],
  "subject": {
    "reference": "Patient/PATIENT_ID"
  },
  "resourceType": "Encounter"
}
'@  | Out-File -FilePath request.json -Encoding utf8

ๆŽฅ่‘—๏ผŒ่ซ‹ๅŸท่กŒไธ‹ๅˆ—ๆŒ‡ไปคไพ†ๅ‚ณ้€ REST ่ฆๆฑ‚๏ผš

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/fhir+json" `
-InFile request.json `
-Uri "https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/fhirStores/FHIR_STORE_ID/fhir/Encounter" | Select-Object -Expand Content

ๆ‚จๆ‡‰่ฉฒๆœƒๆ”ถๅˆฐๅฆ‚ไธ‹็š„ JSON ๅ›žๆ‡‰๏ผš

Python

ๅœจ่ฉฆ็”จ้€™ๅ€‹็ฏ„ไพ‹ไน‹ๅ‰๏ผŒ่ซ‹ๅ…ˆๆŒ‰็…งPythonใ€ŒCloud Healthcare API ๅฟซ้€Ÿๅ…ฅ้–€๏ผšไฝฟ็”จ็”จๆˆถ็ซฏ็จ‹ๅผๅบซใ€ไธญ็š„ๆ“ไฝœ่ชชๆ˜Ž้€ฒ่กŒ่จญๅฎšใ€‚่ฉณๆƒ…่ซ‹ๅƒ้–ฑ Cloud Healthcare API Python API ๅƒ่€ƒ่ชชๆ˜Žๆ–‡ไปถใ€‚

ๅฆ‚่ฆๅ‘ Cloud Healthcare API ้€ฒ่กŒ้ฉ—่ญ‰๏ผŒ่ซ‹่จญๅฎšๆ‡‰็”จ็จ‹ๅผ้ ่จญๆ†‘่ญ‰ใ€‚ ่ฉณๆƒ…่ซ‹ๅƒ้–ฑใ€Œ็‚บๆœฌๆฉŸ้–‹็™ผ็’ฐๅขƒ่จญๅฎš้ฉ—่ญ‰ใ€ใ€‚

# Imports the types Dict and Any for runtime type hints.
from typing import Any, Dict  # noqa: E402

def create_encounter(
    project_id: str,
    location: str,
    dataset_id: str,
    fhir_store_id: str,
    patient_id: str,
) -> Dict[str, Any]:
    """Creates a new Encounter resource in a FHIR store that references a Patient resource.

    See
    https://github.com/GoogleCloudPlatform/python-docs-samples/tree/main/healthcare/api-client/v1/fhir
    before running the sample.
    See
    https://googleapis.github.io/google-api-python-client/docs/dyn/healthcare_v1.projects.locations.datasets.fhirStores.fhir.html#create
    for the Python API reference.

    Args:
      project_id: The project ID or project number of the Cloud project you want
        to use.
      location: The name of the parent dataset's location.
      dataset_id: The name of the parent dataset.
      fhir_store_id: The name of the FHIR store.
      patient_id: The "logical id" of the referenced Patient resource. The ID is
        assigned by the server.

    Returns:
      A dict representing the created Encounter resource.
    """
    # Imports the Google API Discovery Service.
    from googleapiclient import discovery

    api_version = "v1"
    service_name = "healthcare"

    # Returns an authorized API client by discovering the Healthcare API
    # and using GOOGLE_APPLICATION_CREDENTIALS environment variable.
    client = discovery.build(service_name, api_version)

    # TODO(developer): Uncomment these lines and replace with your values.
    # project_id = 'my-project'
    # location = 'us-central1'
    # dataset_id = 'my-dataset'
    # fhir_store_id = 'my-fhir-store'
    # patient_id = 'b682d-0e-4843-a4a9-78c9ac64'  # replace with the associated Patient resource's ID
    fhir_store_parent = (
        f"projects/{project_id}/locations/{location}/datasets/{dataset_id}"
    )
    fhir_store_name = f"{fhir_store_parent}/fhirStores/{fhir_store_id}"

    encounter_body = {
        "status": "finished",
        "class": {
            "system": "http://hl7.org/fhir/v3/ActCode",
            "code": "IMP",
            "display": "inpatient encounter",
        },
        "reason": [
            {
                "text": (
                    "The patient had an abnormal heart rate. She was"
                    " concerned about this."
                )
            }
        ],
        "subject": {"reference": f"Patient/{patient_id}"},
        "resourceType": "Encounter",
    }

    request = (
        client.projects()
        .locations()
        .datasets()
        .fhirStores()
        .fhir()
        .create(parent=fhir_store_name, type="Encounter", body=encounter_body)
    )
    # Sets required application/fhir+json header on the googleapiclient.http.HttpRequest.
    request.headers["content-type"] = "application/fhir+json;charset=utf-8"
    response = request.execute()
    print(f"Created Encounter resource with ID {response['id']}")

    return response

ๅปบ็ซ‹ Encounter ่ณ‡ๆบๅพŒ๏ผŒ่ซ‹ๅปบ็ซ‹่ˆ‡ Encounter ่ณ‡ๆบ็›ธ้—œ่ฏ็š„ Observation ่ณ‡ๆบใ€‚Observation ่ณ‡ๆบๆœƒๆไพ›็—…ๆ‚ฃ็š„ๅฟƒ็އๆธฌ้‡็ตๆžœ๏ผŒๅ–ฎไฝ็‚บๆฏๅˆ†้˜ๅฟƒ่ทณๆ•ธ (BPM) (80 in bpm)ใ€‚

ไธ‹ๅˆ— REST ็ฏ„ไพ‹้ฉ็”จๆ–ผ R4 FHIR ๅ„ฒๅญ˜ๅบซใ€‚Python ็ฏ„ไพ‹้ฉ็”จๆ–ผ STU3 FHIR ๅ„ฒๅญ˜ๅบซใ€‚

REST

ไฝฟ็”จไปปไฝ•่ฆๆฑ‚่ณ‡ๆ–™ไน‹ๅ‰๏ผŒ่ซ‹ๅ…ˆๆ›ฟๆ›ไปฅไธ‹้ …็›ฎ๏ผš

  • PROJECT_ID๏ผšๆ‚จ็š„ Google Cloud ๅฐˆๆกˆ ID
  • LOCATION๏ผš่ณ‡ๆ–™้›†ไฝ็ฝฎ
  • DATASET_ID๏ผšFHIR ๅ„ฒๅญ˜ๅบซ็š„็ˆถ้ …่ณ‡ๆ–™้›†
  • FHIR_STORE_ID๏ผšFHIR ๅ„ฒๅญ˜ๅบซ ID
  • PATIENT_ID๏ผšๅปบ็ซ‹ Patient ่ณ‡ๆบๆ™‚๏ผŒไผบๆœๅ™จๅœจๅ›žๆ‡‰ไธญๅ‚ณๅ›ž็š„ ID
  • ENCOUNTER_ID๏ผšๅปบ็ซ‹ Encounter ่ณ‡ๆบๆ™‚๏ผŒไผบๆœๅ™จๅ‚ณๅ›ž็š„ๅ›žๆ‡‰ ID

JSON ่ฆๆฑ‚ไธป้ซ”๏ผš

{
  "resourceType": "Observation",
  "status": "final",
  "subject": {
    "reference": "Patient/PATIENT_ID"
  },
  "effectiveDateTime": "2020-01-01T00:00:00+00:00",
  "identifier": [
    {
      "system": "my-code-system",
      "value": "ABC-12345"
    }
  ],
  "code": {
    "coding": [
      {
        "system": "http://loinc.org",
        "code": "8867-4",
        "display": "Heart rate"
      }
    ]
  },
  "valueQuantity": {
    "value": 80,
    "unit": "bpm"
  },
  "encounter": {
    "reference": "Encounter/ENCOUNTER_ID"
  }
}

ๅฆ‚่ฆๅ‚ณ้€่ฆๆฑ‚๏ผŒ่ซ‹้ธๆ“‡ไปฅไธ‹ๅ…ถไธญไธ€ๅ€‹้ธ้ …๏ผš

curl

ๅฐ‡่ฆๆฑ‚ไธป้ซ”ๅ„ฒๅญ˜ๅœจๅ็‚บ request.json ็š„ๆช”ๆกˆไธญใ€‚ ๅœจ็ต‚็ซฏๆฉŸไธญๅŸท่กŒไธ‹ๅˆ—ๆŒ‡ไปค๏ผŒๅœจ็›ฎๅ‰็›ฎ้Œ„ไธญๅปบ็ซ‹ๆˆ–่ฆ†ๅฏซ้€™ๅ€‹ๆช”ๆกˆ๏ผš

cat > request.json << 'EOF'
{
  "resourceType": "Observation",
  "status": "final",
  "subject": {
    "reference": "Patient/PATIENT_ID"
  },
  "effectiveDateTime": "2020-01-01T00:00:00+00:00",
  "identifier": [
    {
      "system": "my-code-system",
      "value": "ABC-12345"
    }
  ],
  "code": {
    "coding": [
      {
        "system": "http://loinc.org",
        "code": "8867-4",
        "display": "Heart rate"
      }
    ]
  },
  "valueQuantity": {
    "value": 80,
    "unit": "bpm"
  },
  "encounter": {
    "reference": "Encounter/ENCOUNTER_ID"
  }
}
EOF

ๆŽฅ่‘—๏ผŒ่ซ‹ๅŸท่กŒไธ‹ๅˆ—ๆŒ‡ไปคไพ†ๅ‚ณ้€ REST ่ฆๆฑ‚๏ผš

curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/fhir+json" \
-d @request.json \
"https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/fhirStores/FHIR_STORE_ID/fhir/Observation"

PowerShell

ๅฐ‡่ฆๆฑ‚ไธป้ซ”ๅ„ฒๅญ˜ๅœจๅ็‚บ request.json ็š„ๆช”ๆกˆไธญใ€‚ ๅœจ็ต‚็ซฏๆฉŸไธญๅŸท่กŒไธ‹ๅˆ—ๆŒ‡ไปค๏ผŒๅœจ็›ฎๅ‰็›ฎ้Œ„ไธญๅปบ็ซ‹ๆˆ–่ฆ†ๅฏซ้€™ๅ€‹ๆช”ๆกˆ๏ผš

@'
{
  "resourceType": "Observation",
  "status": "final",
  "subject": {
    "reference": "Patient/PATIENT_ID"
  },
  "effectiveDateTime": "2020-01-01T00:00:00+00:00",
  "identifier": [
    {
      "system": "my-code-system",
      "value": "ABC-12345"
    }
  ],
  "code": {
    "coding": [
      {
        "system": "http://loinc.org",
        "code": "8867-4",
        "display": "Heart rate"
      }
    ]
  },
  "valueQuantity": {
    "value": 80,
    "unit": "bpm"
  },
  "encounter": {
    "reference": "Encounter/ENCOUNTER_ID"
  }
}
'@  | Out-File -FilePath request.json -Encoding utf8

ๆŽฅ่‘—๏ผŒ่ซ‹ๅŸท่กŒไธ‹ๅˆ—ๆŒ‡ไปคไพ†ๅ‚ณ้€ REST ่ฆๆฑ‚๏ผš

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/fhir+json" `
-InFile request.json `
-Uri "https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/fhirStores/FHIR_STORE_ID/fhir/Observation" | Select-Object -Expand Content

ๆ‚จๆ‡‰่ฉฒๆœƒๆ”ถๅˆฐๅฆ‚ไธ‹็š„ JSON ๅ›žๆ‡‰๏ผš

Python

ๅœจ่ฉฆ็”จ้€™ๅ€‹็ฏ„ไพ‹ไน‹ๅ‰๏ผŒ่ซ‹ๅ…ˆๆŒ‰็…งPythonใ€ŒCloud Healthcare API ๅฟซ้€Ÿๅ…ฅ้–€๏ผšไฝฟ็”จ็”จๆˆถ็ซฏ็จ‹ๅผๅบซใ€ไธญ็š„ๆ“ไฝœ่ชชๆ˜Ž้€ฒ่กŒ่จญๅฎšใ€‚่ฉณๆƒ…่ซ‹ๅƒ้–ฑ Cloud Healthcare API Python API ๅƒ่€ƒ่ชชๆ˜Žๆ–‡ไปถใ€‚

ๅฆ‚่ฆๅ‘ Cloud Healthcare API ้€ฒ่กŒ้ฉ—่ญ‰๏ผŒ่ซ‹่จญๅฎšๆ‡‰็”จ็จ‹ๅผ้ ่จญๆ†‘่ญ‰ใ€‚ ่ฉณๆƒ…่ซ‹ๅƒ้–ฑใ€Œ็‚บๆœฌๆฉŸ้–‹็™ผ็’ฐๅขƒ่จญๅฎš้ฉ—่ญ‰ใ€ใ€‚

# Imports the types Dict and Any for runtime type hints.
from typing import Any, Dict  # noqa: E402

def create_observation(
    project_id: str,
    location: str,
    dataset_id: str,
    fhir_store_id: str,
    patient_id: str,
    encounter_id: str,
) -> Dict[str, Any]:
    """Creates a new Observation resource in a FHIR store that references an Encounter and Patient resource.

    See
    https://github.com/GoogleCloudPlatform/python-docs-samples/tree/main/healthcare/api-client/v1/fhir
    before running the sample.
    See
    https://googleapis.github.io/google-api-python-client/docs/dyn/healthcare_v1.projects.locations.datasets.fhirStores.fhir.html#create
    for the Python API reference.

    Args:
      project_id: The project ID or project number of the Cloud project you want
        to use.
      location: The name of the parent dataset's location.
      dataset_id: The name of the parent dataset.
      fhir_store_id: The name of the FHIR store.
      patient_id: The "logical id" of the referenced Patient resource. The ID is
        assigned by the server.
      encounter_id: The "logical id" of the referenced Encounter resource. The ID
        is assigned by the server.

    Returns:
      A dict representing the created Observation resource.
    """
    # Imports the Google API Discovery Service.
    from googleapiclient import discovery

    api_version = "v1"
    service_name = "healthcare"

    # Returns an authorized API client by discovering the Healthcare API
    # and using GOOGLE_APPLICATION_CREDENTIALS environment variable.
    client = discovery.build(service_name, api_version)

    # TODO(developer): Uncomment these lines and replace with your values.
    # project_id = 'my-project'
    # location = 'us-central1'
    # dataset_id = 'my-dataset'
    # fhir_store_id = 'my-fhir-store'
    # patient_id = 'b682d-0e-4843-a4a9-78c9ac64'  # replace with the associated Patient resource's ID
    # encounter_id = 'a7602f-ffba-470a-a5c1-103f993c6  # replace with the associated Encounter resource's ID
    fhir_store_parent = (
        f"projects/{project_id}/locations/{location}/datasets/{dataset_id}"
    )
    fhir_observation_path = (
        f"{fhir_store_parent}/fhirStores/{fhir_store_id}/fhir/Observation"
    )

    observation_body = {
        "resourceType": "Observation",
        "code": {
            "coding": [
                {
                    "system": "http://loinc.org",
                    "code": "8867-4",
                    "display": "Heart rate",
                }
            ]
        },
        "status": "final",
        "subject": {"reference": f"Patient/{patient_id}"},
        "effectiveDateTime": "2019-01-01T00:00:00+00:00",
        "valueQuantity": {"value": 80, "unit": "bpm"},
        "context": {"reference": f"Encounter/{encounter_id}"},
    }

    request = (
        client.projects()
        .locations()
        .datasets()
        .fhirStores()
        .fhir()
        .create(
            parent=fhir_observation_path,
            type="Observation",
            body=observation_body,
        )
    )
    # Sets required application/fhir+json header on the googleapiclient.http.HttpRequest.
    request.headers["content-type"] = "application/fhir+json;charset=utf-8"
    response = request.execute()
    print(f"Created Observation resource with ID {response['id']}")

    return response

ๆœ‰ๆขไปถๅœฐๅปบ็ซ‹ FHIR ่ณ‡ๆบ

ไธ‹ๅˆ— curl ็ฏ„ไพ‹่ชชๆ˜Žๅฆ‚ไฝ•ไฝฟ็”จ projects.locations.datasets.fhirStores.fhir.create ๆ–นๆณ•๏ผŒๆœ‰ๆขไปถๅœฐๅปบ็ซ‹ FHIR ่ณ‡ๆบใ€‚้€™ๅ€‹ๆ–นๆณ•ๆœƒๅฏฆไฝœ FHIR ๆขไปถๅผ create ไบ’ๅ‹• (DSTU2ใ€STU3ใ€R4ใ€R5)ใ€‚

ๆ‚จๅฏไปฅ้‹็”จๆขไปถๅผๅปบ็ซ‹ๅŠŸ่ƒฝ๏ผŒ้ฟๅ…ๅปบ็ซ‹้‡่ค‡็š„ FHIR ่ณ‡ๆบใ€‚่ˆ‰ไพ‹ไพ†่ชช๏ผŒFHIR ไผบๆœๅ™จไธญ็š„ๆฏๅ€‹ Patient ่ณ‡ๆบ้€šๅธธ้ƒฝๆœ‰ๅฐˆๅฑฌ ID๏ผŒไพ‹ๅฆ‚็—…ๆญท็ทจ่™Ÿ (MRN)ใ€‚ๅฆ‚่ฆๅปบ็ซ‹ๆ–ฐ็š„ Patient ่ณ‡ๆบ๏ผŒไธฆ็ขบไฟๆฒ’ๆœ‰็›ธๅŒ MRN ็š„ Patient ่ณ‡ๆบ๏ผŒ่ซ‹ไฝฟ็”จๆœๅฐ‹ๆŸฅ่ฉขๆœ‰ๆขไปถๅœฐๅปบ็ซ‹ๆ–ฐ่ณ‡ๆบใ€‚ๅชๆœ‰ๅœจๆœๅฐ‹ๆŸฅ่ฉขๆฒ’ๆœ‰็›ธ็ฌฆ้ …็›ฎๆ™‚๏ผŒCloud Healthcare API ๆ‰ๆœƒๅปบ็ซ‹ๆ–ฐ่ณ‡ๆบใ€‚

ไผบๆœๅ™จ็š„ๅ›žๆ‡‰ๅ–ๆฑบๆ–ผ็ฌฆๅˆๆœๅฐ‹ๆŸฅ่ฉข็š„่ณ‡ๆบๆ•ธ้‡๏ผš

็›ธ็ฌฆ HTTP ๅ›žๆ‡‰็ขผ ่กŒ็‚บ
ๆœชๆœ‰ 201 CREATED ๅปบ็ซ‹ๆ–ฐ่ณ‡ๆบใ€‚
1 ๅ€‹ 200 OK ไธๆœƒๅปบ็ซ‹ๆ–ฐ่ณ‡ๆบใ€‚
่ถ…้Žไธ€ๅ€‹ 412 Precondition Failed ไธๆœƒๅปบ็ซ‹ๆ–ฐ่ณ‡ๆบ๏ผŒไธฆๅ‚ณๅ›ž "search criteria are not selective enough" ้Œฏ่ชคใ€‚

ๅฆ‚่ฆไฝฟ็”จๆขไปถๅผ create ไบ’ๅ‹•๏ผŒ่€Œ้ž create ไบ’ๅ‹•๏ผŒ่ซ‹ๅœจ่ฆๆฑ‚ไธญๆŒ‡ๅฎšๅŒ…ๅซ FHIR ๆœๅฐ‹ๆŸฅ่ฉข็š„ If-None-Exist HTTP ๆจ™้ ญ๏ผš

If-None-Exist: FHIR_SEARCH_QUERY

ๅœจ Cloud Healthcare API ็ฌฌ 1 ็‰ˆไธญ๏ผŒๆขไปถๅผไฝœๆฅญๆœƒๅฐˆ้–€ไฝฟ็”จ identifier ๆœๅฐ‹ๅƒๆ•ธ (ๅฆ‚ๆžœ FHIR ่ณ‡ๆบ้กžๅž‹ๆœ‰้€™ๅ€‹ๅƒๆ•ธ)๏ผŒๅˆคๆ–ทๅ“ชไบ› FHIR ่ณ‡ๆบ็ฌฆๅˆๆขไปถๅผๆœๅฐ‹ๆŸฅ่ฉขใ€‚

REST

ไปฅไธ‹็ฏ„ไพ‹่ชชๆ˜Žๅฆ‚ไฝ•ไฝฟ็”จ If-None-Exist: identifier=my-code-system|ABC-12345 HTTP ๆจ™้ ญๅปบ็ซ‹ Observation ่ณ‡ๆบใ€‚ๅชๆœ‰ๅœจๆฒ’ๆœ‰็พๆœ‰ Observation ่ณ‡ๆบ็ฌฆๅˆๆŸฅ่ฉข identifier=my-code-system|ABC-12345 ๆ™‚๏ผŒCloud Healthcare API ๆ‰ๆœƒๅปบ็ซ‹่ณ‡ๆบใ€‚

curl -X POST \
  -H "Authorization: Bearer $(gcloud auth print-access-token)" \
  -H "Content-Type: application/fhir+json" \
  -H "If-None-Exist: identifier=my-code-system|ABC-12345" \
  -d @request.json \
  "https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/fhirStores/FHIR_STORE_ID/fhir/Observation"

ไธ‹ๅˆ—่ผธๅ‡บๅ…งๅฎน็ฏ„ไพ‹ๅˆปๆ„้กฏ็คบๅคฑๆ•—็š„่ฆๆฑ‚ใ€‚ๅฆ‚่ฆๆŸฅ็œ‹ๆˆๅŠŸ่ฆๆฑ‚็š„ๅ›žๆ‡‰๏ผŒ่ซ‹ๅƒ้–ฑใ€Œๅปบ็ซ‹ FHIR ่ณ‡ๆบใ€ใ€‚

ๅฆ‚ๆžœๆœ‰ๅคšๅ€‹ Observation ่ณ‡ๆบ็ฌฆๅˆๆŸฅ่ฉขๆขไปถ๏ผŒCloud Healthcare API ๆœƒๅ‚ณๅ›žไธ‹ๅˆ—ๅ›žๆ‡‰๏ผŒไธ”ๆขไปถๅผๅปบ็ซ‹่ฆๆฑ‚ๆœƒๅคฑๆ•—๏ผš

{
  "issue": [
    {
      "code": "conflict",
      "details": {
        "text": "ambiguous_query"
      },
      "diagnostics": "search criteria are not selective enough",
      "severity": "error"
    }
  ],
  "resourceType": "OperationOutcome"
}

ๆ›ดๆ–ฐ FHIR ่ณ‡ๆบ

ไธ‹ๅˆ—็ฏ„ไพ‹่ชชๆ˜Žๅฆ‚ไฝ•ไฝฟ็”จ projects.locations.datasets.fhirStores.fhir.update ๆ–นๆณ•ๆ›ดๆ–ฐ FHIR ่ณ‡ๆบใ€‚้€™ๅ€‹ๆ–นๆณ•ๆœƒๅฏฆไฝœ FHIR ๆจ™ๆบ–็š„ๆ›ดๆ–ฐไบ’ๅ‹• (DSTU2ใ€STU3ใ€R4 ๅ’Œ R5)ใ€‚

ๆ›ดๆ–ฐ่ณ‡ๆบๆ™‚๏ผŒๆ‚จๆœƒๆ›ดๆ–ฐ่ณ‡ๆบ็š„ๅฎŒๆ•ดๅ…งๅฎนใ€‚ ้€™่ˆ‡ไฟฎ่ฃœ่ณ‡ๆบไธๅŒ๏ผŒๅพŒ่€…ๅชๆœƒๆ›ดๆ–ฐ่ณ‡ๆบ็š„้ƒจๅˆ†ๅ…งๅฎนใ€‚

ๅฆ‚ๆžœ FHIR ๅญ˜ๆ”พๅ€ๅทฒ่จญๅฎš enableUpdateCreate๏ผŒ็ณป็ตฑๆœƒๅฐ‡่ฆๆฑ‚่ฆ–็‚บ upsert (ๆ›ดๆ–ฐๆˆ–ๆ’ๅ…ฅ)๏ผŒๅฆ‚ๆžœ่ณ‡ๆบๅญ˜ๅœจ๏ผŒๅ‰‡ๆœƒๆ›ดๆ–ฐ่ณ‡ๆบ๏ผ›ๅฆ‚ๆžœ่ณ‡ๆบไธๅญ˜ๅœจ๏ผŒๅ‰‡ๆœƒไฝฟ็”จ่ฆๆฑ‚ไธญๆŒ‡ๅฎš็š„ ID ๆ’ๅ…ฅ่ณ‡ๆบใ€‚

่ฆๆฑ‚ไธป้ซ”ๅฟ…้ ˆๅŒ…ๅซ JSON ็ทจ็ขผ็š„ FHIR ่ณ‡ๆบ๏ผŒ่ฆๆฑ‚ๆจ™้ ญๅ‰‡ๅฟ…้ ˆๅŒ…ๅซ Content-Type: application/fhir+jsonใ€‚่ณ‡ๆบๅฟ…้ ˆๅŒ…ๅซ id ๅ…ƒ็ด ๏ผŒๅ…ถๅ€ผ่ˆ‡่ฆๆฑ‚ REST ่ทฏๅพ‘ไธญ็š„ ID ็›ธๅŒใ€‚

ไธ‹ๅˆ— REST ็ฏ„ไพ‹้ฉ็”จๆ–ผ R4 FHIR ๅ„ฒๅญ˜ๅบซใ€‚Goใ€Javaใ€Node.js ๅ’Œ Python ็ฏ„ไพ‹้ฉ็”จๆ–ผ STU3 FHIR ๅญ˜ๆ”พๅ€ใ€‚

REST

ไธ‹ๅˆ—็ฏ„ไพ‹่ชชๆ˜Žๅฆ‚ไฝ•ๆ›ดๆ–ฐ Observation ่ณ‡ๆบไธญ็š„ๆฏๅˆ†้˜ๅฟƒ่ทณๆ•ธ (BPM)ใ€‚

ไฝฟ็”จไปปไฝ•่ฆๆฑ‚่ณ‡ๆ–™ไน‹ๅ‰๏ผŒ่ซ‹ๅ…ˆๆ›ฟๆ›ไปฅไธ‹้ …็›ฎ๏ผš

  • PROJECT_ID๏ผšๆ‚จ็š„ Google Cloud ๅฐˆๆกˆ ID
  • LOCATION๏ผš่ณ‡ๆ–™้›†ไฝ็ฝฎ
  • DATASET_ID๏ผšFHIR ๅ„ฒๅญ˜ๅบซ็š„็ˆถ้ …่ณ‡ๆ–™้›†
  • FHIR_STORE_ID๏ผšFHIR ๅ„ฒๅญ˜ๅบซ ID
  • OBSERVATION_ID๏ผšObservation ่ณ‡ๆบ ID
  • PATIENT_ID๏ผš็—…ๆ‚ฃ่ณ‡ๆบ ID
  • ENCOUNTER_ID๏ผšๆœƒ่จบ่ณ‡ๆบ ID
  • BPM_VALUE๏ผšๆ›ดๆ–ฐๅพŒใ€Œ่ง€ๅฏŸใ€่ณ‡ๆบไธญ็š„ๆฏๅˆ†้˜ๅฟƒ่ทณๆ•ธ (BPM) ๅ€ผ

JSON ่ฆๆฑ‚ไธป้ซ”๏ผš

{
  "resourceType": "Observation",
  "id": "OBSERVATION_ID",
  "status": "final",
  "subject": {
    "reference": "Patient/PATIENT_ID"
  },
  "effectiveDateTime": "2020-01-01T00:00:00+00:00",
  "identifier": [
    {
      "system": "my-code-system",
      "value": "ABC-12345"
    }
  ],
  "code": {
    "coding": [
      {
        "system": "http://loinc.org",
        "code": "8867-4",
        "display": "Heart rate"
      }
    ]
  },
  "valueQuantity": {
    "value": BPM_VALUE,
    "unit": "bpm"
  },
  "encounter": {
    "reference": "Encounter/ENCOUNTER_ID"
  }
}

ๅฆ‚่ฆๅ‚ณ้€่ฆๆฑ‚๏ผŒ่ซ‹้ธๆ“‡ไปฅไธ‹ๅ…ถไธญไธ€ๅ€‹้ธ้ …๏ผš

curl

ๅฐ‡่ฆๆฑ‚ไธป้ซ”ๅ„ฒๅญ˜ๅœจๅ็‚บ request.json ็š„ๆช”ๆกˆไธญใ€‚ ๅœจ็ต‚็ซฏๆฉŸไธญๅŸท่กŒไธ‹ๅˆ—ๆŒ‡ไปค๏ผŒๅœจ็›ฎๅ‰็›ฎ้Œ„ไธญๅปบ็ซ‹ๆˆ–่ฆ†ๅฏซ้€™ๅ€‹ๆช”ๆกˆ๏ผš

cat > request.json << 'EOF'
{
  "resourceType": "Observation",
  "id": "OBSERVATION_ID",
  "status": "final",
  "subject": {
    "reference": "Patient/PATIENT_ID"
  },
  "effectiveDateTime": "2020-01-01T00:00:00+00:00",
  "identifier": [
    {
      "system": "my-code-system",
      "value": "ABC-12345"
    }
  ],
  "code": {
    "coding": [
      {
        "system": "http://loinc.org",
        "code": "8867-4",
        "display": "Heart rate"
      }
    ]
  },
  "valueQuantity": {
    "value": BPM_VALUE,
    "unit": "bpm"
  },
  "encounter": {
    "reference": "Encounter/ENCOUNTER_ID"
  }
}
EOF

ๆŽฅ่‘—๏ผŒ่ซ‹ๅŸท่กŒไธ‹ๅˆ—ๆŒ‡ไปคไพ†ๅ‚ณ้€ REST ่ฆๆฑ‚๏ผš

curl -X PUT \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/fhirStores/FHIR_STORE_ID/fhir/Observation/OBSERVATION_ID"

PowerShell

ๅฐ‡่ฆๆฑ‚ไธป้ซ”ๅ„ฒๅญ˜ๅœจๅ็‚บ request.json ็š„ๆช”ๆกˆไธญใ€‚ ๅœจ็ต‚็ซฏๆฉŸไธญๅŸท่กŒไธ‹ๅˆ—ๆŒ‡ไปค๏ผŒๅœจ็›ฎๅ‰็›ฎ้Œ„ไธญๅปบ็ซ‹ๆˆ–่ฆ†ๅฏซ้€™ๅ€‹ๆช”ๆกˆ๏ผš

@'
{
  "resourceType": "Observation",
  "id": "OBSERVATION_ID",
  "status": "final",
  "subject": {
    "reference": "Patient/PATIENT_ID"
  },
  "effectiveDateTime": "2020-01-01T00:00:00+00:00",
  "identifier": [
    {
      "system": "my-code-system",
      "value": "ABC-12345"
    }
  ],
  "code": {
    "coding": [
      {
        "system": "http://loinc.org",
        "code": "8867-4",
        "display": "Heart rate"
      }
    ]
  },
  "valueQuantity": {
    "value": BPM_VALUE,
    "unit": "bpm"
  },
  "encounter": {
    "reference": "Encounter/ENCOUNTER_ID"
  }
}
'@  | Out-File -FilePath request.json -Encoding utf8

ๆŽฅ่‘—๏ผŒ่ซ‹ๅŸท่กŒไธ‹ๅˆ—ๆŒ‡ไปคไพ†ๅ‚ณ้€ REST ่ฆๆฑ‚๏ผš

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method PUT `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/fhirStores/FHIR_STORE_ID/fhir/Observation/OBSERVATION_ID" | Select-Object -Expand Content

APIs Explorer

่ค‡่ฃฝ่ฆๆฑ‚ๅ…งๆ–‡ไธฆ้–‹ๅ•Ÿๆ–นๆณ•ๅƒ่€ƒ่ณ‡ๆ–™้ ้ขใ€‚็ณป็ตฑๆœƒๅœจ้ ้ขๅณๅด้–‹ๅ•Ÿ APIs Explorer ้ขๆฟใ€‚ๆ‚จๅฏไปฅไฝฟ็”จ้€™้ …ๅทฅๅ…ทไพ†ๅ‚ณ้€่ฆๆฑ‚ใ€‚ๅฐ‡่ฆๆฑ‚ๅ…งๆ–‡่ฒผๅˆฐ้€™้ …ๅทฅๅ…ทไธญ๏ผŒไธฆๅกซๅฆฅๅ…ถไป–ๅฟ…ๅกซๆฌ„ไฝ๏ผŒ็„ถๅพŒๆŒ‰ไธ€ไธ‹ใ€ŒExecuteใ€(ๅŸท่กŒ)ใ€‚

ๆ‚จๆ‡‰่ฉฒๆœƒๆ”ถๅˆฐๅฆ‚ไธ‹็š„ JSON ๅ›žๆ‡‰๏ผš

Go

import (
	"bytes"
	"context"
	"encoding/json"
	"fmt"
	"io"

	healthcare "google.golang.org/api/healthcare/v1"
)

// updateFHIRResource updates an FHIR resource to be active or not.
func updateFHIRResource(w io.Writer, projectID, location, datasetID, fhirStoreID, resourceType, fhirResourceID string, active bool) error {
	ctx := context.Background()

	healthcareService, err := healthcare.NewService(ctx)
	if err != nil {
		return fmt.Errorf("healthcare.NewService: %w", err)
	}

	fhirService := healthcareService.Projects.Locations.Datasets.FhirStores.Fhir

	// The following payload works with a Patient resource and is not
	// intended to work with other types of FHIR resources. If necessary,
	// supply a new payload with data that corresponds to the FHIR resource
	// you are updating.
	payload := map[string]interface{}{
		"resourceType": resourceType,
		"id":           fhirResourceID,
		"active":       active,
	}
	jsonPayload, err := json.Marshal(payload)
	if err != nil {
		return fmt.Errorf("json.Encode: %w", err)
	}

	name := fmt.Sprintf("projects/%s/locations/%s/datasets/%s/fhirStores/%s/fhir/%s/%s", projectID, location, datasetID, fhirStoreID, resourceType, fhirResourceID)

	call := fhirService.Update(name, bytes.NewReader(jsonPayload))
	call.Header().Set("Content-Type", "application/fhir+json;charset=utf-8")
	resp, err := call.Do()
	if err != nil {
		return fmt.Errorf("Update: %w", err)
	}
	defer resp.Body.Close()

	respBytes, err := io.ReadAll(resp.Body)
	if err != nil {
		return fmt.Errorf("could not read response: %w", err)
	}

	if resp.StatusCode > 299 {
		return fmt.Errorf("Update: status %d %s: %s", resp.StatusCode, resp.Status, respBytes)
	}
	fmt.Fprintf(w, "%s", respBytes)

	return nil
}

Node.js

const google = require('@googleapis/healthcare');
const healthcare = google.healthcare({
  version: 'v1',
  auth: new google.auth.GoogleAuth({
    scopes: ['https://www.googleapis.com/auth/cloud-platform'],
  }),
  headers: {'Content-Type': 'application/fhir+json'},
});

const updateFhirResource = async () => {
  // TODO(developer): uncomment these lines before running the sample
  // const cloudRegion = 'us-central1';
  // const projectId = 'adjective-noun-123';
  // const datasetId = 'my-dataset';
  // const fhirStoreId = 'my-fhir-store';
  // const resourceType = 'Patient';
  // const resourceId = '16e8a860-33b3-49be-9b03-de979feed14a';
  const name = `projects/${projectId}/locations/${cloudRegion}/datasets/${datasetId}/fhirStores/${fhirStoreId}/fhir/${resourceType}/${resourceId}`;
  // The following body works with a Patient resource and is not intended
  // to work with other types of FHIR resources. If necessary, supply a new
  // body with data that corresponds to the FHIR resource you are updating.
  const body = {resourceType: resourceType, id: resourceId, active: true};
  const request = {name, requestBody: body};

  const resource =
    await healthcare.projects.locations.datasets.fhirStores.fhir.update(
      request
    );
  console.log(`Updated ${resourceType} resource:\n`, resource.data);
};

updateFhirResource();

Python

# Imports the types Dict and Any for runtime type hints.
from typing import Any, Dict  # noqa: E402


def update_resource(
    project_id: str,
    location: str,
    dataset_id: str,
    fhir_store_id: str,
    resource_type: str,
    resource_id: str,
) -> Dict[str, Any]:
    """Updates the entire contents of a FHIR resource.

    Creates a new current version if the resource already exists, or creates
    a new resource with an initial version if no resource already exists with
    the provided ID.

    See
    https://github.com/GoogleCloudPlatform/python-docs-samples/tree/main/healthcare/api-client/v1/fhir
    before running the sample.
    See
    https://googleapis.github.io/google-api-python-client/docs/dyn/healthcare_v1.projects.locations.datasets.fhirStores.fhir.html#update
    for the Python API reference.

    Args:
      project_id: The project ID or project number of the Cloud project you want
        to use.
      location: The name of the parent dataset's location.
      dataset_id: The name of the parent dataset.
      fhir_store_id: The name of the FHIR store.
      resource_type: The type of the FHIR resource.
      resource_id: The "logical id" of the resource. The ID is assigned by the
        server.

    Returns:
      A dict representing the updated FHIR resource.
    """
    # Imports the Google API Discovery Service.
    from googleapiclient import discovery

    api_version = "v1"
    service_name = "healthcare"

    # Returns an authorized API client by discovering the Healthcare API
    # and using GOOGLE_APPLICATION_CREDENTIALS environment variable.
    client = discovery.build(service_name, api_version)

    # TODO(developer): Uncomment these lines and replace with your values.
    # project_id = 'my-project'
    # location = 'us-central1'
    # dataset_id = 'my-dataset'
    # fhir_store_id = 'my-fhir-store'
    # resource_type = 'Patient'
    # resource_id = 'b682d-0e-4843-a4a9-78c9ac64'
    fhir_store_parent = (
        f"projects/{project_id}/locations/{location}/datasets/{dataset_id}"
    )
    fhir_resource_path = f"{fhir_store_parent}/fhirStores/{fhir_store_id}/fhir/{resource_type}/{resource_id}"

    # The following sample body works with a Patient resource and isn't guaranteed
    # to work with other types of FHIR resources. If necessary,
    # supply a new body with data that corresponds to the resource you
    # are updating.
    patient_body = {
        "resourceType": resource_type,
        "active": True,
        "id": resource_id,
    }

    request = (
        client.projects()
        .locations()
        .datasets()
        .fhirStores()
        .fhir()
        .update(name=fhir_resource_path, body=patient_body)
    )
    # Sets required application/fhir+json header on the googleapiclient.http.HttpRequest.
    request.headers["content-type"] = "application/fhir+json;charset=utf-8"
    response = request.execute()

    print(
        f"Updated {resource_type} resource with ID {resource_id}:\n"
        f" {json.dumps(response, indent=2)}"
    )

    return response

ๆœ‰ๆขไปถๅœฐๆ›ดๆ–ฐ FHIR ่ณ‡ๆบ

ไธ‹ๅˆ—็ฏ„ไพ‹่ชชๆ˜Žๅฆ‚ไฝ•ๅ‘ผๅซ projects.locations.datasets.fhirStores.fhir.conditionalUpdate ๆ–นๆณ•๏ผŒๆ›ดๆ–ฐ็ฌฆๅˆๆœๅฐ‹ๆŸฅ่ฉข็š„ FHIR ่ณ‡ๆบ๏ผŒ่€Œ้žไพ ID ่ญ˜ๅˆฅ่ณ‡ๆบใ€‚้€™ๅ€‹ๆ–นๆณ•ๆœƒๅฏฆไฝœ FHIR ๆจ™ๆบ–ๆขไปถๅผๆ›ดๆ–ฐไบ’ๅ‹• (DSTU2ใ€STU3ใ€R4 ๅ’Œ R5)ใ€‚

ๆขไปถๅผๆ›ดๆ–ฐไธ€ๆฌกๅช่ƒฝๅฅ—็”จ่‡ณไธ€้ … FHIR ่ณ‡ๆบใ€‚

ไผบๆœๅ™จๅ‚ณๅ›ž็š„ๅ›žๆ‡‰ๅ–ๆฑบๆ–ผๆ นๆ“šๆœๅฐ‹ๆขไปถๆฏ”ๅฐ็š„็ตๆžœๆ•ธ้‡๏ผš

  • ไธ€ๅ€‹็›ธ็ฌฆ้ …็›ฎ๏ผš่ณ‡ๆบๅทฒๆˆๅŠŸๆ›ดๆ–ฐ๏ผŒๆˆ–็ณป็ตฑๅ‚ณๅ›ž้Œฏ่ชคใ€‚
  • ๅคšๅ€‹็›ธ็ฌฆ้ …็›ฎ๏ผš่ฆๆฑ‚ๆœƒๅ‚ณๅ›ž 412 Precondition Failed ้Œฏ่ชคใ€‚
  • ้›ถๅ€‹็ฌฆๅˆ id ็š„้ …็›ฎ๏ผšๅฆ‚ๆžœๆœๅฐ‹ๆขไปถๆœชๆ‰พๅ‡บไปปไฝ•็›ธ็ฌฆ้ …็›ฎใ€ๆไพ›็š„่ฆๆฑ‚ไธป้ซ”ๅŒ…ๅซ id๏ผŒไธ” FHIR ๅ„ฒๅญ˜ๅบซๅทฒๅฐ‡ enableUpdateCreate ่จญ็‚บ true๏ผŒ็ณป็ตฑๆœƒไฝฟ็”จ่ฆๆฑ‚ไธป้ซ”ไธญ็š„ id ๅปบ็ซ‹ FHIR ่ณ‡ๆบใ€‚
  • ๆฒ’ๆœ‰็›ธ็ฌฆ้ …็›ฎ๏ผŒไธ”ๆฒ’ๆœ‰ id๏ผšๅฆ‚ๆžœๆœๅฐ‹ๆขไปถๆฒ’ๆœ‰็›ธ็ฌฆ้ …็›ฎ๏ผŒไธ”ๆไพ›็š„่ฆๆฑ‚ไธป้ซ”ไธๅซ id๏ผŒ็ณป็ตฑๆœƒๅปบ็ซ‹ FHIR ่ณ‡ๆบ๏ผŒไธฆๆŒ‡ๆดพไผบๆœๅ™จ ID๏ผŒๅฐฑๅƒๆ˜ฏไฝฟ็”จ projects.locations.datasets.fhirStores.fhir.create ๅปบ็ซ‹่ณ‡ๆบไธ€ๆจฃใ€‚

่ฆๆฑ‚ไธป้ซ”ๅฟ…้ ˆๅŒ…ๅซ JSON ็ทจ็ขผ็š„ FHIR ่ณ‡ๆบ๏ผŒ่ฆๆฑ‚ๆจ™้ ญๅ‰‡ๅฟ…้ ˆๅŒ…ๅซ Content-Type: application/fhir+jsonใ€‚

ๅœจ Cloud Healthcare API ็ฌฌ 1 ็‰ˆไธญ๏ผŒๆขไปถๅผไฝœๆฅญๆœƒๅฐˆ้–€ไฝฟ็”จ identifier ๆœๅฐ‹ๅƒๆ•ธ (ๅฆ‚ๆžœ FHIR ่ณ‡ๆบ้กžๅž‹ๆœ‰้€™ๅ€‹ๅƒๆ•ธ)๏ผŒๅˆคๆ–ทๅ“ชไบ› FHIR ่ณ‡ๆบ็ฌฆๅˆๆขไปถๅผๆœๅฐ‹ๆŸฅ่ฉขใ€‚

REST

ไปฅไธ‹็ฏ„ไพ‹่ชชๆ˜Žๅฆ‚ไฝ•ไฝฟ็”จ curl ๅ’Œ PowerShell ๅ‚ณ้€ PUT ่ฆๆฑ‚๏ผŒ่—‰็”ฑ Observation ็š„ ID (my-code-system ไธญ็š„ ABC-12345) ็ทจ่ผฏ Observation ่ณ‡ๆบใ€‚Observation ๆœƒๆไพ›็—…ๆ‚ฃๆฏๅˆ†้˜ๅฟƒ่ทณๆฌกๆ•ธ (BPM) ็š„ๆธฌ้‡็ตๆžœใ€‚

ไฝฟ็”จไปปไฝ•่ฆๆฑ‚่ณ‡ๆ–™ไน‹ๅ‰๏ผŒ่ซ‹ๅ…ˆๆ›ฟๆ›ไปฅไธ‹้ …็›ฎ๏ผš

  • PROJECT_ID๏ผšๆ‚จ็š„ Google Cloud ๅฐˆๆกˆ ID
  • LOCATION๏ผš่ณ‡ๆ–™้›†ไฝ็ฝฎ
  • DATASET_ID๏ผšFHIR ๅ„ฒๅญ˜ๅบซ็š„็ˆถ้ …่ณ‡ๆ–™้›†
  • FHIR_STORE_ID๏ผšFHIR ๅ„ฒๅญ˜ๅบซ ID
  • PATIENT_ID๏ผš็—…ๆ‚ฃ่ณ‡ๆบ ID
  • ENCOUNTER_ID๏ผšๆœƒ่จบ่ณ‡ๆบ ID
  • BPM_VALUE๏ผšObservation ่ณ‡ๆบไธญ็š„ๆฏๅˆ†้˜ๅฟƒ่ทณๆ•ธ (BPM) ๅ€ผ

JSON ่ฆๆฑ‚ไธป้ซ”๏ผš

{
  "resourceType": "Observation",
  "status": "final",
  "subject": {
    "reference": "Patient/PATIENT_ID"
  },
  "effectiveDateTime": "2020-01-01T00:00:00+00:00",
  "identifier": [
    {
      "system": "my-code-system",
      "value": "ABC-12345"
    }
  ],
  "code": {
    "coding": [
      {
        "system": "http://loinc.org",
        "code": "8867-4",
        "display": "Heart rate"
      }
    ]
  },
  "valueQuantity": {
    "value": BPM_VALUE,
    "unit": "bpm"
  },
  "encounter": {
    "reference": "Encounter/ENCOUNTER_ID"
  }
}

ๅฆ‚่ฆๅ‚ณ้€่ฆๆฑ‚๏ผŒ่ซ‹้ธๆ“‡ไปฅไธ‹ๅ…ถไธญไธ€ๅ€‹้ธ้ …๏ผš

curl

ๅฐ‡่ฆๆฑ‚ไธป้ซ”ๅ„ฒๅญ˜ๅœจๅ็‚บ request.json ็š„ๆช”ๆกˆไธญใ€‚ ๅœจ็ต‚็ซฏๆฉŸไธญๅŸท่กŒไธ‹ๅˆ—ๆŒ‡ไปค๏ผŒๅœจ็›ฎๅ‰็›ฎ้Œ„ไธญๅปบ็ซ‹ๆˆ–่ฆ†ๅฏซ้€™ๅ€‹ๆช”ๆกˆ๏ผš

cat > request.json << 'EOF'
{
  "resourceType": "Observation",
  "status": "final",
  "subject": {
    "reference": "Patient/PATIENT_ID"
  },
  "effectiveDateTime": "2020-01-01T00:00:00+00:00",
  "identifier": [
    {
      "system": "my-code-system",
      "value": "ABC-12345"
    }
  ],
  "code": {
    "coding": [
      {
        "system": "http://loinc.org",
        "code": "8867-4",
        "display": "Heart rate"
      }
    ]
  },
  "valueQuantity": {
    "value": BPM_VALUE,
    "unit": "bpm"
  },
  "encounter": {
    "reference": "Encounter/ENCOUNTER_ID"
  }
}
EOF

ๆŽฅ่‘—๏ผŒ่ซ‹ๅŸท่กŒไธ‹ๅˆ—ๆŒ‡ไปคไพ†ๅ‚ณ้€ REST ่ฆๆฑ‚๏ผš

curl -X PUT \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/fhirStores/FHIR_STORE_ID/fhir/Observation?identifier=my-code-system|ABC-12345"

PowerShell

ๅฐ‡่ฆๆฑ‚ไธป้ซ”ๅ„ฒๅญ˜ๅœจๅ็‚บ request.json ็š„ๆช”ๆกˆไธญใ€‚ ๅœจ็ต‚็ซฏๆฉŸไธญๅŸท่กŒไธ‹ๅˆ—ๆŒ‡ไปค๏ผŒๅœจ็›ฎๅ‰็›ฎ้Œ„ไธญๅปบ็ซ‹ๆˆ–่ฆ†ๅฏซ้€™ๅ€‹ๆช”ๆกˆ๏ผš

@'
{
  "resourceType": "Observation",
  "status": "final",
  "subject": {
    "reference": "Patient/PATIENT_ID"
  },
  "effectiveDateTime": "2020-01-01T00:00:00+00:00",
  "identifier": [
    {
      "system": "my-code-system",
      "value": "ABC-12345"
    }
  ],
  "code": {
    "coding": [
      {
        "system": "http://loinc.org",
        "code": "8867-4",
        "display": "Heart rate"
      }
    ]
  },
  "valueQuantity": {
    "value": BPM_VALUE,
    "unit": "bpm"
  },
  "encounter": {
    "reference": "Encounter/ENCOUNTER_ID"
  }
}
'@  | Out-File -FilePath request.json -Encoding utf8

ๆŽฅ่‘—๏ผŒ่ซ‹ๅŸท่กŒไธ‹ๅˆ—ๆŒ‡ไปคไพ†ๅ‚ณ้€ REST ่ฆๆฑ‚๏ผš

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method PUT `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/fhirStores/FHIR_STORE_ID/fhir/Observation?identifier=my-code-system|ABC-12345" | Select-Object -Expand Content

APIs Explorer

่ค‡่ฃฝ่ฆๆฑ‚ๅ…งๆ–‡ไธฆ้–‹ๅ•Ÿๆ–นๆณ•ๅƒ่€ƒ่ณ‡ๆ–™้ ้ขใ€‚็ณป็ตฑๆœƒๅœจ้ ้ขๅณๅด้–‹ๅ•Ÿ APIs Explorer ้ขๆฟใ€‚ๆ‚จๅฏไปฅไฝฟ็”จ้€™้ …ๅทฅๅ…ทไพ†ๅ‚ณ้€่ฆๆฑ‚ใ€‚ๅฐ‡่ฆๆฑ‚ๅ…งๆ–‡่ฒผๅˆฐ้€™้ …ๅทฅๅ…ทไธญ๏ผŒไธฆๅกซๅฆฅๅ…ถไป–ๅฟ…ๅกซๆฌ„ไฝ๏ผŒ็„ถๅพŒๆŒ‰ไธ€ไธ‹ใ€ŒExecuteใ€(ๅŸท่กŒ)ใ€‚

ๆ‚จๆ‡‰่ฉฒๆœƒๆ”ถๅˆฐๅฆ‚ไธ‹็š„ JSON ๅ›žๆ‡‰๏ผš

ไฟฎ่ฃœ FHIR ่ณ‡ๆบ

ไธ‹ๅˆ—็ฏ„ไพ‹่ชชๆ˜Žๅฆ‚ไฝ•ๅ‘ผๅซ projects.locations.datasets.fhirStores.fhir.patch ๆ–นๆณ•๏ผŒไฟฎ่ฃœ FHIR ่ณ‡ๆบใ€‚้€™ๅ€‹ๆ–นๆณ•ๆœƒๅฏฆไฝœ FHIR ๆจ™ๆบ–ไฟฎ่ฃœไบ’ๅ‹• (DSTU2ใ€STU3ใ€R4 ๅ’Œ R5)ใ€‚

ไฟฎ่ฃœ่ณ‡ๆบๆ™‚๏ผŒๆ‚จๆœƒๅฅ—็”จ JSON ไฟฎ่ฃœๆ–‡ไปถๆŒ‡ๅฎš็š„ไฝœๆฅญ๏ผŒๆ›ดๆ–ฐ่ณ‡ๆบ็š„้ƒจๅˆ†ๅ…งๅฎนใ€‚

่ฆๆฑ‚ๅฟ…้ ˆๅŒ…ๅซ JSON ไฟฎ่ฃœ็จ‹ๅผๆ–‡ไปถ๏ผŒไธ”่ฆๆฑ‚ๆจ™้ ญๅฟ…้ ˆๅŒ…ๅซ Content-Type: application/json-patch+jsonใ€‚

ไธ‹ๅˆ—็ฏ„ไพ‹่ชชๆ˜Žๅฆ‚ไฝ•ไฟฎ่ฃœ Observation ่ณ‡ๆบใ€‚็—…ๆ‚ฃๆฏๅˆ†้˜ๅฟƒ่ทณๆฌกๆ•ธ (BPM) ็š„ Observation ๆœƒไฝฟ็”จ replace patch ไฝœๆฅญๆ›ดๆ–ฐใ€‚

ไธ‹ๅˆ— REST ็ฏ„ไพ‹้ฉ็”จๆ–ผ R4 FHIR ๅ„ฒๅญ˜ๅบซใ€‚Goใ€Javaใ€Node.js ๅ’Œ Python ็ฏ„ไพ‹้ฉ็”จๆ–ผ STU3 FHIR ๅญ˜ๆ”พๅ€ใ€‚

REST

ไฝฟ็”จไปปไฝ•่ฆๆฑ‚่ณ‡ๆ–™ไน‹ๅ‰๏ผŒ่ซ‹ๅ…ˆๆ›ฟๆ›ไปฅไธ‹้ …็›ฎ๏ผš

  • PROJECT_ID๏ผšๆ‚จ็š„ Google Cloud ๅฐˆๆกˆ ID
  • LOCATION๏ผš่ณ‡ๆ–™้›†ไฝ็ฝฎ
  • DATASET_ID๏ผšFHIR ๅ„ฒๅญ˜ๅบซ็š„็ˆถ้ …่ณ‡ๆ–™้›†
  • FHIR_STORE_ID๏ผšFHIR ๅ„ฒๅญ˜ๅบซ ID
  • OBSERVATION_ID๏ผšObservation ่ณ‡ๆบ ID
  • BPM_VALUE๏ผšไฟฎ่ฃœ็š„ Observation ่ณ‡ๆบไธญๆฏๅˆ†้˜ๅฟƒ่ทณๆ•ธ (BPM) ๅ€ผ

JSON ่ฆๆฑ‚ไธป้ซ”๏ผš

[
  {
    "op": "replace",
    "path": "/valueQuantity/value",
    "value": BPM_VALUE
  }
]

ๅฆ‚่ฆๅ‚ณ้€่ฆๆฑ‚๏ผŒ่ซ‹้ธๆ“‡ไปฅไธ‹ๅ…ถไธญไธ€ๅ€‹้ธ้ …๏ผš

curl

ๅฐ‡่ฆๆฑ‚ไธป้ซ”ๅ„ฒๅญ˜ๅœจๅ็‚บ request.json ็š„ๆช”ๆกˆไธญใ€‚ ๅœจ็ต‚็ซฏๆฉŸไธญๅŸท่กŒไธ‹ๅˆ—ๆŒ‡ไปค๏ผŒๅœจ็›ฎๅ‰็›ฎ้Œ„ไธญๅปบ็ซ‹ๆˆ–่ฆ†ๅฏซ้€™ๅ€‹ๆช”ๆกˆ๏ผš

cat > request.json << 'EOF'
[
  {
    "op": "replace",
    "path": "/valueQuantity/value",
    "value": BPM_VALUE
  }
]
EOF

ๆŽฅ่‘—๏ผŒ่ซ‹ๅŸท่กŒไธ‹ๅˆ—ๆŒ‡ไปคไพ†ๅ‚ณ้€ REST ่ฆๆฑ‚๏ผš

curl -X PATCH \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json-patch+json" \
-d @request.json \
"https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/fhirStores/FHIR_STORE_ID/fhir/Observation/OBSERVATION_ID"

PowerShell

ๅฐ‡่ฆๆฑ‚ไธป้ซ”ๅ„ฒๅญ˜ๅœจๅ็‚บ request.json ็š„ๆช”ๆกˆไธญใ€‚ ๅœจ็ต‚็ซฏๆฉŸไธญๅŸท่กŒไธ‹ๅˆ—ๆŒ‡ไปค๏ผŒๅœจ็›ฎๅ‰็›ฎ้Œ„ไธญๅปบ็ซ‹ๆˆ–่ฆ†ๅฏซ้€™ๅ€‹ๆช”ๆกˆ๏ผš

@'
[
  {
    "op": "replace",
    "path": "/valueQuantity/value",
    "value": BPM_VALUE
  }
]
'@  | Out-File -FilePath request.json -Encoding utf8

ๆŽฅ่‘—๏ผŒ่ซ‹ๅŸท่กŒไธ‹ๅˆ—ๆŒ‡ไปคไพ†ๅ‚ณ้€ REST ่ฆๆฑ‚๏ผš

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method PATCH `
-Headers $headers `
-ContentType: "application/json-patch+json" `
-InFile request.json `
-Uri "https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/fhirStores/FHIR_STORE_ID/fhir/Observation/OBSERVATION_ID" | Select-Object -Expand Content

ๆ‚จๆ‡‰่ฉฒๆœƒๆ”ถๅˆฐๅฆ‚ไธ‹็š„ JSON ๅ›žๆ‡‰๏ผš

Go

import (
	"bytes"
	"context"
	"encoding/json"
	"fmt"
	"io"

	healthcare "google.golang.org/api/healthcare/v1"
)

// patchFHIRResource patches an FHIR resource to be active or not.
func patchFHIRResource(w io.Writer, projectID, location, datasetID, fhirStoreID, resourceType, fhirResourceID string, active bool) error {
	ctx := context.Background()

	healthcareService, err := healthcare.NewService(ctx)
	if err != nil {
		return fmt.Errorf("healthcare.NewService: %w", err)
	}

	fhirService := healthcareService.Projects.Locations.Datasets.FhirStores.Fhir

	// The following payload works with a Patient resource and is not intended to work with
	// other types of FHIR resources. If necessary, supply a new payload with data that
	// corresponds to the FHIR resource you are patching.
	payload := []map[string]interface{}{
		{
			"op":    "replace",
			"path":  "/active",
			"value": active,
		},
	}
	jsonPayload, err := json.Marshal(payload)
	if err != nil {
		return fmt.Errorf("json.Encode: %w", err)
	}

	name := fmt.Sprintf("projects/%s/locations/%s/datasets/%s/fhirStores/%s/fhir/%s/%s", projectID, location, datasetID, fhirStoreID, resourceType, fhirResourceID)

	call := fhirService.Patch(name, bytes.NewReader(jsonPayload))
	call.Header().Set("Content-Type", "application/json-patch+json")
	resp, err := call.Do()
	if err != nil {
		return fmt.Errorf("Patch: %w", err)
	}
	defer resp.Body.Close()

	respBytes, err := io.ReadAll(resp.Body)
	if err != nil {
		return fmt.Errorf("could not read response: %w", err)
	}

	if resp.StatusCode > 299 {
		return fmt.Errorf("Patch: status %d %s: %s", resp.StatusCode, resp.Status, respBytes)
	}
	fmt.Fprintf(w, "%s", respBytes)

	return nil
}

Java

import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.gson.GsonFactory;
import com.google.api.services.healthcare.v1.CloudHealthcare;
import com.google.api.services.healthcare.v1.CloudHealthcareScopes;
import com.google.auth.http.HttpCredentialsAdapter;
import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.Collections;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.client.methods.RequestBuilder;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.HttpClients;

public class FhirResourcePatch {
  private static final String FHIR_NAME =
      "projects/%s/locations/%s/datasets/%s/fhirStores/%s/fhir/%s/%s";
  private static final JsonFactory JSON_FACTORY = new GsonFactory();
  private static final NetHttpTransport HTTP_TRANSPORT = new NetHttpTransport();

  public static void fhirResourcePatch(String resourceName, String data)
      throws IOException, URISyntaxException {
    // String resourceName =
    //    String.format(
    //        FHIR_NAME, "project-id", "region-id", "dataset-id", "store-id", "resource-type",
    // "resource-id");
    // The following data works with a Patient resource and is not intended to work with
    // other types of FHIR resources. If necessary, supply new values for data that
    // correspond to the FHIR resource you are patching.
    // String data = "[{\"op\": \"replace\", \"path\": \"/active\", \"value\": false}]";

    // Initialize the client, which will be used to interact with the service.
    CloudHealthcare client = createClient();

    HttpClient httpClient = HttpClients.createDefault();
    String uri = String.format("%sv1/%s", client.getRootUrl(), resourceName);
    URIBuilder uriBuilder = new URIBuilder(uri).setParameter("access_token", getAccessToken());
    StringEntity requestEntity = new StringEntity(data);

    HttpUriRequest request =
        RequestBuilder.patch(uriBuilder.build())
            .setEntity(requestEntity)
            .addHeader("Content-Type", "application/json-patch+json")
            .addHeader("Accept-Charset", "utf-8")
            .addHeader("Accept", "application/fhir+json; charset=utf-8")
            .build();

    // Execute the request and process the results.
    HttpResponse response = httpClient.execute(request);
    HttpEntity responseEntity = response.getEntity();
    if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
      System.err.print(
          String.format(
              "Exception patching FHIR resource: %s\n", response.getStatusLine().toString()));
      responseEntity.writeTo(System.err);
      throw new RuntimeException();
    }
    System.out.println("FHIR resource patched: ");
    responseEntity.writeTo(System.out);
  }

  private static CloudHealthcare createClient() throws IOException {
    // Use Application Default Credentials (ADC) to authenticate the requests
    // For more information see https://cloud.google.com/docs/authentication/production
    GoogleCredentials credential =
        GoogleCredentials.getApplicationDefault()
            .createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));

    // Create a HttpRequestInitializer, which will provide a baseline configuration to all requests.
    HttpRequestInitializer requestInitializer =
        request -> {
          new HttpCredentialsAdapter(credential).initialize(request);
          request.setConnectTimeout(60000); // 1 minute connect timeout
          request.setReadTimeout(60000); // 1 minute read timeout
        };

    // Build the client for interacting with the service.
    return new CloudHealthcare.Builder(HTTP_TRANSPORT, JSON_FACTORY, requestInitializer)
        .setApplicationName("your-application-name")
        .build();
  }

  private static String getAccessToken() throws IOException {
    GoogleCredentials credential =
        GoogleCredentials.getApplicationDefault()
            .createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));

    return credential.refreshAccessToken().getTokenValue();
  }
}

Node.js

const google = require('@googleapis/healthcare');
const healthcare = google.healthcare({
  version: 'v1',
  auth: new google.auth.GoogleAuth({
    scopes: ['https://www.googleapis.com/auth/cloud-platform'],
  }),
  headers: {'Content-Type': 'application/json-patch+json'},
});

async function patchFhirResource() {
  // TODO(developer): replace patchOptions with your desired JSON patch body
  const patchOptions = [{op: 'replace', path: '/active', value: false}];

  // TODO(developer): uncomment these lines before running the sample
  // const cloudRegion = 'us-central1';
  // const projectId = 'adjective-noun-123';
  // const datasetId = 'my-dataset';
  // const fhirStoreId = 'my-fhir-store';
  // const resourceType = 'Patient';
  // const resourceId = '16e8a860-33b3-49be-9b03-de979feed14a';
  const name = `projects/${projectId}/locations/${cloudRegion}/datasets/${datasetId}/fhirStores/${fhirStoreId}/fhir/${resourceType}/${resourceId}`;
  const request = {
    name,
    requestBody: patchOptions,
  };

  await healthcare.projects.locations.datasets.fhirStores.fhir.patch(request);
  console.log(`Patched ${resourceType} resource`);
}

patchFhirResource();

Python

# Imports the types Dict and Any for runtime type hints.
from typing import Any, Dict  # noqa: E402


def patch_resource(
    project_id: str,
    location: str,
    dataset_id: str,
    fhir_store_id: str,
    resource_type: str,
    resource_id: str,
) -> Dict[str, Any]:
    """Updates part of an existing FHIR resource by applying the operations specified in a [JSON Patch](http://jsonpatch.com/) document.

    See
    https://github.com/GoogleCloudPlatform/python-docs-samples/tree/main/healthcare/api-client/v1/fhir
    before running the sample.
    See
    https://googleapis.github.io/google-api-python-client/docs/dyn/healthcare_v1.projects.locations.datasets.fhirStores.fhir.html#patch
    for the Python API reference.

    Args:
      project_id: The project ID or project number of the Cloud project you want
        to use.
      location: The name of the parent dataset's location.
      dataset_id: The name of the parent dataset.
      fhir_store_id: The name of the FHIR store.
      resource_type: The type of the FHIR resource.
      resource_id: The "logical id" of the resource. The ID is assigned by the
        server.

    Returns:
      A dict representing the patched FHIR resource.
    """
    # Imports the Google API Discovery Service.
    from googleapiclient import discovery

    api_version = "v1"
    service_name = "healthcare"

    # Returns an authorized API client by discovering the Healthcare API
    # and using GOOGLE_APPLICATION_CREDENTIALS environment variable.
    client = discovery.build(service_name, api_version)

    # TODO(developer): Uncomment these lines and replace with your values.
    # project_id = 'my-project'
    # location = 'us-central1'
    # dataset_id = 'my-dataset'
    # fhir_store_id = 'my-fhir-store'
    # resource_type = 'Patient'
    # resource_id = 'b682d-0e-4843-a4a9-78c9ac64'
    fhir_store_parent = (
        f"projects/{project_id}/locations/{location}/datasets/{dataset_id}"
    )
    fhir_resource_path = f"{fhir_store_parent}/fhirStores/{fhir_store_id}/fhir/{resource_type}/{resource_id}"

    # The following sample body works with a Patient resource and isn't guaranteed
    # to work with other types of FHIR resources. If necessary,
    # supply a new body with data that corresponds to the resource you
    # are updating.
    patient_body = [{"op": "replace", "path": "/active", "value": False}]

    request = (
        client.projects()
        .locations()
        .datasets()
        .fhirStores()
        .fhir()
        .patch(name=fhir_resource_path, body=patient_body)
    )

    # Sets required application/json-patch+json header.
    # See https://tools.ietf.org/html/rfc6902 for more information.
    request.headers["content-type"] = "application/json-patch+json"

    response = request.execute()

    print(
        f"Patched {resource_type} resource with ID {resource_id}:\n"
        f" {json.dumps(response, indent=2)}"
    )

    return response

ๅœจ FHIR ่ปŸ้ซ”ๅŒ…ไธญๅŸท่กŒ PATCH ่ฆๆฑ‚

ๆ‚จๅฏไปฅๅœจ FHIR ็ต„ๅˆไธญๆŒ‡ๅฎš PATCH ่ฆๆฑ‚ (ๅƒ…้™ FHIR R4)ใ€‚ๅœจ FHIR ็ต„ๅˆไธญๅŸท่กŒ PATCH ่ฆๆฑ‚๏ผŒๅฏ่ฎ“ๆ‚จไธ€ๆฌกไฟฎ่ฃœๅคšๅ€‹ FHIR ่ณ‡ๆบ๏ผŒไธๅฟ…็‚บๆฏๅ€‹ FHIR ่ณ‡ๆบๆๅ‡บๅ€‹ๅˆฅ็š„ไฟฎ่ฃœ่ฆๆฑ‚ใ€‚

ๅฆ‚่ฆๅœจๅฅ—ไปถไธญๆๅ‡บ PATCH ่ฆๆฑ‚๏ผŒ่ซ‹ๅœจ่ฆๆฑ‚ไธญ็š„ resource ็‰ฉไปถไธญๆŒ‡ๅฎšไธ‹ๅˆ—่ณ‡่จŠ๏ผš

  • ่จญ็‚บ Binary ็š„ resourceType ๆฌ„ไฝ
  • ่จญ็‚บ application/json-patch+json ็š„ contentType ๆฌ„ไฝ
  • ไปฅ Base64 ็ทจ็ขผ็š„ไฟฎ่ฃœ็จ‹ๅผไธป้ซ”

็ขบ่ช resource ็‰ฉไปถๅฆ‚ไธ‹ๆ‰€็คบ๏ผš

"resource": {
  "resourceType": "Binary",
  "contentType": "application/json-patch+json",
  "data": "WyB7ICJvcCI6ICJyZXBsYWNlIiwgInBhdGgiOiAiL2JpcnRoRGF0ZSIsICJ2YWx1ZSI6ICIxOTkwLTAxLTAxIiB9IF0K"
}

ไปฅไธ‹้กฏ็คบๅœจ data ๆฌ„ไฝไธญไปฅ Base64 ็ทจ็ขผ็š„ไฟฎ่ฃœ็จ‹ๅผไธป้ซ”๏ผš

[
  {
    "op": "replace",
    "path": "/birthdate",
    "value": "1990-01-01"
  }
]

ไธ‹ๅˆ—็ฏ„ไพ‹่ชชๆ˜Žๅฆ‚ไฝ•ๅœจๅฅ—ไปถไธญไฝฟ็”จ PATCH ่ฆๆฑ‚๏ผŒไฟฎ่ฃœๆ‚จๅœจใ€Œๅปบ็ซ‹ FHIR ่ณ‡ๆบใ€ไธญๅปบ็ซ‹็š„ Patient ่ณ‡ๆบ๏ผŒๅฐ‡ birthDate ๅ€ผ่จญ็‚บ 1990-01-01๏ผš

ไฝฟ็”จไปปไฝ•่ฆๆฑ‚่ณ‡ๆ–™ไน‹ๅ‰๏ผŒ่ซ‹ๅ…ˆๆ›ฟๆ›ไปฅไธ‹้ …็›ฎ๏ผš

  • PROJECT_ID๏ผšๆ‚จ็š„ Google Cloud ๅฐˆๆกˆ ID
  • LOCATION๏ผš็ˆถ้ …่ณ‡ๆ–™้›†็š„ไฝ็ฝฎ
  • DATASET_ID๏ผšFHIR ๅ„ฒๅญ˜ๅบซ็š„็ˆถ้ …่ณ‡ๆ–™้›†
  • FHIR_STORE_ID๏ผšFHIR ๅ„ฒๅญ˜ๅบซ ID
  • PATIENT_ID๏ผš็พๆœ‰ Patient ่ณ‡ๆบ็š„ ID

JSON ่ฆๆฑ‚ไธป้ซ”๏ผš

{
  "type": "transaction",
  "resourceType": "Bundle",
  "entry": [
    {
      "request": {
        "method": "PATCH",
        "url": "Patient/PATIENT_ID"
      },
      "resource": {
        "resourceType": "Binary",
        "contentType": "application/json-patch+json",
        "data": "WyB7ICJvcCI6ICJyZXBsYWNlIiwgInBhdGgiOiAiL2JpcnRoRGF0ZSIsICJ2YWx1ZSI6ICIxOTkwLTAxLTAxIiB9IF0K"
      }
    }
  ]
}

ๅฆ‚่ฆๅ‚ณ้€่ฆๆฑ‚๏ผŒ่ซ‹้ธๆ“‡ไปฅไธ‹ๅ…ถไธญไธ€ๅ€‹้ธ้ …๏ผš

curl

ๅฐ‡่ฆๆฑ‚ไธป้ซ”ๅ„ฒๅญ˜ๅœจๅ็‚บ request.json ็š„ๆช”ๆกˆไธญใ€‚ ๅœจ็ต‚็ซฏๆฉŸไธญๅŸท่กŒไธ‹ๅˆ—ๆŒ‡ไปค๏ผŒๅœจ็›ฎๅ‰็›ฎ้Œ„ไธญๅปบ็ซ‹ๆˆ–่ฆ†ๅฏซ้€™ๅ€‹ๆช”ๆกˆ๏ผš

cat > request.json << 'EOF'
{
  "type": "transaction",
  "resourceType": "Bundle",
  "entry": [
    {
      "request": {
        "method": "PATCH",
        "url": "Patient/PATIENT_ID"
      },
      "resource": {
        "resourceType": "Binary",
        "contentType": "application/json-patch+json",
        "data": "WyB7ICJvcCI6ICJyZXBsYWNlIiwgInBhdGgiOiAiL2JpcnRoRGF0ZSIsICJ2YWx1ZSI6ICIxOTkwLTAxLTAxIiB9IF0K"
      }
    }
  ]
}
EOF

ๆŽฅ่‘—๏ผŒ่ซ‹ๅŸท่กŒไธ‹ๅˆ—ๆŒ‡ไปคไพ†ๅ‚ณ้€ REST ่ฆๆฑ‚๏ผš

curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/fhir+json" \
-d @request.json \
"https://healthcare.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/fhirStores/FHIR_STORE_ID/fhir"

PowerShell

ๅฐ‡่ฆๆฑ‚ไธป้ซ”ๅ„ฒๅญ˜ๅœจๅ็‚บ request.json ็š„ๆช”ๆกˆไธญใ€‚ ๅœจ็ต‚็ซฏๆฉŸไธญๅŸท่กŒไธ‹ๅˆ—ๆŒ‡ไปค๏ผŒๅœจ็›ฎๅ‰็›ฎ้Œ„ไธญๅปบ็ซ‹ๆˆ–่ฆ†ๅฏซ้€™ๅ€‹ๆช”ๆกˆ๏ผš

@'
{
  "type": "transaction",
  "resourceType": "Bundle",
  "entry": [
    {
      "request": {
        "method": "PATCH",
        "url": "Patient/PATIENT_ID"
      },
      "resource": {
        "resourceType": "Binary",
        "contentType": "application/json-patch+json",
        "data": "WyB7ICJvcCI6ICJyZXBsYWNlIiwgInBhdGgiOiAiL2JpcnRoRGF0ZSIsICJ2YWx1ZSI6ICIxOTkwLTAxLTAxIiB9IF0K"
      }
    }
  ]
}
'@  | Out-File -FilePath request.json -Encoding utf8

ๆŽฅ่‘—๏ผŒ่ซ‹ๅŸท่กŒไธ‹ๅˆ—ๆŒ‡ไปคไพ†ๅ‚ณ้€ REST ่ฆๆฑ‚๏ผš

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/fhir+json" `
-InFile request.json `
-Uri "https://healthcare.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/fhirStores/FHIR_STORE_ID/fhir" | Select-Object -Expand Content

ๆ‚จๆ‡‰่ฉฒๆœƒๆ”ถๅˆฐๅฆ‚ไธ‹็š„ JSON ๅ›žๆ‡‰๏ผš

ๆœ‰ๆขไปถๅœฐไฟฎ่ฃœ FHIR ่ณ‡ๆบ

ไธ‹ๅˆ—็ฏ„ไพ‹่ชชๆ˜Žๅฆ‚ไฝ•ๅ‘ผๅซ projects.locations.datasets.fhirStores.fhir.conditionalPatch ๆ–นๆณ•๏ผŒไฟฎ่ฃœ็ฌฆๅˆๆœๅฐ‹ๆŸฅ่ฉข็š„ FHIR ่ณ‡ๆบ๏ผŒ่€Œ้žไพ ID ่ญ˜ๅˆฅ่ณ‡ๆบใ€‚้€™ๅ€‹ๆ–นๆณ•ๆœƒๅฏฆไฝœ FHIR ๆจ™ๆบ–็š„ๆขไปถๅผไฟฎ่ฃœไบ’ๅ‹• (DSTU2ใ€STU3ใ€R4 ๅ’Œ R4)ใ€‚

ๆขไปถๅผไฟฎ่ฃœ็จ‹ๅผไธ€ๆฌกๅช่ƒฝๅฅ—็”จ่‡ณไธ€้ …่ณ‡ๆบใ€‚ๅฆ‚ๆžœๆœๅฐ‹ๆขไปถๆ‰พๅˆฐๅคšๅ€‹็›ธ็ฌฆ้ …็›ฎ๏ผŒ่ฆๆฑ‚ๆœƒๅ‚ณๅ›ž 412 Precondition Failed ้Œฏ่ชคใ€‚

ๅœจ Cloud Healthcare API ็ฌฌ 1 ็‰ˆไธญ๏ผŒๆขไปถๅผไฝœๆฅญๆœƒๅฐˆ้–€ไฝฟ็”จ identifier ๆœๅฐ‹ๅƒๆ•ธ (ๅฆ‚ๆžœ FHIR ่ณ‡ๆบ้กžๅž‹ๆœ‰้€™ๅ€‹ๅƒๆ•ธ)๏ผŒๅˆคๆ–ทๅ“ชไบ› FHIR ่ณ‡ๆบ็ฌฆๅˆๆขไปถๅผๆœๅฐ‹ๆŸฅ่ฉขใ€‚

REST

ไธ‹ๅˆ—็ฏ„ไพ‹่ชชๆ˜Žๅฆ‚ไฝ•ๅ‚ณ้€ PATCH ่ฆๆฑ‚๏ผŒๅœจ Observation ็š„ ID ็‚บ ABC-12345 ๆ™‚๏ผŒ็ทจ่ผฏ my-code-system ไธญ็š„ Observation ่ณ‡ๆบใ€‚็ณป็ตฑๆœƒไฝฟ็”จ replace patch ไฝœๆฅญ๏ผŒๆ›ดๆ–ฐ็—…ๆ‚ฃๆฏๅˆ†้˜ๅฟƒ่ทณๆฌกๆ•ธ (BPM) ็š„่ง€ๅฏŸ็ตๆžœใ€‚

ไฝฟ็”จไปปไฝ•่ฆๆฑ‚่ณ‡ๆ–™ไน‹ๅ‰๏ผŒ่ซ‹ๅ…ˆๆ›ฟๆ›ไปฅไธ‹้ …็›ฎ๏ผš

  • PROJECT_ID๏ผšๆ‚จ็š„ Google Cloud ๅฐˆๆกˆ ID
  • LOCATION๏ผš่ณ‡ๆ–™้›†ไฝ็ฝฎ
  • DATASET_ID๏ผšFHIR ๅ„ฒๅญ˜ๅบซ็š„็ˆถ้ …่ณ‡ๆ–™้›†
  • FHIR_STORE_ID๏ผšFHIR ๅ„ฒๅญ˜ๅบซ ID
  • BPM_VALUE๏ผšObservation ่ณ‡ๆบไธญ็š„ๆฏๅˆ†้˜ๅฟƒ่ทณๆ•ธ (BPM) ๅ€ผ

JSON ่ฆๆฑ‚ไธป้ซ”๏ผš

[
  {
    "op": "replace",
    "path": "/valueQuantity/value",
    "value": BPM_VALUE
  }
]

ๅฆ‚่ฆๅ‚ณ้€่ฆๆฑ‚๏ผŒ่ซ‹้ธๆ“‡ไปฅไธ‹ๅ…ถไธญไธ€ๅ€‹้ธ้ …๏ผš

curl

ๅฐ‡่ฆๆฑ‚ไธป้ซ”ๅ„ฒๅญ˜ๅœจๅ็‚บ request.json ็š„ๆช”ๆกˆไธญใ€‚ ๅœจ็ต‚็ซฏๆฉŸไธญๅŸท่กŒไธ‹ๅˆ—ๆŒ‡ไปค๏ผŒๅœจ็›ฎๅ‰็›ฎ้Œ„ไธญๅปบ็ซ‹ๆˆ–่ฆ†ๅฏซ้€™ๅ€‹ๆช”ๆกˆ๏ผš

cat > request.json << 'EOF'
[
  {
    "op": "replace",
    "path": "/valueQuantity/value",
    "value": BPM_VALUE
  }
]
EOF

ๆŽฅ่‘—๏ผŒ่ซ‹ๅŸท่กŒไธ‹ๅˆ—ๆŒ‡ไปคไพ†ๅ‚ณ้€ REST ่ฆๆฑ‚๏ผš

curl -X PATCH \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json-patch+json" \
-d @request.json \
"https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/fhirStores/FHIR_STORE_ID/fhir/Observation?identifier=my-code-system|ABC-12345"

PowerShell

ๅฐ‡่ฆๆฑ‚ไธป้ซ”ๅ„ฒๅญ˜ๅœจๅ็‚บ request.json ็š„ๆช”ๆกˆไธญใ€‚ ๅœจ็ต‚็ซฏๆฉŸไธญๅŸท่กŒไธ‹ๅˆ—ๆŒ‡ไปค๏ผŒๅœจ็›ฎๅ‰็›ฎ้Œ„ไธญๅปบ็ซ‹ๆˆ–่ฆ†ๅฏซ้€™ๅ€‹ๆช”ๆกˆ๏ผš

@'
[
  {
    "op": "replace",
    "path": "/valueQuantity/value",
    "value": BPM_VALUE
  }
]
'@  | Out-File -FilePath request.json -Encoding utf8

ๆŽฅ่‘—๏ผŒ่ซ‹ๅŸท่กŒไธ‹ๅˆ—ๆŒ‡ไปคไพ†ๅ‚ณ้€ REST ่ฆๆฑ‚๏ผš

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method PATCH `
-Headers $headers `
-ContentType: "application/json-patch+json" `
-InFile request.json `
-Uri "https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/fhirStores/FHIR_STORE_ID/fhir/Observation?identifier=my-code-system|ABC-12345" | Select-Object -Expand Content

APIs Explorer

่ค‡่ฃฝ่ฆๆฑ‚ๅ…งๆ–‡ไธฆ้–‹ๅ•Ÿๆ–นๆณ•ๅƒ่€ƒ่ณ‡ๆ–™้ ้ขใ€‚็ณป็ตฑๆœƒๅœจ้ ้ขๅณๅด้–‹ๅ•Ÿ APIs Explorer ้ขๆฟใ€‚ๆ‚จๅฏไปฅไฝฟ็”จ้€™้ …ๅทฅๅ…ทไพ†ๅ‚ณ้€่ฆๆฑ‚ใ€‚ๅฐ‡่ฆๆฑ‚ๅ…งๆ–‡่ฒผๅˆฐ้€™้ …ๅทฅๅ…ทไธญ๏ผŒไธฆๅกซๅฆฅๅ…ถไป–ๅฟ…ๅกซๆฌ„ไฝ๏ผŒ็„ถๅพŒๆŒ‰ไธ€ไธ‹ใ€ŒExecuteใ€(ๅŸท่กŒ)ใ€‚

ๆ‚จๆ‡‰่ฉฒๆœƒๆ”ถๅˆฐๅฆ‚ไธ‹็š„ JSON ๅ›žๆ‡‰๏ผš

ๅ–ๅพ— FHIR ่ณ‡ๆบ

ไธ‹ๅˆ—็ฏ„ไพ‹่ชชๆ˜Žๅฆ‚ไฝ•ๅ–ๅพ— FHIR ่ณ‡ๆบ็š„ๅ…งๅฎนใ€‚

ไธ‹ๅˆ— REST ็ฏ„ไพ‹้ฉ็”จๆ–ผ R4 FHIR ๅ„ฒๅญ˜ๅบซใ€‚Goใ€Javaใ€Node.js ๅ’Œ Python ็ฏ„ไพ‹้ฉ็”จๆ–ผ STU3 FHIR ๅญ˜ๆ”พๅ€ใ€‚

ๆŽงๅˆถๅฐ

  1. ๅ‰ๅพ€ Google Cloud ๆŽงๅˆถๅฐ็š„ใ€ŒFHIR viewerใ€้ ้ขใ€‚

    ๅ‰ๅพ€ FHIR ๆชข่ฆ–ๅ™จ

  2. ๅœจใ€ŒFHIR Storeใ€(FHIR ๅ„ฒๅญ˜ๅบซ) ไธ‹ๆ‹‰ๅผๆธ…ๅ–ฎไธญ้ธๅ–่ณ‡ๆ–™้›†๏ผŒ็„ถๅพŒ้ธๅ–่ณ‡ๆ–™้›†ไธญ็š„ FHIR ๅ„ฒๅญ˜ๅบซใ€‚

  3. ๅฆ‚่ฆ็ฏฉ้ธ่ณ‡ๆบ้กžๅž‹ๆธ…ๅ–ฎ๏ผŒ่ซ‹ๆœๅฐ‹่ฆ้กฏ็คบ็š„่ณ‡ๆบ้กžๅž‹ใ€‚

  4. ๆŒ‰ไธ€ไธ‹ใ€Œ่ณ‡ๆบ้กžๅž‹ใ€ๆฌ„ไฝใ€‚

  5. ๅœจ้šจๅณๅ‡บ็พ็š„ใ€ŒPropertiesใ€(ๅฑฌๆ€ง) ไธ‹ๆ‹‰ๅผๆธ…ๅ–ฎไธญ้ธๅ–ใ€ŒResource Typeใ€(่ณ‡ๆบ้กžๅž‹)ใ€‚

  6. ่ผธๅ…ฅ่ณ‡ๆบ้กžๅž‹ใ€‚

  7. ๅฆ‚่ฆๆœๅฐ‹ๅ…ถไป–่ณ‡ๆบ้กžๅž‹๏ผŒ่ซ‹ๅพž้šจๅณ้กฏ็คบ็š„ใ€ŒOperatorsใ€(้‹็ฎ—ๅญ) ไธ‹ๆ‹‰ๅผๆธ…ๅ–ฎไธญ้ธๅ–ใ€ŒORใ€(ๆˆ–)๏ผŒ็„ถๅพŒ่ผธๅ…ฅๅ…ถไป–่ณ‡ๆบ้กžๅž‹ใ€‚

  8. ๅœจ่ณ‡ๆบ้กžๅž‹ๆธ…ๅ–ฎไธญ๏ผŒ้ธๅ–่ฆๅ–ๅพ—ๅ…งๅฎน็š„่ณ‡ๆบ้กžๅž‹ใ€‚

  9. ๅœจ้šจๅณ้กฏ็คบ็š„่ณ‡ๆบ่กจๆ ผไธญ๏ผŒ้ธๅ–ๆˆ–ๆœๅฐ‹่ณ‡ๆบใ€‚

REST

ไธ‹ๅˆ—็ฏ„ไพ‹่ชชๆ˜Žๅฆ‚ไฝ•ไฝฟ็”จ projects.locations.datasets.fhirStores.fhir.read ๆ–นๆณ•๏ผŒๅ–ๅพ—ๅ‰ไธ€็ฏ€ไธญๅปบ็ซ‹็š„ Observation ่ณ‡ๆบ่ฉณ็ดฐ่ณ‡ๆ–™ใ€‚

ไฝฟ็”จไปปไฝ•่ฆๆฑ‚่ณ‡ๆ–™ไน‹ๅ‰๏ผŒ่ซ‹ๅ…ˆๆ›ฟๆ›ไปฅไธ‹้ …็›ฎ๏ผš

  • PROJECT_ID๏ผšๆ‚จ็š„ Google Cloud ๅฐˆๆกˆ ID
  • LOCATION๏ผš่ณ‡ๆ–™้›†ไฝ็ฝฎ
  • DATASET_ID๏ผšFHIR ๅ„ฒๅญ˜ๅบซ็š„็ˆถ้ …่ณ‡ๆ–™้›†
  • FHIR_STORE_ID๏ผšFHIR ๅ„ฒๅญ˜ๅบซ ID
  • OBSERVATION_ID๏ผšObservation ่ณ‡ๆบ ID

ๅฆ‚่ฆๅ‚ณ้€่ฆๆฑ‚๏ผŒ่ซ‹้ธๆ“‡ไปฅไธ‹ๅ…ถไธญไธ€ๅ€‹้ธ้ …๏ผš

curl

ๅŸท่กŒไธ‹ๅˆ—ๆŒ‡ไปค๏ผš

curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/fhirStores/FHIR_STORE_ID/fhir/Observation/OBSERVATION_ID"

PowerShell

ๅŸท่กŒไธ‹ๅˆ—ๆŒ‡ไปค๏ผš

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method GET `
-Headers $headers `
-Uri "https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/fhirStores/FHIR_STORE_ID/fhir/Observation/OBSERVATION_ID" | Select-Object -Expand Content

APIs Explorer

้–‹ๅ•Ÿๆ–นๆณ•ๅƒ่€ƒ้ ้ขใ€‚็ณป็ตฑๆœƒๅœจ้ ้ขๅณๅด้–‹ๅ•Ÿ APIs Explorer ้ขๆฟใ€‚ๆ‚จๅฏไปฅไฝฟ็”จ้€™้ …ๅทฅๅ…ทไพ†ๅ‚ณ้€่ฆๆฑ‚ใ€‚ๅฎŒๆˆไปปไฝ•ๅฟ…ๅกซๆฌ„ไฝ๏ผŒ็„ถๅพŒๆŒ‰ไธ€ไธ‹ใ€ŒๅŸท่กŒใ€ใ€‚

ๆ‚จๆ‡‰่ฉฒๆœƒๆ”ถๅˆฐๅฆ‚ไธ‹็š„ JSON ๅ›žๆ‡‰๏ผš

Go

import (
	"context"
	"fmt"
	"io"

	healthcare "google.golang.org/api/healthcare/v1"
)

// getFHIRResource gets an FHIR resource.
func getFHIRResource(w io.Writer, projectID, location, datasetID, fhirStoreID, resourceType, fhirResourceID string) error {
	ctx := context.Background()

	healthcareService, err := healthcare.NewService(ctx)
	if err != nil {
		return fmt.Errorf("healthcare.NewService: %w", err)
	}

	fhirService := healthcareService.Projects.Locations.Datasets.FhirStores.Fhir

	name := fmt.Sprintf("projects/%s/locations/%s/datasets/%s/fhirStores/%s/fhir/%s/%s", projectID, location, datasetID, fhirStoreID, resourceType, fhirResourceID)

	call := fhirService.Read(name)
	call.Header().Set("Content-Type", "application/fhir+json;charset=utf-8")
	resp, err := call.Do()
	if err != nil {
		return fmt.Errorf("Read: %w", err)
	}

	defer resp.Body.Close()

	respBytes, err := io.ReadAll(resp.Body)
	if err != nil {
		return fmt.Errorf("could not read response: %w", err)
	}

	if resp.StatusCode > 299 {
		return fmt.Errorf("Read: status %d %s: %s", resp.StatusCode, resp.Status, respBytes)
	}
	fmt.Fprintf(w, "%s", respBytes)

	return nil
}

Java

import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.gson.GsonFactory;
import com.google.api.services.healthcare.v1.CloudHealthcare;
import com.google.api.services.healthcare.v1.CloudHealthcareScopes;
import com.google.auth.http.HttpCredentialsAdapter;
import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.Collections;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.client.methods.RequestBuilder;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.impl.client.HttpClients;

public class FhirResourceGet {
  private static final String FHIR_NAME =
      "projects/%s/locations/%s/datasets/%s/fhirStores/%s/fhir/%s/%s";
  private static final JsonFactory JSON_FACTORY = new GsonFactory();
  private static final NetHttpTransport HTTP_TRANSPORT = new NetHttpTransport();

  public static void fhirResourceGet(String resourceName) throws IOException, URISyntaxException {
    // String resourceName =
    //    String.format(
    //        FHIR_NAME, "project-id", "region-id", "dataset-id", "store-id", "resource-type",
    //  "resource-id");

    // Initialize the client, which will be used to interact with the service.
    CloudHealthcare client = createClient();
    HttpClient httpClient = HttpClients.createDefault();
    String uri = String.format("%sv1/%s", client.getRootUrl(), resourceName);
    URIBuilder uriBuilder = new URIBuilder(uri).setParameter("access_token", getAccessToken());

    HttpUriRequest request = RequestBuilder.get().setUri(uriBuilder.build()).build();

    // Execute the request and process the results.
    HttpResponse response = httpClient.execute(request);
    HttpEntity responseEntity = response.getEntity();
    if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
      String errorMessage =
          String.format(
              "Exception retrieving FHIR resource: %s\n", response.getStatusLine().toString());
      System.err.print(errorMessage);
      responseEntity.writeTo(System.err);
      throw new RuntimeException(errorMessage);
    }
    System.out.println("FHIR resource retrieved: ");
    responseEntity.writeTo(System.out);
  }

  private static CloudHealthcare createClient() throws IOException {
    // Use Application Default Credentials (ADC) to authenticate the requests
    // For more information see https://cloud.google.com/docs/authentication/production
    GoogleCredentials credential =
        GoogleCredentials.getApplicationDefault()
            .createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));

    // Create a HttpRequestInitializer, which will provide a baseline configuration to all requests.
    HttpRequestInitializer requestInitializer =
        request -> {
          new HttpCredentialsAdapter(credential).initialize(request);
          request.setConnectTimeout(60000); // 1 minute connect timeout
          request.setReadTimeout(60000); // 1 minute read timeout
        };

    // Build the client for interacting with the service.
    return new CloudHealthcare.Builder(HTTP_TRANSPORT, JSON_FACTORY, requestInitializer)
        .setApplicationName("your-application-name")
        .build();
  }

  private static String getAccessToken() throws IOException {
    GoogleCredentials credential =
        GoogleCredentials.getApplicationDefault()
            .createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));

    return credential.refreshAccessToken().getTokenValue();
  }
}

Node.js

const google = require('@googleapis/healthcare');
const healthcare = google.healthcare({
  version: 'v1',
  auth: new google.auth.GoogleAuth({
    scopes: ['https://www.googleapis.com/auth/cloud-platform'],
  }),
});

const getFhirResource = async () => {
  // TODO(developer): uncomment these lines before running the sample
  // const cloudRegion = 'us-central1';
  // const projectId = 'adjective-noun-123';
  // const datasetId = 'my-dataset';
  // const fhirStoreId = 'my-fhir-store';
  // const resourceType = 'Patient';
  // const resourceId = '16e8a860-33b3-49be-9b03-de979feed14a';
  const name = `projects/${projectId}/locations/${cloudRegion}/datasets/${datasetId}/fhirStores/${fhirStoreId}/fhir/${resourceType}/${resourceId}`;
  const request = {name};

  const resource =
    await healthcare.projects.locations.datasets.fhirStores.fhir.read(
      request
    );
  console.log(`Got ${resourceType} resource:\n`, resource.data);
};

getFhirResource();

Python

# Imports the types Dict and Any for runtime type hints.
from typing import Any, Dict  # noqa: E402


def get_resource(
    project_id: str,
    location: str,
    dataset_id: str,
    fhir_store_id: str,
    resource_type: str,
    resource_id: str,
) -> Dict[str, Any]:
    """Gets the contents of a FHIR resource.

    See
    https://github.com/GoogleCloudPlatform/python-docs-samples/tree/main/healthcare/api-client/v1/fhir
    before running the sample.
    See
    https://googleapis.github.io/google-api-python-client/docs/dyn/healthcare_v1.projects.locations.datasets.fhirStores.fhir.html#read
    for the Python API reference.

    Args:
      project_id: The project ID or project number of the Cloud project you want
        to use.
      location: The name of the parent dataset's location.
      dataset_id: The name of the parent dataset.
      fhir_store_id: The name of the FHIR store.
      resource_type: The type of FHIR resource.
      resource_id: The "logical id" of the resource you want to get the contents
        of. The ID is assigned by the server.

    Returns:
      A dict representing the FHIR resource.
    """
    # Imports the Google API Discovery Service.
    from googleapiclient import discovery

    api_version = "v1"
    service_name = "healthcare"

    # Returns an authorized API client by discovering the Healthcare API
    # and using GOOGLE_APPLICATION_CREDENTIALS environment variable.
    client = discovery.build(service_name, api_version)

    # TODO(developer): Uncomment these lines and replace with your values.
    # project_id = 'my-project'
    # location = 'us-central1'
    # dataset_id = 'my-dataset'
    # fhir_store_id = 'my-fhir-store'
    # resource_type = 'Patient'
    # resource_id = 'b682d-0e-4843-a4a9-78c9ac64'
    fhir_store_parent = (
        f"projects/{project_id}/locations/{location}/datasets/{dataset_id}"
    )
    fhir_resource_path = f"{fhir_store_parent}/fhirStores/{fhir_store_id}/fhir/{resource_type}/{resource_id}"

    request = (
        client.projects()
        .locations()
        .datasets()
        .fhirStores()
        .fhir()
        .read(name=fhir_resource_path)
    )
    response = request.execute()
    print(
        f"Got contents of {resource_type} resource with ID {resource_id}:\n",
        json.dumps(response, indent=2),
    )

    return response

ๅ–ๅพ—ๆ‰€ๆœ‰ Encounter ่ณ‡ๆบ่ฉณ็ดฐ่ณ‡ๆ–™

ไธ‹ๅˆ—็ฏ„ไพ‹่ชชๆ˜Žๅฆ‚ไฝ•ๆŸฅ็œ‹ Encounter ่ณ‡ๆบ็š„่ฉณ็ดฐ่ณ‡ๆ–™๏ผŒไปฅๅŠ่ˆ‡ Encounter ็›ธ้—œ็š„ๆ‰€ๆœ‰่ณ‡ๆบใ€‚

้€™ๅ€‹ๆ–นๆณ•ๆœƒๅฏฆไฝœไธ‹ๅˆ— FHIR ็‰ˆๆœฌไธญๅฎš็พฉ็š„ FHIR ๆ“ดๅ……ไฝœๆฅญ Encounter-everything๏ผš

REST

่ซ‹ไฝฟ็”จ projects.locations.datasets.fhirStores.fhir.Encounter-everything ๆ–นๆณ•ใ€‚

ไฝฟ็”จไปปไฝ•่ฆๆฑ‚่ณ‡ๆ–™ไน‹ๅ‰๏ผŒ่ซ‹ๅ…ˆๆ›ฟๆ›ไปฅไธ‹้ …็›ฎ๏ผš

  • PROJECT_ID๏ผšๆ‚จ็š„ Google Cloud ๅฐˆๆกˆ ID
  • LOCATION๏ผš่ณ‡ๆ–™้›†ไฝ็ฝฎ
  • DATASET_ID๏ผš่ณ‡ๆ–™้›† ID
  • FHIR_STORE_ID๏ผšFHIR ๅ„ฒๅญ˜ๅบซ ID
  • ENCOUNTER_ID๏ผšๆœƒ่จบ่ณ‡ๆบ ID

ๅฆ‚่ฆๅ‚ณ้€่ฆๆฑ‚๏ผŒ่ซ‹้ธๆ“‡ไปฅไธ‹ๅ…ถไธญไธ€ๅ€‹้ธ้ …๏ผš

curl

ๅŸท่กŒไธ‹ๅˆ—ๆŒ‡ไปค๏ผš

curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://healthcare.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/fhirStores/FHIR_STORE_ID/fhir/Encounter/ENCOUNTER_ID/\$everything"

PowerShell

ๅŸท่กŒไธ‹ๅˆ—ๆŒ‡ไปค๏ผš

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method GET `
-Headers $headers `
-Uri "https://healthcare.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/fhirStores/FHIR_STORE_ID/fhir/Encounter/ENCOUNTER_ID/\$everything" | Select-Object -Expand Content
ๅœจ ID ็‚บ c427ce3e-7677-400e-bc06-33a8cecfdd77 ็š„ Encounter ่ณ‡ๆบไธŠๅ‘ผๅซๆ–นๆณ•ๆ™‚๏ผŒ็ณป็ตฑๆœƒๅ‚ณๅ›žไธ‹ๅˆ—็ฏ„ไพ‹ๅ›žๆ‡‰ใ€‚้€™ๅ€‹่ณ‡ๆบๆ˜ฏ gs://gcp-public-data--synthea-fhir-data-10-patients/fhir_r4_ndjson/ ๅ…ฌ้–‹ Cloud Storage ๅ€ผๅ€ไธญ็š„ๅˆๆˆ่ณ‡ๆบใ€‚

ๅ–ๅพ—ๆ‰€ๆœ‰็—…ๆ‚ฃๅ€้š”่ณ‡ๆบ

ไธ‹ๅˆ—็ฏ„ไพ‹่ชชๆ˜Žๅฆ‚ไฝ•ๅ–ๅพ—่ˆ‡็‰นๅฎš็—…ๆ‚ฃๅ€้–“็›ธ้—œ่ฏ็š„ๆ‰€ๆœ‰่ณ‡ๆบ (DSTU2ใ€STU3ใ€R4 ๅ’Œ R5)ใ€‚่ฉณๆƒ…่ซ‹ๅƒ้–ฑ projects.locations.datasets.fhirStores.fhir.Patient-everythingใ€‚

ไธ‹ๅˆ— REST ็ฏ„ไพ‹้ฉ็”จๆ–ผ R4 FHIR ๅ„ฒๅญ˜ๅบซใ€‚Goใ€Javaใ€Node.js ๅ’Œ Python ็ฏ„ไพ‹้ฉ็”จๆ–ผ STU3 FHIR ๅญ˜ๆ”พๅ€ใ€‚

curl

ๅฆ‚่ฆๅ–ๅพ—็—…ๆ‚ฃๅ€้š”ไธญ็š„่ณ‡ๆบ๏ผŒ่ซ‹็™ผๅ‡บ GET ่ฆๆฑ‚ไธฆๆŒ‡ๅฎšไธ‹ๅˆ—่ณ‡่จŠ๏ผš

  • ็ˆถ้ …่ณ‡ๆ–™้›†็š„ๅ็จฑ
  • FHIR ๅ„ฒๅญ˜ๅบซๅ็จฑ
  • ็—…ๆ‚ฃ ID
  • ๅญ˜ๅ–ๆฌŠๆ–

ไปฅไธ‹็ฏ„ไพ‹้กฏ็คบไฝฟ็”จ curl ็š„ GET ่ฆๆฑ‚๏ผš

curl -X GET \
     -H "Authorization: Bearer $(gcloud auth application-default print-access-token)" \
     "https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/fhirStores/FHIR_STORE_ID/fhir/Patient/PATIENT_ID/\$everything"

ๅฆ‚ๆžœ่ฆๆฑ‚ๆˆๅŠŸ๏ผŒไผบๆœๅ™จๆœƒไปฅ JSON ๆ ผๅผๅ‚ณๅ›ž้กžไผผไปฅไธ‹็ฏ„ไพ‹็š„ๅ›žๆ‡‰๏ผš

{
  "entry": [
    {
      "resource": {
        "birthDate": "1970-01-01",
        "gender": "female",
        "id": "PATIENT_ID",
        "name": [
          {
            "family": "Smith",
            "given": [
              "Darcy"
            ],
            "use": "official"
          }
        ],
        "resourceType": "Patient"
      }
    },
    {
      "resource": {
        "class": {
          "code": "IMP",
          "display": "inpatient encounter",
          "system": "http://hl7.org/fhir/v3/ActCode"
        },
        "id": "ENCOUNTER_ID",
        "reasonCode": [
          {
            "text": "The patient had an abnormal heart rate. She was concerned about this."
          }
        ],
        "resourceType": "Encounter",
        "status": "finished",
        "subject": {
          "reference": "Patient/PATIENT_ID"
        }
      }
    },
    {
      "resource": {
        "encounter": {
          "reference": "Encounter/ENCOUNTER_ID"
        },
        "effectiveDateTime": "2020-01-01T00:00:00+00:00",
        "id": "OBSERVATION_ID",
        "resourceType": "Observation",
        "status": "final",
        "subject": {
          "reference": "Patient/PATIENT_ID"
        },
        "valueQuantity": {
          "unit": "bpm",
          "value": BPM_VALUE
        }
      }
    }
  ],
  "resourceType": "Bundle",
  "type": "searchset"
}

PowerShell

ๅฆ‚่ฆๅ–ๅพ—็—…ๆ‚ฃๅ€้š”ไธญ็š„่ณ‡ๆบ๏ผŒ่ซ‹็™ผๅ‡บ GET ่ฆๆฑ‚ไธฆๆŒ‡ๅฎšไธ‹ๅˆ—่ณ‡่จŠ๏ผš

  • ็ˆถ้ …่ณ‡ๆ–™้›†็š„ๅ็จฑ
  • FHIR ๅ„ฒๅญ˜ๅบซๅ็จฑ
  • ็—…ๆ‚ฃ ID
  • ๅญ˜ๅ–ๆฌŠๆ–

ไปฅไธ‹็ฏ„ไพ‹้กฏ็คบๅฆ‚ไฝ•ไฝฟ็”จ PowerShell ๆๅ‡บ GET ่ฆๆฑ‚๏ผš

$cred = gcloud auth application-default print-access-token
$headers = @{ Authorization = "Bearer $cred" }

Invoke-RestMethod `
  -Method Get `
  -Headers $headers `
  -Uri 'https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/fhirStores/FHIR_STORE_ID/fhir/Patient/RESOURCE_ID/$everything' | ConvertTo-Json

ๅฆ‚ๆžœ่ฆๆฑ‚ๆˆๅŠŸ๏ผŒไผบๆœๅ™จๆœƒไปฅ JSON ๆ ผๅผๅ‚ณๅ›ž้กžไผผไปฅไธ‹็ฏ„ไพ‹็š„ๅ›žๆ‡‰๏ผš

{
  "entry": [
    {
      "resource": {
        "birthDate": "1970-01-01",
        "gender": "female",
        "id": "PATIENT_ID",
        "name": [
          {
            "family": "Smith",
            "given": [
              "Darcy"
            ],
            "use": "official"
          }
        ],
        "resourceType": "Patient"
      }
    },
    {
      "resource": {
        "class": {
          "code": "IMP",
          "display": "inpatient encounter",
          "system": "http://hl7.org/fhir/v3/ActCode"
        },
        "id": "ENCOUNTER_ID",
        "reasonCode": [
          {
            "text": "The patient had an abnormal heart rate. She was concerned about this."
          }
        ],
        "resourceType": "Encounter",
        "status": "finished",
        "subject": {
          "reference": "Patient/PATIENT_ID"
        }
      }
    },
    {
      "resource": {
        "encounter": {
          "reference": "Encounter/ENCOUNTER_ID"
        },
        "effectiveDateTime": "2020-01-01T00:00:00+00:00",
        "id": "OBSERVATION_ID",
        "resourceType": "Observation",
        "status": "final",
        "subject": {
          "reference": "Patient/PATIENT_ID"
        },
        "valueQuantity": {
          "unit": "bpm",
          "value": BPM_VALUE
        }
      }
    }
  ],
  "resourceType": "Bundle",
  "type": "searchset"
}

Go

import (
	"context"
	"fmt"
	"io"

	healthcare "google.golang.org/api/healthcare/v1"
)

// fhirGetPatientEverything gets all resources associated with a particular
// patient compartment.
func fhirGetPatientEverything(w io.Writer, projectID, location, datasetID, fhirStoreID, fhirResourceID string) error {
	ctx := context.Background()

	healthcareService, err := healthcare.NewService(ctx)
	if err != nil {
		return fmt.Errorf("healthcare.NewService: %w", err)
	}
	fhirService := healthcareService.Projects.Locations.Datasets.FhirStores.Fhir
	name := fmt.Sprintf("projects/%s/locations/%s/datasets/%s/fhirStores/%s/fhir/Patient/%s", projectID, location, datasetID, fhirStoreID, fhirResourceID)

	resp, err := fhirService.PatientEverything(name).Do()
	if err != nil {
		return fmt.Errorf("PatientEverything: %w", err)
	}

	defer resp.Body.Close()

	respBytes, err := io.ReadAll(resp.Body)
	if err != nil {
		return fmt.Errorf("could not read response: %w", err)
	}

	if resp.StatusCode > 299 {
		return fmt.Errorf("PatientEverything: status %d %s: %s", resp.StatusCode, resp.Status, respBytes)
	}
	fmt.Fprintf(w, "%s", respBytes)

	return nil
}

Java

import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.gson.GsonFactory;
import com.google.api.services.healthcare.v1.CloudHealthcare;
import com.google.api.services.healthcare.v1.CloudHealthcareScopes;
import com.google.auth.http.HttpCredentialsAdapter;
import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.Collections;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.client.methods.RequestBuilder;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.impl.client.HttpClients;

public class FhirResourceGetPatientEverything {
  private static final String FHIR_NAME =
      "projects/%s/locations/%s/datasets/%s/fhirStores/%s/fhir/Patient/%s";
  private static final JsonFactory JSON_FACTORY = new GsonFactory();
  private static final NetHttpTransport HTTP_TRANSPORT = new NetHttpTransport();

  public static void fhirResourceGetPatientEverything(String resourceName)
      throws IOException, URISyntaxException {
    // String resourceName =
    //    String.format(
    //        FHIR_NAME, "project-id", "region-id", "dataset-id", "store-id", "patient-id");

    // Initialize the client, which will be used to interact with the service.
    CloudHealthcare client = createClient();

    HttpClient httpClient = HttpClients.createDefault();
    String uri = String.format("%sv1/%s/$everything", client.getRootUrl(), resourceName);
    URIBuilder uriBuilder = new URIBuilder(uri).setParameter("access_token", getAccessToken());

    HttpUriRequest request =
        RequestBuilder.get(uriBuilder.build())
            .addHeader("Content-Type", "application/json-patch+json")
            .addHeader("Accept-Charset", "utf-8")
            .addHeader("Accept", "application/fhir+json; charset=utf-8")
            .build();

    // Execute the request and process the results.
    HttpResponse response = httpClient.execute(request);
    HttpEntity responseEntity = response.getEntity();
    if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
      System.err.print(
          String.format(
              "Exception getting patient everythingresource: %s\n",
              response.getStatusLine().toString()));
      responseEntity.writeTo(System.err);
      throw new RuntimeException();
    }
    System.out.println("Patient compartment results: ");
    responseEntity.writeTo(System.out);
  }

  private static CloudHealthcare createClient() throws IOException {
    // Use Application Default Credentials (ADC) to authenticate the requests
    // For more information see https://cloud.google.com/docs/authentication/production
    GoogleCredentials credential =
        GoogleCredentials.getApplicationDefault()
            .createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));

    // Create a HttpRequestInitializer, which will provide a baseline configuration to all requests.
    HttpRequestInitializer requestInitializer =
        request -> {
          new HttpCredentialsAdapter(credential).initialize(request);
          request.setConnectTimeout(60000); // 1 minute connect timeout
          request.setReadTimeout(60000); // 1 minute read timeout
        };

    // Build the client for interacting with the service.
    return new CloudHealthcare.Builder(HTTP_TRANSPORT, JSON_FACTORY, requestInitializer)
        .setApplicationName("your-application-name")
        .build();
  }

  private static String getAccessToken() throws IOException {
    GoogleCredentials credential =
        GoogleCredentials.getApplicationDefault()
            .createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));

    return credential.refreshAccessToken().getTokenValue();
  }
}

Node.js

const google = require('@googleapis/healthcare');
const healthcare = google.healthcare({
  version: 'v1',
  auth: new google.auth.GoogleAuth({
    scopes: ['https://www.googleapis.com/auth/cloud-platform'],
  }),
});

const getPatientEverything = async () => {
  // TODO(developer): uncomment these lines before running the sample
  // const cloudRegion = 'us-central1';
  // const projectId = 'adjective-noun-123';
  // const datasetId = 'my-dataset';
  // const fhirStoreId = 'my-fhir-store';
  // const patientId = '16e8a860-33b3-49be-9b03-de979feed14a';
  const name = `projects/${projectId}/locations/${cloudRegion}/datasets/${datasetId}/fhirStores/${fhirStoreId}/fhir/Patient/${patientId}`;
  const request = {name};

  const patientEverything =
    await healthcare.projects.locations.datasets.fhirStores.fhir.PatientEverything(
      request
    );
  console.log(
    `Got all resources in patient ${patientId} compartment:\n`,
    JSON.stringify(patientEverything)
  );
};

getPatientEverything();

Python

def get_patient_everything(
    project_id,
    location,
    dataset_id,
    fhir_store_id,
    resource_id,
):
    """Gets all the resources in the patient compartment.

    See https://github.com/GoogleCloudPlatform/python-docs-samples/tree/main/healthcare/api-client/v1/fhir
    before running the sample."""
    # Imports Python's built-in "os" module
    import os

    # Imports the google.auth.transport.requests transport
    from google.auth.transport import requests

    # Imports a module to allow authentication using a service account
    from google.oauth2 import service_account

    # Gets credentials from the environment.
    credentials = service_account.Credentials.from_service_account_file(
        os.environ["GOOGLE_APPLICATION_CREDENTIALS"]
    )
    scoped_credentials = credentials.with_scopes(
        ["https://www.googleapis.com/auth/cloud-platform"]
    )
    # Creates a requests Session object with the credentials.
    session = requests.AuthorizedSession(scoped_credentials)

    # URL to the Cloud Healthcare API endpoint and version
    base_url = "https://healthcare.googleapis.com/v1"

    # TODO(developer): Uncomment these lines and replace with your values.
    # project_id = 'my-project'  # replace with your GCP project ID
    # location = 'us-central1'  # replace with the parent dataset's location
    # dataset_id = 'my-dataset'  # replace with the parent dataset's ID
    # fhir_store_id = 'my-fhir-store' # replace with the FHIR store ID
    # resource_id = 'b682d-0e-4843-a4a9-78c9ac64'  # replace with the Patient resource's ID
    url = f"{base_url}/projects/{project_id}/locations/{location}"

    resource_path = "{}/datasets/{}/fhirStores/{}/fhir/{}/{}".format(
        url, dataset_id, fhir_store_id, "Patient", resource_id
    )
    resource_path += "/$everything"

    # Sets required application/fhir+json header on the request
    headers = {"Content-Type": "application/fhir+json;charset=utf-8"}

    response = session.get(resource_path, headers=headers)
    response.raise_for_status()

    resource = response.json()

    print(json.dumps(resource, indent=2))

    return resource

ๅ–ๅพ—ไพ้กžๅž‹ๆˆ–ๆ—ฅๆœŸ็ฏฉ้ธ็š„็—…ๆ‚ฃๅ€้š”่ณ‡ๆบ

ไธ‹ๅˆ—็ฏ„ไพ‹่ชชๆ˜Žๅฆ‚ไฝ•ๅ–ๅพ—่ˆ‡็‰นๅฎš็—…ๆ‚ฃๅ€้–“ (R4)็›ธ้—œ่ฏ็š„ๆ‰€ๆœ‰่ณ‡ๆบ๏ผŒไธฆไพ้กžๅž‹ๆธ…ๅ–ฎๅ’ŒๆŒ‡ๅฎšๆ—ฅๆœŸ่ˆ‡ๆ™‚้–“้€ฒ่กŒ็ฏฉ้ธใ€‚่ฉณๆƒ…่ซ‹ๅƒ้–ฑ projects.locations.datasets.fhirStores.fhir.Patient-everything ็š„่ชชๆ˜Žใ€‚

ไธ‹ๅˆ— REST ็ฏ„ไพ‹้ฉ็”จๆ–ผ R4 FHIR ๅ„ฒๅญ˜ๅบซใ€‚

curl

ๅฆ‚่ฆๅ–ๅพ—็‰นๅฎš้กžๅž‹ไธ”่‡ชๆŒ‡ๅฎšๆ—ฅๆœŸ่ตท๏ผŒไฝๆ–ผ็—…ๆ‚ฃๅ€้š”ไธญ็š„่ณ‡ๆบ๏ผŒ่ซ‹ๆๅ‡บ GET ่ฆๆฑ‚ไธฆๆŒ‡ๅฎšไธ‹ๅˆ—่ณ‡่จŠ๏ผš

  • ็ˆถ้ …่ณ‡ๆ–™้›†็š„ๅ็จฑ
  • FHIR ๅ„ฒๅญ˜ๅบซๅ็จฑ
  • ็—…ๆ‚ฃ ID
  • ๆŸฅ่ฉขๅญ—ไธฒ๏ผŒๅ…งๅซไปฅๅŠๅฝข้€—่™Ÿๅˆ†้š”็š„่ณ‡ๆบ้กžๅž‹ๆธ…ๅ–ฎๅ’Œ้–‹ๅง‹ๆ—ฅๆœŸ
  • ๅญ˜ๅ–ๆฌŠๆ–

ไปฅไธ‹็ฏ„ไพ‹้กฏ็คบไฝฟ็”จ curl ็š„ GET ่ฆๆฑ‚๏ผš

curl -X GET \
     -H "Authorization: Bearer $(gcloud auth application-default print-access-token)" \
     "https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/fhirStores/FHIR_STORE_ID/fhir/Patient/PATIENT_ID/\$everything?_type=RESOURCE_TYPES&_since=DATE"

ๅฆ‚ๆžœ่ฆๆฑ‚ๆˆๅŠŸ๏ผŒไผบๆœๅ™จๆœƒไปฅ JSON ๆ ผๅผๅ‚ณๅ›ž็ฌฆๅˆๆŒ‡ๅฎšๆขไปถ็š„ๆ‰€ๆœ‰่ณ‡ๆบใ€‚

PowerShell

ๅฆ‚่ฆๅ–ๅพ—็‰นๅฎš้กžๅž‹ไธ”่‡ชๆŒ‡ๅฎšๆ—ฅๆœŸ่ตท๏ผŒไฝๆ–ผ็—…ๆ‚ฃๅ€้š”ไธญ็š„่ณ‡ๆบ๏ผŒ่ซ‹ๆๅ‡บ GET ่ฆๆฑ‚ไธฆๆŒ‡ๅฎšไธ‹ๅˆ—่ณ‡่จŠ๏ผš

  • ็ˆถ้ …่ณ‡ๆ–™้›†็š„ๅ็จฑ
  • FHIR ๅ„ฒๅญ˜ๅบซๅ็จฑ
  • ็—…ๆ‚ฃ ID
  • ๆŸฅ่ฉขๅญ—ไธฒ๏ผŒๅ…งๅซไปฅๅŠๅฝข้€—่™Ÿๅˆ†้š”็š„่ณ‡ๆบ้กžๅž‹ๆธ…ๅ–ฎๅ’Œ้–‹ๅง‹ๆ—ฅๆœŸ
  • ๅญ˜ๅ–ๆฌŠๆ–

ไปฅไธ‹็ฏ„ไพ‹้กฏ็คบๅฆ‚ไฝ•ไฝฟ็”จ PowerShell ๆๅ‡บ GET ่ฆๆฑ‚๏ผš

$cred = gcloud auth application-default print-access-token
$headers = @{ Authorization = "Bearer $cred" }

Invoke-RestMethod `
  -Method Get `
  -Headers $headers `
  -Uri 'https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/fhirStores/FHIR_STORE_ID/fhir/Patient/RESOURCE_ID/$everything?_type=RESOURCE_TYPES&_since=DATE' | ConvertTo-Json

ๅฆ‚ๆžœ่ฆๆฑ‚ๆˆๅŠŸ๏ผŒไผบๆœๅ™จๆœƒไปฅ JSON ๆ ผๅผๅ‚ณๅ›ž็ฌฆๅˆๆŒ‡ๅฎšๆขไปถ็š„ๆ‰€ๆœ‰่ณ‡ๆบใ€‚

ๅˆ—ๅ‡บ FHIR ่ณ‡ๆบ็‰ˆๆœฌ

ๆ‚จๅฏไปฅๅˆ—ๅ‡บ FHIR ่ณ‡ๆบ็š„ๆญทๅฒ็‰ˆๆœฌ๏ผŒๅŒ…ๆ‹ฌ็›ฎๅ‰็‰ˆๆœฌๅ’Œๆ‰€ๆœ‰ๅทฒๅˆช้™ค็š„็‰ˆๆœฌใ€‚้€™้ …ๅŠŸ่ƒฝๅฏ่ฎ“ๆ‚จๅŸท่กŒไธ‹ๅˆ—ๆ“ไฝœ๏ผš

  • ่ฟฝ่นค็—…ๆญทใ€่—ฅ็‰ฉๆˆ–็…ง่ญท่จˆ็•ซ็š„่ฎŠๆ›ดใ€‚
  • ๅฆ‚ๆžœ FHIR ่ณ‡ๆบๅŒ…ๅซไธๆญฃ็ขบ็š„่ณ‡ๆ–™๏ผŒๆ‚จๅฏไปฅๆŸฅ็œ‹ๆญทๅฒ็‰ˆๆœฌ๏ผŒๅˆคๆ–ทไธๆญฃ็ขบ็š„่ณ‡ๆ–™ๆ˜ฏๅœจไฝ•ๆ™‚่ผธๅ…ฅ๏ผŒไธฆๅพฉๅŽŸๆญฃ็ขบ็š„่ณ‡่จŠใ€‚
  • ๆไพ›ๅฎŒๆ•ด็š„็จฝๆ ธ่ฟฝ่นค่จ˜้Œ„๏ผŒ็ขบไฟ็ฌฆๅˆๆณ•่ฆ่ฆๆฑ‚ใ€‚

ไธ‹ๅˆ— REST ็ฏ„ไพ‹้ฉ็”จๆ–ผ R4 FHIR ๅ„ฒๅญ˜ๅบซใ€‚Goใ€Javaใ€Node.js ๅ’Œ Python ็ฏ„ไพ‹้ฉ็”จๆ–ผ STU3 FHIR ๅญ˜ๆ”พๅ€ใ€‚

ๆŽงๅˆถๅฐ

  1. ๅ‰ๅพ€ Google Cloud ๆŽงๅˆถๅฐ็š„ใ€ŒFHIR viewerใ€้ ้ขใ€‚

    ๅ‰ๅพ€ FHIR ๆชข่ฆ–ๅ™จ

  2. ๅœจใ€ŒFHIR storeใ€(FHIR ๅ„ฒๅญ˜ๅบซ) ้ธๅ–ฎไธญ้ธๅ–่ณ‡ๆ–™้›†๏ผŒ็„ถๅพŒ้ธๅ–่ณ‡ๆ–™้›†ไธญ็š„ FHIR ๅ„ฒๅญ˜ๅบซใ€‚

  3. ๅฆ‚่ฆ็ฏฉ้ธ FHIR ่ณ‡ๆบ้กžๅž‹ๆธ…ๅ–ฎ๏ผŒ่ซ‹ๆœๅฐ‹่ฆ้กฏ็คบ็š„่ณ‡ๆบ้กžๅž‹ใ€‚

  4. ๆŒ‰ไธ€ไธ‹ใ€Œ่ณ‡ๆบ้กžๅž‹ใ€ๆฌ„ไฝใ€‚

  5. ๅœจ้šจๅณๅ‡บ็พ็š„ใ€ŒPropertiesใ€(ๅฑฌๆ€ง) ไธ‹ๆ‹‰ๅผๆธ…ๅ–ฎไธญ้ธๅ–ใ€ŒResource Typeใ€(่ณ‡ๆบ้กžๅž‹)ใ€‚

  6. ่ผธๅ…ฅ FHIR ่ณ‡ๆบ้กžๅž‹ใ€‚

  7. ๅœจ FHIR ่ณ‡ๆบ้กžๅž‹ๆธ…ๅ–ฎไธญ๏ผŒ้ธๅ–่ณ‡ๆบ้กžๅž‹ใ€‚

  8. ๅœจ้šจๅณ้กฏ็คบ็š„ FHIR ่ณ‡ๆบ่กจๆ ผไธญ๏ผŒ้ธๅ–ๆˆ–ๆœๅฐ‹่ณ‡ๆบใ€‚

  9. ๅฆ‚่ฆๆŸฅ็œ‹ๅŠๆฏ”่ผƒ FHIR ่ณ‡ๆบ็š„ๆญทๅฒ็‰ˆๆœฌ๏ผŒ่ซ‹ๆŒ‰ไธ€ไธ‹ใ€ŒOverviewใ€(็ธฝ่ฆฝ) ๅˆ†้ ๆจ™็ฑค๏ผŒ็„ถๅพŒๅŸท่กŒไธ‹ๅˆ—ๆ“ไฝœ๏ผš

    1. ๅฆ‚่ฆๆŸฅ็œ‹ FHIR ่ณ‡ๆบ็š„ๆญทไพ†็‰ˆๆœฌ๏ผŒ่ซ‹ๅœจใ€Œ็‰ˆๆœฌ IDใ€็š„ๅŒไธ€ๅˆ—ไธญ๏ผŒๆŒ‰ไธ€ไธ‹ใ€ŒๆŸฅ็œ‹ๆญทไพ†็‰ˆๆœฌใ€ใ€‚ ๅœจใ€ŒSelect a resource versionใ€(้ธๅ–่ณ‡ๆบ็‰ˆๆœฌ) ็ช—ๆ ผไธญ๏ผŒ้ธๅ–็‰ˆๆœฌ๏ผŒ็„ถๅพŒๆŒ‰ไธ€ไธ‹ใ€ŒConfirmใ€(็ขบ่ช)ใ€‚็‰ˆๆœฌไธญ็š„่ณ‡ๆ–™ๆœƒๅกซๅ…ฅใ€Œ็ธฝ่ฆฝใ€ใ€ใ€Œๅ…ƒ็ด ใ€ๅ’Œใ€ŒJSONใ€ๅˆ†้ ใ€‚
    2. ๅฆ‚่ฆๆฏ”่ผƒๅ…ฉๅ€‹็‰ˆๆœฌ็š„ FHIR ่ณ‡ๆบ๏ผŒ่ซ‹ๅœจใ€Œ็‰ˆๆœฌ IDใ€ๆ‰€ๅœจ็š„ๅŒไธ€ๅˆ—ไธญ๏ผŒๆŒ‰ไธ€ไธ‹ใ€Œๆฏ”่ผƒ่ณ‡ๆบ็‰ˆๆœฌใ€ใ€‚ ๅœจใ€Œ้ธๅ–่ฆๆฏ”่ผƒ็š„่ณ‡ๆบ็‰ˆๆœฌใ€็ช—ๆ ผไธญ๏ผŒ้ธๅ–ๅ…ฉๅ€‹่ณ‡ๆบ็‰ˆๆœฌ๏ผŒ็„ถๅพŒๆŒ‰ไธ€ไธ‹ใ€Œ็ขบ่ชใ€ใ€‚็ณป็ตฑๆœƒไปฅๅทฎ็•ฐๆชข่ฆ–็•ซ้ข้กฏ็คบ้€™ๅ…ฉๅ€‹่ณ‡ๆบ็‰ˆๆœฌ๏ผŒๅทฆๅดๆ˜ฏๆ‚จ้ธๅ–็š„็ฌฌไธ€ๅ€‹็‰ˆๆœฌ๏ผŒๅณๅดๅ‰‡ๆ˜ฏ็ฌฌไบŒๅ€‹็‰ˆๆœฌใ€‚

REST

่ซ‹ไฝฟ็”จ projects.locations.datasets.fhirStores.fhir.history ๆ–นๆณ•ใ€‚

ไฝฟ็”จไปปไฝ•่ฆๆฑ‚่ณ‡ๆ–™ไน‹ๅ‰๏ผŒ่ซ‹ๅ…ˆๆ›ฟๆ›ไปฅไธ‹้ …็›ฎ๏ผš

  • PROJECT_ID๏ผšๆ‚จ็š„ Google Cloud ๅฐˆๆกˆ ID
  • LOCATION๏ผš่ณ‡ๆ–™้›†ไฝ็ฝฎ
  • DATASET_ID๏ผšFHIR ๅ„ฒๅญ˜ๅบซ็š„็ˆถ้ …่ณ‡ๆ–™้›†
  • FHIR_STORE_ID๏ผšFHIR ๅ„ฒๅญ˜ๅบซ ID
  • RESOURCE_TYPE๏ผšFHIR ่ณ‡ๆบ้กžๅž‹
  • RESOURCE_ID๏ผšFHIR ่ณ‡ๆบ ID

ๅฆ‚่ฆๅ‚ณ้€่ฆๆฑ‚๏ผŒ่ซ‹้ธๆ“‡ไปฅไธ‹ๅ…ถไธญไธ€ๅ€‹้ธ้ …๏ผš

curl

ไธ‹ๅˆ—็ฏ„ไพ‹่ชชๆ˜Žๅฆ‚ไฝ•ๅˆ—ๅ‡บ Observation ่ณ‡ๆบ็š„ๆ‰€ๆœ‰็‰ˆๆœฌใ€‚ๅŽŸๅง‹ๅปบ็ซ‹ๅพŒ๏ผŒ็ณป็ตฑๆ›ดๆ–ฐไบ†ใ€Œ่ง€ๅฏŸใ€ไธ€ๆฌก๏ผŒ่ฎŠๆ›ด็—…ๆ‚ฃๆฏๅˆ†้˜ๅฟƒ่ทณๆฌกๆ•ธ (BPM)ใ€‚

ๅŸท่กŒไธ‹ๅˆ—ๆŒ‡ไปค๏ผš

curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/fhirStores/FHIR_STORE_ID/fhir/RESOURCE_TYPE/RESOURCE_ID/_history"

PowerShell

ไธ‹ๅˆ—็ฏ„ไพ‹่ชชๆ˜Žๅฆ‚ไฝ•ๅˆ—ๅ‡บ Observation ่ณ‡ๆบ็š„ๆ‰€ๆœ‰็‰ˆๆœฌใ€‚ๅŽŸๅง‹ๅปบ็ซ‹ๅพŒ๏ผŒ็ณป็ตฑๆ›ดๆ–ฐไบ†ใ€Œ่ง€ๅฏŸใ€ไธ€ๆฌก๏ผŒ่ฎŠๆ›ด็—…ๆ‚ฃๆฏๅˆ†้˜ๅฟƒ่ทณๆฌกๆ•ธ (BPM)ใ€‚

ๅŸท่กŒไธ‹ๅˆ—ๆŒ‡ไปค๏ผš

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method GET `
-Headers $headers `
-Uri "https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/fhirStores/FHIR_STORE_ID/fhir/RESOURCE_TYPE/RESOURCE_ID/_history" | Select-Object -Expand Content
ๅฆ‚ๆžœ่ฆๆฑ‚ๆˆๅŠŸ๏ผŒไผบๆœๅ™จๆœƒไปฅ JSON ๆ ผๅผๅ‚ณๅ›žๅ›žๆ‡‰ใ€‚ๅœจๆœฌไพ‹ไธญ๏ผŒ็ณป็ตฑๆœƒๅ‚ณๅ›žๅ…ฉๅ€‹็‰ˆๆœฌ็š„ Observationใ€‚ๅœจ็ฌฌไธ€ๅ€‹็‰ˆๆœฌไธญ๏ผŒ็—…ๆ‚ฃ็š„ๅฟƒ็އ็‚บ 75 BPMใ€‚ๅœจ็ฌฌไบŒๅ€‹็‰ˆๆœฌไธญ๏ผŒ็—…ๆ‚ฃ็š„ๅฟƒ็އ็‚บๆฏๅˆ†้˜ 85 ไธ‹ใ€‚
{
  "entry": [
    {
      "resource": {
        "effectiveDateTime": "2020-01-01T00:00:00+00:00",
        "id": "OBSERVATION_ID",
        "meta": {
          "lastUpdated": "2020-01-02T00:00:00+00:00",
          "versionId": "MTU0MTE5MDk5Mzk2ODcyODAwMA"
        },
        "resourceType": "Observation",
        "status": "final",
        "subject": {
          "reference": "Patient/PATIENT_ID"
        },
        "valueQuantity": {
          "unit": "bpm",
          "value": 85
        }
      }
    },
    {
      "resource": {
        "encounter": {
          "reference": "Encounter/ENCOUNTER_ID"
        },
        "effectiveDateTime": "2020-01-01T00:00:00+00:00",
        "id": "OBSERVATION_ID",
        "meta": {
          "lastUpdated": "2020-01-01T00:00:00+00:00",
          "versionId": "MTU0MTE5MDg4MTY0MzQ3MjAwMA"
        },
        "resourceType": "Observation",
        "status": "final",
        "subject": {
          "reference": "Patient/PATIENT_ID"
        },
        "valueQuantity": {
          "unit": "bpm",
          "value": 75
        }
      }
    }
  ],
  "resourceType": "Bundle",
  "type": "history"
}

Go

import (
	"context"
	"fmt"
	"io"

	healthcare "google.golang.org/api/healthcare/v1"
)

// listFHIRResourceHistory lists an FHIR resource's history.
func listFHIRResourceHistory(w io.Writer, projectID, location, datasetID, fhirStoreID, resourceType, fhirResourceID string) error {
	ctx := context.Background()

	healthcareService, err := healthcare.NewService(ctx)
	if err != nil {
		return fmt.Errorf("healthcare.NewService: %w", err)
	}

	fhirService := healthcareService.Projects.Locations.Datasets.FhirStores.Fhir

	name := fmt.Sprintf("projects/%s/locations/%s/datasets/%s/fhirStores/%s/fhir/%s/%s", projectID, location, datasetID, fhirStoreID, resourceType, fhirResourceID)

	resp, err := fhirService.History(name).Do()
	if err != nil {
		return fmt.Errorf("History: %w", err)
	}

	defer resp.Body.Close()

	respBytes, err := io.ReadAll(resp.Body)
	if err != nil {
		return fmt.Errorf("could not read response: %w", err)
	}

	if resp.StatusCode > 299 {
		return fmt.Errorf("History: status %d %s: %s", resp.StatusCode, resp.Status, respBytes)
	}
	fmt.Fprintf(w, "%s", respBytes)

	return nil
}

Java


import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.gson.GsonFactory;
import com.google.api.services.healthcare.v1.CloudHealthcare;
import com.google.api.services.healthcare.v1.CloudHealthcareScopes;
import com.google.auth.http.HttpCredentialsAdapter;
import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.Collections;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.client.methods.RequestBuilder;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.impl.client.HttpClients;

public class FhirResourceListHistory {
  private static final String FHIR_NAME =
      "projects/%s/locations/%s/datasets/%s/fhirStores/%s/fhir/%s/%s";
  private static final JsonFactory JSON_FACTORY = new GsonFactory();
  private static final NetHttpTransport HTTP_TRANSPORT = new NetHttpTransport();

  public static void fhirResourceListHistory(String resourceName)
      throws IOException, URISyntaxException {
    // String resourceName =
    //    String.format(
    //        FHIR_NAME, "project-id", "region-id", "dataset-id", "store-id", "resource-type",
    //  "resource-id");

    // Initialize the client, which will be used to interact with the service.
    CloudHealthcare client = createClient();

    HttpClient httpClient = HttpClients.createDefault();
    String uri = String.format("%sv1/%s/_history", client.getRootUrl(), resourceName);
    URIBuilder uriBuilder = new URIBuilder(uri).setParameter("access_token", getAccessToken());

    HttpUriRequest request =
        RequestBuilder.get()
            .setUri(uriBuilder.build())
            .addHeader("Content-Type", "application/fhir+json")
            .addHeader("Accept-Charset", "utf-8")
            .addHeader("Accept", "application/fhir+json; charset=utf-8")
            .build();

    // Execute the request and process the results.
    HttpResponse response = httpClient.execute(request);
    HttpEntity responseEntity = response.getEntity();
    if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
      System.err.print(
          String.format(
              "Exception retrieving FHIR history: %s\n", response.getStatusLine().toString()));
      responseEntity.writeTo(System.err);
      throw new RuntimeException();
    }
    System.out.println("FHIR resource history retrieved: ");
    responseEntity.writeTo(System.out);
  }

  private static CloudHealthcare createClient() throws IOException {
    // Use Application Default Credentials (ADC) to authenticate the requests
    // For more information see https://cloud.google.com/docs/authentication/production
    GoogleCredentials credential =
        GoogleCredentials.getApplicationDefault()
            .createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));

    // Create a HttpRequestInitializer, which will provide a baseline configuration to all requests.
    HttpRequestInitializer requestInitializer =
        request -> {
          new HttpCredentialsAdapter(credential).initialize(request);
          request.setConnectTimeout(60000); // 1 minute connect timeout
          request.setReadTimeout(60000); // 1 minute read timeout
        };

    // Build the client for interacting with the service.
    return new CloudHealthcare.Builder(HTTP_TRANSPORT, JSON_FACTORY, requestInitializer)
        .setApplicationName("your-application-name")
        .build();
  }

  private static String getAccessToken() throws IOException {
    GoogleCredentials credential =
        GoogleCredentials.getApplicationDefault()
            .createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));

    return credential.refreshAccessToken().getTokenValue();
  }
}

Node.js

const google = require('@googleapis/healthcare');
const healthcare = google.healthcare({
  version: 'v1',
  auth: new google.auth.GoogleAuth({
    scopes: ['https://www.googleapis.com/auth/cloud-platform'],
  }),
});

const listFhirResourceHistory = async () => {
  // TODO(developer): uncomment these lines before running the sample
  // const cloudRegion = 'us-central1';
  // const projectId = 'adjective-noun-123';
  // const datasetId = 'my-dataset';
  // const fhirStoreId = 'my-fhir-store';
  // const resourceType = 'Patient';
  // const resourceId = '16e8a860-33b3-49be-9b03-de979feed14a';
  const name = `projects/${projectId}/locations/${cloudRegion}/datasets/${datasetId}/fhirStores/${fhirStoreId}/fhir/${resourceType}/${resourceId}/_history`;
  const request = {name};

  const resource =
    await healthcare.projects.locations.datasets.fhirStores.fhir.read(
      request
    );
  console.log(JSON.stringify(resource.data, null, 2));
};

listFhirResourceHistory();

Python

# Imports the types Dict and Any for runtime type hints.
from typing import Any, Dict  # noqa: E402


def list_resource_history(
    project_id: str,
    location: str,
    dataset_id: str,
    fhir_store_id: str,
    resource_type: str,
    resource_id: str,
) -> Dict[str, Any]:
    """Gets the history of a resource.

    See
    https://github.com/GoogleCloudPlatform/python-docs-samples/tree/main/healthcare/api-client/v1/fhir
    before running the sample.
    See
    https://googleapis.github.io/google-api-python-client/docs/dyn/healthcare_v1.projects.locations.datasets.fhirStores.fhir.html#history
    for the Python API reference.

    Args:
      project_id: The project ID or project number of the Cloud project you want
        to use.
      location: The name of the parent dataset's location.
      dataset_id: The name of the parent dataset.
      fhir_store_id: The name of the FHIR store.
      resource_type: The type of FHIR resource.
      resource_id: The "logical id" of the resource whose history you want to
        list. The ID is assigned by the server.

    Returns:
      A dict representing the FHIR resource.
    """
    # Imports the Google API Discovery Service.
    from googleapiclient import discovery

    api_version = "v1"
    service_name = "healthcare"

    # Returns an authorized API client by discovering the Healthcare API
    # and using GOOGLE_APPLICATION_CREDENTIALS environment variable.
    client = discovery.build(service_name, api_version)

    # TODO(developer): Uncomment these lines and replace with your values.
    # project_id = 'my-project'
    # location = 'us-central1'
    # dataset_id = 'my-dataset'
    # fhir_store_id = 'my-fhir-store'
    # resource_type = 'Patient'
    # resource_id = 'b682d-0e-4843-a4a9-78c9ac64'
    fhir_store_parent = (
        f"projects/{project_id}/locations/{location}/datasets/{dataset_id}"
    )
    fhir_resource_path = f"{fhir_store_parent}/fhirStores/{fhir_store_id}/fhir/{resource_type}/{resource_id}"

    request = (
        client.projects()
        .locations()
        .datasets()
        .fhirStores()
        .fhir()
        .history(name=fhir_resource_path)
    )
    response = request.execute()
    print(
        f"History for {resource_type} resource with ID {resource_id}:\n"
        f" {json.dumps(response, indent=2)}"
    )
    return response

ๆ“ทๅ– FHIR ่ณ‡ๆบ็‰ˆๆœฌ

ไธ‹ๅˆ—็ฏ„ไพ‹่ชชๆ˜Žๅฆ‚ไฝ•ๆ“ทๅ–็‰นๅฎš็‰ˆๆœฌ็š„ FHIR ่ณ‡ๆบใ€‚ๅฆ‚่ฆๅฐ‹ๆ‰พ็‰นๅฎš็‰ˆๆœฌ๏ผŒๅฏไปฅๅˆ—ๅ‡บ FHIR ่ณ‡ๆบ็š„็‰ˆๆœฌ๏ผŒ็„ถๅพŒๆŸฅ็œ‹่ฉฒ็‰ˆๆœฌ็š„่ณ‡่จŠใ€‚็‰ˆๆœฌ ID ไฝๆ–ผ "versionId" ๆฌ„ไฝไธญใ€‚่ˆ‰ไพ‹ไพ†่ชช๏ผŒ่ซ‹ๅƒ้–ฑไธ‹ๅˆ— JSON ไธป้ซ”๏ผŒๅ…ถไธญ้†’็›ฎ้กฏ็คบไบ†ใ€Œๅˆ—ๅ‡บ FHIR ่ณ‡ๆบ็‰ˆๆœฌใ€ไธญ Observation ่ณ‡ๆบ็š„็‰ˆๆœฌ ID๏ผš

{
  "entry": [
    {
      "resource": {
        "effectiveDateTime": "2020-01-01T00:00:00+00:00",
        "id": "OBSERVATION_ID",
        "meta": {
          "lastUpdated": "2020-01-02T00:00:00+00:00",
          "versionId": "MTU0MTE5MDk5Mzk2ODcyODAwMA"
        },
...
    {
      "resource": {
        "encounter": {
          "reference": "Encounter/ENCOUNTER_ID"
        },
        "effectiveDateTime": "2020-01-01T00:00:00+00:00",
        "id": "OBSERVATION_ID",
        "meta": {
          "lastUpdated": "2020-01-01T00:00:00+00:00",
          "versionId": "MTU0MTE5MDg4MTY0MzQ3MjAwMA"
        },
...
}

ไธ‹ๅˆ—็ฏ„ไพ‹ๆœƒไฝฟ็”จใ€Œๅปบ็ซ‹ FHIR ่ณ‡ๆบใ€ไธญๅปบ็ซ‹็š„่ณ‡ๆบ๏ผŒไธฆ่ชชๆ˜Žๅฆ‚ไฝ•ๆŸฅ็œ‹ Observation ่ณ‡ๆบใ€‚REST ็ฏ„ไพ‹้ฉ็”จๆ–ผ R4 FHIR ๅ„ฒๅญ˜ๅบซใ€‚Goใ€Node.js ๅ’Œ Python ็ฏ„ไพ‹้ฉ็”จๆ–ผ STU3 FHIR ๅญ˜ๆ”พๅ€ใ€‚

ๆŽงๅˆถๅฐ

  1. ๅ‰ๅพ€ Google Cloud ๆŽงๅˆถๅฐ็š„ใ€ŒFHIR viewerใ€้ ้ขใ€‚

    ๅ‰ๅพ€ FHIR ๆชข่ฆ–ๅ™จ

  2. ๅœจใ€ŒFHIR storeใ€(FHIR ๅ„ฒๅญ˜ๅบซ) ้ธๅ–ฎไธญ้ธๅ–่ณ‡ๆ–™้›†๏ผŒ็„ถๅพŒ้ธๅ–่ณ‡ๆ–™้›†ไธญ็š„ FHIR ๅ„ฒๅญ˜ๅบซใ€‚

  3. ๅฆ‚่ฆ็ฏฉ้ธ FHIR ่ณ‡ๆบ้กžๅž‹ๆธ…ๅ–ฎ๏ผŒ่ซ‹ๆœๅฐ‹่ฆ้กฏ็คบ็š„่ณ‡ๆบ้กžๅž‹ใ€‚

  4. ๆŒ‰ไธ€ไธ‹ใ€Œ่ณ‡ๆบ้กžๅž‹ใ€ๆฌ„ไฝใ€‚

  5. ๅœจ้šจๅณๅ‡บ็พ็š„ใ€ŒPropertiesใ€(ๅฑฌๆ€ง) ไธ‹ๆ‹‰ๅผๆธ…ๅ–ฎไธญ้ธๅ–ใ€ŒResource Typeใ€(่ณ‡ๆบ้กžๅž‹)ใ€‚

  6. ่ผธๅ…ฅ FHIR ่ณ‡ๆบ้กžๅž‹ใ€‚

  7. ๅœจ FHIR ่ณ‡ๆบ้กžๅž‹ๆธ…ๅ–ฎไธญ๏ผŒ้ธๅ–่ณ‡ๆบ้กžๅž‹ใ€‚

  8. ๅœจ้šจๅณ้กฏ็คบ็š„ FHIR ่ณ‡ๆบ่กจๆ ผไธญ๏ผŒ้ธๅ–ๆˆ–ๆœๅฐ‹่ณ‡ๆบใ€‚

  9. ๅฆ‚่ฆๆŸฅ็œ‹็‰นๅฎš็‰ˆๆœฌ็š„ FHIR ่ณ‡ๆบ๏ผŒ่ซ‹ๆŒ‰็…งไธ‹ๅˆ—ๆญฅ้ฉŸๆ“ไฝœ๏ผš

    1. ๆŒ‰ไธ€ไธ‹ใ€Œ็ธฝ่ฆฝใ€ๅˆ†้ ๆจ™็ฑคใ€‚
    2. ๅœจใ€Œ็‰ˆๆœฌ IDใ€ๆ‰€ๅœจ็š„ๅˆ—ไธญ๏ผŒๆŒ‰ไธ€ไธ‹ใ€ŒๆŸฅ็œ‹ๆญทไพ†็‰ˆๆœฌใ€ใ€‚
    3. ๅœจใ€ŒSelect a resource versionใ€(้ธๅ–่ณ‡ๆบ็‰ˆๆœฌ) ็ช—ๆ ผไธญ๏ผŒ้ธๅ–็‰ˆๆœฌ๏ผŒ็„ถๅพŒๆŒ‰ไธ€ไธ‹ใ€ŒConfirmใ€(็ขบ่ช)ใ€‚็‰ˆๆœฌไธญ็š„่ณ‡ๆ–™ๆœƒๅกซๅ…ฅใ€Œ็ธฝ่ฆฝใ€ใ€ใ€Œๅ…ƒ็ด ใ€ๅ’Œใ€ŒJSONใ€ๅˆ†้ ใ€‚

REST

่ซ‹ไฝฟ็”จ projects.locations.datasets.fhirStores.fhir.vread ๆ–นๆณ•ใ€‚

ไฝฟ็”จไปปไฝ•่ฆๆฑ‚่ณ‡ๆ–™ไน‹ๅ‰๏ผŒ่ซ‹ๅ…ˆๆ›ฟๆ›ไปฅไธ‹้ …็›ฎ๏ผš

  • PROJECT_ID๏ผšๆ‚จ็š„ Google Cloud ๅฐˆๆกˆ ID
  • LOCATION๏ผš่ณ‡ๆ–™้›†ไฝ็ฝฎ
  • DATASET_ID๏ผšFHIR ๅ„ฒๅญ˜ๅบซ็š„็ˆถ้ …่ณ‡ๆ–™้›†
  • FHIR_STORE_ID๏ผšFHIR ๅ„ฒๅญ˜ๅบซ ID
  • RESOURCE_TYPE๏ผšFHIR ่ณ‡ๆบ้กžๅž‹
  • RESOURCE_ID๏ผšFHIR ่ณ‡ๆบ ID
  • RESOURCE_VERSION๏ผšFHIR ่ณ‡ๆบ็‰ˆๆœฌ

ๅฆ‚่ฆๅ‚ณ้€่ฆๆฑ‚๏ผŒ่ซ‹้ธๆ“‡ไปฅไธ‹ๅ…ถไธญไธ€ๅ€‹้ธ้ …๏ผš

curl

ไธ‹ๅˆ—็ฏ„ไพ‹่ชชๆ˜Žๅฆ‚ไฝ•ๅˆ—ๅ‡บ Observation ่ณ‡ๆบ็š„ๆ‰€ๆœ‰็‰ˆๆœฌใ€‚ๅŽŸๅง‹ๅปบ็ซ‹ๅพŒ๏ผŒ็ณป็ตฑๆ›ดๆ–ฐไบ†ใ€Œ่ง€ๅฏŸใ€ไธ€ๆฌก๏ผŒ่ฎŠๆ›ด็—…ๆ‚ฃๆฏๅˆ†้˜ๅฟƒ่ทณๆฌกๆ•ธ (BPM)ใ€‚

ๅŸท่กŒไธ‹ๅˆ—ๆŒ‡ไปค๏ผš

curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/fhirStores/FHIR_STORE_ID/fhir/RESOURCE_TYPE/RESOURCE_ID/_history/RESOURCE_VERSION"

PowerShell

ไธ‹ๅˆ—็ฏ„ไพ‹่ชชๆ˜Žๅฆ‚ไฝ•ๅˆ—ๅ‡บ Observation ่ณ‡ๆบ็š„ๆ‰€ๆœ‰็‰ˆๆœฌใ€‚ๅŽŸๅง‹ๅปบ็ซ‹ๅพŒ๏ผŒ็ณป็ตฑๆ›ดๆ–ฐไบ†ใ€Œ่ง€ๅฏŸใ€ไธ€ๆฌก๏ผŒ่ฎŠๆ›ด็—…ๆ‚ฃๆฏๅˆ†้˜ๅฟƒ่ทณๆฌกๆ•ธ (BPM)ใ€‚

ๅŸท่กŒไธ‹ๅˆ—ๆŒ‡ไปค๏ผš

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method GET `
-Headers $headers `
-Uri "https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/fhirStores/FHIR_STORE_ID/fhir/RESOURCE_TYPE/RESOURCE_ID/_history/RESOURCE_VERSION" | Select-Object -Expand Content
ๅฆ‚ๆžœ่ฆๆฑ‚ๆˆๅŠŸ๏ผŒไผบๆœๅ™จๆœƒไปฅ JSON ๆ ผๅผๅ‚ณๅ›žๅ›žๆ‡‰ใ€‚ๅœจๆœฌไพ‹ไธญ๏ผŒ็ณป็ตฑๆœƒๅ‚ณๅ›ž็ฌฌไธ€ๅ€‹็‰ˆๆœฌ็š„ Observation๏ผŒๅ…ถไธญ็—…ๆ‚ฃ็š„ๅฟƒ็އ็‚บ 75 BPMใ€‚
{
  "encounter": {
    "reference": "Encounter/ENCOUNTER_ID"
  },
  "effectiveDateTime": "2020-01-01T00:00:00+00:00",
  "id": "OBSERVATION_ID",
  "meta": {
    "lastUpdated": "2020-01-01T00:00:00+00:00",
    "versionId": "MTU0MTE5MDg4MTY0MzQ3MjAwMA"
  },
  "resourceType": "Observation",
  "status": "final",
  "subject": {
    "reference": "Patient/PATIENT_ID"
  },
  "valueQuantity": {
    "unit": "bpm",
    "value": 75
  }
}

Go

import (
	"context"
	"fmt"
	"io"

	healthcare "google.golang.org/api/healthcare/v1"
)

// getFHIRResourceHistory gets an FHIR resource history.
func getFHIRResourceHistory(w io.Writer, projectID, location, datasetID, fhirStoreID, resourceType, fhirResourceID, versionID string) error {
	ctx := context.Background()

	healthcareService, err := healthcare.NewService(ctx)
	if err != nil {
		return fmt.Errorf("healthcare.NewService: %w", err)
	}

	fhirService := healthcareService.Projects.Locations.Datasets.FhirStores.Fhir

	name := fmt.Sprintf("projects/%s/locations/%s/datasets/%s/fhirStores/%s/fhir/%s/%s/_history/%s", projectID, location, datasetID, fhirStoreID, resourceType, fhirResourceID, versionID)

	resp, err := fhirService.Vread(name).Do()
	if err != nil {
		return fmt.Errorf("Vread: %w", err)
	}

	defer resp.Body.Close()

	respBytes, err := io.ReadAll(resp.Body)
	if err != nil {
		return fmt.Errorf("could not read response: %w", err)
	}

	if resp.StatusCode > 299 {
		return fmt.Errorf("Vread: status %d %s: %s", resp.StatusCode, resp.Status, respBytes)
	}
	fmt.Fprintf(w, "%s", respBytes)

	return nil
}

Java

import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.gson.GsonFactory;
import com.google.api.services.healthcare.v1.CloudHealthcare;
import com.google.api.services.healthcare.v1.CloudHealthcareScopes;
import com.google.auth.http.HttpCredentialsAdapter;
import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.Collections;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.client.methods.RequestBuilder;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.impl.client.HttpClients;

public class FhirResourceGetHistory {
  private static final String FHIR_NAME =
      "projects/%s/locations/%s/datasets/%s/fhirStores/%s/fhir/%s/%s";
  private static final JsonFactory JSON_FACTORY = new GsonFactory();
  private static final NetHttpTransport HTTP_TRANSPORT = new NetHttpTransport();

  public static void fhirResourceGetHistory(String resourceName, String versionId)
      throws IOException, URISyntaxException {
    // String resourceName =
    //    String.format(
    //        FHIR_NAME, "project-id", "region-id", "dataset-id", "store-id", "resource-type",
    // "resource-id");
    // String versionId = "version-uuid"

    // Initialize the client, which will be used to interact with the service.
    CloudHealthcare client = createClient();

    HttpClient httpClient = HttpClients.createDefault();
    String uri = String.format("%sv1/%s/_history/%s", client.getRootUrl(), resourceName, versionId);
    URIBuilder uriBuilder = new URIBuilder(uri).setParameter("access_token", getAccessToken());

    HttpUriRequest request =
        RequestBuilder.get()
            .setUri(uriBuilder.build())
            .addHeader("Content-Type", "application/fhir+json")
            .addHeader("Accept-Charset", "utf-8")
            .addHeader("Accept", "application/fhir+json; charset=utf-8")
            .build();

    // Execute the request and process the results.
    HttpResponse response = httpClient.execute(request);
    HttpEntity responseEntity = response.getEntity();
    if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
      System.err.print(
          String.format(
              "Exception retrieving FHIR history: %s\n", response.getStatusLine().toString()));
      responseEntity.writeTo(System.err);
      throw new RuntimeException();
    }
    System.out.println("FHIR resource retrieved from version: ");
    responseEntity.writeTo(System.out);
  }

  private static CloudHealthcare createClient() throws IOException {
    // Use Application Default Credentials (ADC) to authenticate the requests
    // For more information see https://cloud.google.com/docs/authentication/production
    GoogleCredentials credential =
        GoogleCredentials.getApplicationDefault()
            .createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));

    // Create a HttpRequestInitializer, which will provide a baseline configuration to all requests.
    HttpRequestInitializer requestInitializer =
        request -> {
          new HttpCredentialsAdapter(credential).initialize(request);
          request.setConnectTimeout(60000); // 1 minute connect timeout
          request.setReadTimeout(60000); // 1 minute read timeout
        };

    // Build the client for interacting with the service.
    return new CloudHealthcare.Builder(HTTP_TRANSPORT, JSON_FACTORY, requestInitializer)
        .setApplicationName("your-application-name")
        .build();
  }

  private static String getAccessToken() throws IOException {
    GoogleCredentials credential =
        GoogleCredentials.getApplicationDefault()
            .createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));

    return credential.refreshAccessToken().getTokenValue();
  }
}

Node.js

const google = require('@googleapis/healthcare');
const healthcare = google.healthcare({
  version: 'v1',
  auth: new google.auth.GoogleAuth({
    scopes: ['https://www.googleapis.com/auth/cloud-platform'],
  }),
});

const getFhirResourceHistory = async () => {
  // TODO(developer): uncomment these lines before running the sample
  // const cloudRegion = 'us-central1';
  // const projectId = 'adjective-noun-123';
  // const datasetId = 'my-dataset';
  // const fhirStoreId = 'my-fhir-store';
  // const resourceType = 'Patient';
  // const resourceId = '16e8a860-33b3-49be-9b03-de979feed14a';
  // const versionId = 'MTU2NPg3NDgyNDAxMDc4OTAwMA';
  const name = `projects/${projectId}/locations/${cloudRegion}/datasets/${datasetId}/fhirStores/${fhirStoreId}/fhir/${resourceType}/${resourceId}/_history/${versionId}`;
  const request = {name};

  const resource =
    await healthcare.projects.locations.datasets.fhirStores.fhir.vread(
      request
    );
  console.log(JSON.stringify(resource.data, null, 2));
};

getFhirResourceHistory();

Python

# Imports the types Dict and Any for runtime type hints.
from typing import Any, Dict  # noqa: E402


def get_resource_history(
    project_id: str,
    location: str,
    dataset_id: str,
    fhir_store_id: str,
    resource_type: str,
    resource_id: str,
    version_id: str,
) -> Dict[str, Any]:
    """Gets the contents of a version (current or historical) of a FHIR resource by version ID.

    See
    https://github.com/GoogleCloudPlatform/python-docs-samples/tree/main/healthcare/api-client/v1/fhir
    before running the sample.
    See
    https://googleapis.github.io/google-api-python-client/docs/dyn/healthcare_v1.projects.locations.datasets.fhirStores.fhir.html#vread
    for the Python API reference.

    Args:
      project_id: The project ID or project number of the Cloud project you want
        to use.
      location: The name of the parent dataset's location.
      dataset_id: The name of the parent dataset.
      fhir_store_id: The name of the FHIR store.
      resource_type: The type of FHIR resource.
      resource_id: The "logical id" of the resource whose details you want to view
        at a particular version. The ID is assigned by the server.
      version_id: The ID of the version. Changes whenever the FHIR resource is
        modified.

    Returns:
      A dict representing the FHIR resource at the specified version.
    """
    # Imports the Google API Discovery Service.
    from googleapiclient import discovery

    api_version = "v1"
    service_name = "healthcare"

    # Returns an authorized API client by discovering the Healthcare API
    # and using GOOGLE_APPLICATION_CREDENTIALS environment variable.
    client = discovery.build(service_name, api_version)

    # TODO(developer): Uncomment these lines and replace with your values.
    # project_id = 'my-project'
    # location = 'us-central1'
    # dataset_id = 'my-dataset'
    # fhir_store_id = 'my-fhir-store'
    # resource_type = 'Patient'
    # resource_id = 'b682d-0e-4843-a4a9-78c9ac64'
    # version_id = 'MTY4NDQ1MDc3MDU2ODgyNzAwMA'
    fhir_store_parent = (
        f"projects/{project_id}/locations/{location}/datasets/{dataset_id}"
    )
    fhir_resource_path = f"{fhir_store_parent}/fhirStores/{fhir_store_id}/fhir/{resource_type}/{resource_id}/_history/{version_id}"

    request = (
        client.projects()
        .locations()
        .datasets()
        .fhirStores()
        .fhir()
        .vread(name=fhir_resource_path)
    )
    response = request.execute()
    print(
        f"Got contents of {resource_type} resource with ID {resource_id} at"
        f" version {version_id}:\n {json.dumps(response, indent=2)}"
    )

    return response

ๅˆช้™ค FHIR ่ณ‡ๆบ

ไธ‹ๅˆ—็ฏ„ไพ‹่ชชๆ˜Žๅฆ‚ไฝ•ๅ‘ผๅซ projects.locations.datasets.fhirStores.fhir.delete ๆ–นๆณ•๏ผŒๅˆช้™ค Observation FHIR ่ณ‡ๆบใ€‚

็„ก่ซ–ไฝœๆฅญๆˆๅŠŸๆˆ–ๅคฑๆ•—๏ผŒไผบๆœๅ™จ้ƒฝๆœƒๅ‚ณๅ›ž 200 OK HTTP ็‹€ๆ…‹็ขผใ€‚ๅฆ‚่ฆ็ขบ่ช่ณ‡ๆบๆ˜ฏๅฆๅทฒๆˆๅŠŸๅˆช้™ค๏ผŒ่ซ‹ๆœๅฐ‹ๆˆ–ๅ–ๅพ—่ฉฒ่ณ‡ๆบ๏ผŒไธฆ็ขบ่ช่ณ‡ๆบๆ˜ฏๅฆๅญ˜ๅœจใ€‚

ไธ‹ๅˆ— REST ็ฏ„ไพ‹้ฉ็”จๆ–ผ R4 FHIR ๅ„ฒๅญ˜ๅบซใ€‚Goใ€Javaใ€Node.js ๅ’Œ Python ็ฏ„ไพ‹้ฉ็”จๆ–ผ STU3 FHIR ๅญ˜ๆ”พๅ€ใ€‚

REST

ไฝฟ็”จไปปไฝ•่ฆๆฑ‚่ณ‡ๆ–™ไน‹ๅ‰๏ผŒ่ซ‹ๅ…ˆๆ›ฟๆ›ไปฅไธ‹้ …็›ฎ๏ผš

  • PROJECT_ID๏ผšๆ‚จ็š„ Google Cloud ๅฐˆๆกˆ ID
  • LOCATION๏ผš่ณ‡ๆ–™้›†ไฝ็ฝฎ
  • DATASET_ID๏ผšFHIR ๅ„ฒๅญ˜ๅบซ็š„็ˆถ้ …่ณ‡ๆ–™้›†
  • FHIR_STORE_ID๏ผšFHIR ๅ„ฒๅญ˜ๅบซ ID
  • OBSERVATION_ID๏ผšObservation ่ณ‡ๆบ ID

ๅฆ‚่ฆๅ‚ณ้€่ฆๆฑ‚๏ผŒ่ซ‹้ธๆ“‡ไปฅไธ‹ๅ…ถไธญไธ€ๅ€‹้ธ้ …๏ผš

curl

ๅŸท่กŒไธ‹ๅˆ—ๆŒ‡ไปค๏ผš

curl -X DELETE \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/fhirStores/FHIR_STORE_ID/fhir/Observation/OBSERVATION_ID"

PowerShell

ๅŸท่กŒไธ‹ๅˆ—ๆŒ‡ไปค๏ผš

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method DELETE `
-Headers $headers `
-Uri "https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/fhirStores/FHIR_STORE_ID/fhir/Observation/OBSERVATION_ID" | Select-Object -Expand Content

APIs Explorer

้–‹ๅ•Ÿๆ–นๆณ•ๅƒ่€ƒ้ ้ขใ€‚็ณป็ตฑๆœƒๅœจ้ ้ขๅณๅด้–‹ๅ•Ÿ APIs Explorer ้ขๆฟใ€‚ๆ‚จๅฏไปฅไฝฟ็”จ้€™้ …ๅทฅๅ…ทไพ†ๅ‚ณ้€่ฆๆฑ‚ใ€‚ๅฎŒๆˆไปปไฝ•ๅฟ…ๅกซๆฌ„ไฝ๏ผŒ็„ถๅพŒๆŒ‰ไธ€ไธ‹ใ€ŒๅŸท่กŒใ€ใ€‚

ๆ‚จๆ‡‰่ฉฒๆœƒๆ”ถๅˆฐๅฆ‚ไธ‹็š„ JSON ๅ›žๆ‡‰๏ผš

Go

import (
	"context"
	"fmt"
	"io"

	healthcare "google.golang.org/api/healthcare/v1"
)

// deleteFHIRResource deletes an FHIR resource.
// Regardless of whether the operation succeeds or
// fails, the server returns a 200 OK HTTP status code. To check that the
// resource was successfully deleted, search for or get the resource and
// see if it exists.
func deleteFHIRResource(w io.Writer, projectID, location, datasetID, fhirStoreID, resourceType, fhirResourceID string) error {
	ctx := context.Background()

	healthcareService, err := healthcare.NewService(ctx)
	if err != nil {
		return fmt.Errorf("healthcare.NewService: %w", err)
	}

	fhirService := healthcareService.Projects.Locations.Datasets.FhirStores.Fhir

	name := fmt.Sprintf("projects/%s/locations/%s/datasets/%s/fhirStores/%s/fhir/%s/%s", projectID, location, datasetID, fhirStoreID, resourceType, fhirResourceID)

	if _, err := fhirService.Delete(name).Do(); err != nil {
		return fmt.Errorf("Delete: %w", err)
	}

	fmt.Fprintf(w, "Deleted %q", name)

	return nil
}

Java

import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.gson.GsonFactory;
import com.google.api.services.healthcare.v1.CloudHealthcare;
import com.google.api.services.healthcare.v1.CloudHealthcareScopes;
import com.google.auth.http.HttpCredentialsAdapter;
import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.Collections;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.client.methods.RequestBuilder;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.impl.client.HttpClients;

public class FhirResourceDelete {
  private static final String FHIR_NAME =
      "projects/%s/locations/%s/datasets/%s/fhirStores/%s/fhir/%s/%s";
  private static final JsonFactory JSON_FACTORY = new GsonFactory();
  private static final NetHttpTransport HTTP_TRANSPORT = new NetHttpTransport();

  public static void fhirResourceDelete(String resourceName)
      throws IOException, URISyntaxException {
    // String resourceName =
    //    String.format(
    //        FHIR_NAME, "project-id", "region-id", "dataset-id", "store-id", "resource-type",
    // "resource-id");

    // Initialize the client, which will be used to interact with the service.
    CloudHealthcare client = createClient();

    HttpClient httpClient = HttpClients.createDefault();
    String uri = String.format("%sv1/%s", client.getRootUrl(), resourceName);
    URIBuilder uriBuilder = new URIBuilder(uri).setParameter("access_token", getAccessToken());

    HttpUriRequest request =
        RequestBuilder.delete()
            .setUri(uriBuilder.build())
            .addHeader("Content-Type", "application/fhir+json")
            .addHeader("Accept-Charset", "utf-8")
            .addHeader("Accept", "application/fhir+json; charset=utf-8")
            .build();

    // Execute the request and process the results.
    // Regardless of whether the operation succeeds or
    // fails, the server returns a 200 OK HTTP status code. To check that the
    // resource was successfully deleted, search for or get the resource and
    // see if it exists.
    HttpResponse response = httpClient.execute(request);
    HttpEntity responseEntity = response.getEntity();
    if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
      String errorMessage =
          String.format(
              "Exception deleting FHIR resource: %s\n", response.getStatusLine().toString());
      System.err.print(errorMessage);
      responseEntity.writeTo(System.err);
      throw new RuntimeException(errorMessage);
    }
    System.out.println("FHIR resource deleted.");
    responseEntity.writeTo(System.out);
  }

  private static CloudHealthcare createClient() throws IOException {
    // Use Application Default Credentials (ADC) to authenticate the requests
    // For more information see https://cloud.google.com/docs/authentication/production
    GoogleCredentials credential =
        GoogleCredentials.getApplicationDefault()
            .createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));

    // Create a HttpRequestInitializer, which will provide a baseline configuration to all requests.
    HttpRequestInitializer requestInitializer =
        request -> {
          new HttpCredentialsAdapter(credential).initialize(request);
          request.setConnectTimeout(60000); // 1 minute connect timeout
          request.setReadTimeout(60000); // 1 minute read timeout
        };

    // Build the client for interacting with the service.
    return new CloudHealthcare.Builder(HTTP_TRANSPORT, JSON_FACTORY, requestInitializer)
        .setApplicationName("your-application-name")
        .build();
  }

  private static String getAccessToken() throws IOException {
    GoogleCredentials credential =
        GoogleCredentials.getApplicationDefault()
            .createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));

    return credential.refreshAccessToken().getTokenValue();
  }
}

Node.js

const google = require('@googleapis/healthcare');
const healthcare = google.healthcare({
  version: 'v1',
  auth: new google.auth.GoogleAuth({
    scopes: ['https://www.googleapis.com/auth/cloud-platform'],
  }),
});

const deleteFhirResource = async () => {
  // TODO(developer): uncomment these lines before running the sample
  // const cloudRegion = 'us-central1';
  // const projectId = 'adjective-noun-123';
  // const datasetId = 'my-dataset';
  // const fhirStoreId = 'my-fhir-store';
  // const resourceType = 'Patient';
  // const resourceId = '9a664e07-79a4-4c2e-04ed-e996c75484e1';
  const name = `projects/${projectId}/locations/${cloudRegion}/datasets/${datasetId}/fhirStores/${fhirStoreId}/fhir/${resourceType}/${resourceId}`;
  const request = {name};

  // Regardless of whether the operation succeeds or
  // fails, the server returns a 200 OK HTTP status code. To check that the
  // resource was successfully deleted, search for or get the resource and
  // see if it exists.
  await healthcare.projects.locations.datasets.fhirStores.fhir.delete(
    request
  );
  console.log('Deleted FHIR resource');
};

deleteFhirResource();

Python

def delete_resource(
    project_id: str,
    location: str,
    dataset_id: str,
    fhir_store_id: str,
    resource_type: str,
    resource_id: str,
) -> dict:
    """Deletes a FHIR resource.

    Regardless of whether the operation succeeds or
    fails, the server returns a 200 OK HTTP status code. To check that the
    resource was successfully deleted, search for or get the resource and
    see if it exists.

    See
    https://github.com/GoogleCloudPlatform/python-docs-samples/tree/main/healthcare/api-client/v1/fhir
    before running the sample.
    See
    https://googleapis.github.io/google-api-python-client/docs/dyn/healthcare_v1.projects.locations.datasets.fhirStores.fhir.html#delete
    for the Python API reference.
    Args:
      project_id: The project ID or project number of the Cloud project you want
        to use.
      location: The name of the parent dataset's location.
      dataset_id: The name of the parent dataset.
      fhir_store_id: The name of the FHIR store.
      resource_type: The type of the FHIR resource.
      resource_id: The "logical id" of the FHIR resource you want to delete. The
        ID is assigned by the server.

    Returns:
      An empty dict.
    """
    # Imports the Google API Discovery Service.
    from googleapiclient import discovery

    api_version = "v1"
    service_name = "healthcare"

    # Returns an authorized API client by discovering the Healthcare API
    # and using GOOGLE_APPLICATION_CREDENTIALS environment variable.
    client = discovery.build(service_name, api_version)

    # TODO(developer): Uncomment these lines and replace with your values.
    # project_id = 'my-project'
    # location = 'us-central1'
    # dataset_id = 'my-dataset'
    # fhir_store_id = 'my-fhir-store'
    # resource_type = 'Patient'
    # resource_id = 'b682d-0e-4843-a4a9-78c9ac64'
    fhir_store_parent = (
        f"projects/{project_id}/locations/{location}/datasets/{dataset_id}"
    )
    fhir_resource_path = f"{fhir_store_parent}/fhirStores/{fhir_store_id}/fhir/{resource_type}/{resource_id}"

    request = (
        client.projects()
        .locations()
        .datasets()
        .fhirStores()
        .fhir()
        .delete(name=fhir_resource_path)
    )
    response = request.execute()
    print(f"Deleted {resource_type} resource with ID {resource_id}.")

    return response

ๆœ‰ๆขไปถๅœฐๅˆช้™ค FHIR ่ณ‡ๆบ

ๅœจ Cloud Healthcare API ็ฌฌ 1 ็‰ˆไธญ๏ผŒๆขไปถๅผไฝœๆฅญๆœƒๅฐˆ้–€ไฝฟ็”จ identifier ๆœๅฐ‹ๅƒๆ•ธ (ๅฆ‚ๆžœ FHIR ่ณ‡ๆบ้กžๅž‹ๆœ‰้€™ๅ€‹ๅƒๆ•ธ)๏ผŒๅˆคๆ–ทๅ“ชไบ› FHIR ่ณ‡ๆบ็ฌฆๅˆๆขไปถๅผๆœๅฐ‹ๆŸฅ่ฉขใ€‚

ๅชๆœ‰ๅœจ FHIR ่ณ‡ๆบ็š„ identifier.system ็‚บ my-code-system ไธ” identifier.value ็‚บ ABC-12345 ๆ™‚๏ผŒ่ฉฒ่ณ‡ๆบๆ‰ๆœƒ็ฌฆๅˆๆŸฅ่ฉข ?identifier=my-code-system|ABC-12345ใ€‚ๅฆ‚ๆžœ FHIR ่ณ‡ๆบ็ฌฆๅˆๆŸฅ่ฉขๆขไปถ๏ผŒCloud Healthcare API ๅฐฑๆœƒๅˆช้™ค่ฉฒ่ณ‡ๆบใ€‚

ๅฆ‚ๆžœๆŸฅ่ฉขไฝฟ็”จ identifier ๆœๅฐ‹ๅƒๆ•ธ๏ผŒไธ”็ฌฆๅˆๅคšๅ€‹ FHIR ่ณ‡ๆบ๏ผŒCloud Healthcare API ๆœƒๅ‚ณๅ›ž "412 - Condition not selective enough" ้Œฏ่ชคใ€‚ๅฆ‚่ฆๅ€‹ๅˆฅๅˆช้™ค่ณ‡ๆบ๏ผŒ่ซ‹ๆŒ‰็…งไธ‹ๅˆ—ๆญฅ้ฉŸๆ“ไฝœ๏ผš

  1. ๆœๅฐ‹ๆฏๅ€‹่ณ‡ๆบ๏ผŒๅ–ๅพ—ไผบๆœๅ™จๆŒ‡ๆดพ็š„ๅฐˆๅฑฌ IDใ€‚
  2. ไฝฟ็”จ ID ้€ไธ€ๅˆช้™คๅ„้ …่ณ‡ๆบใ€‚

ไธ‹ๅˆ—็ฏ„ไพ‹่ชชๆ˜Žๅฆ‚ไฝ•ๆœ‰ๆขไปถๅœฐๅˆช้™ค็ฌฆๅˆๆœๅฐ‹ๆŸฅ่ฉข็š„ FHIR ่ณ‡ๆบ๏ผŒ่€Œไธๆ˜ฏไพๆ“š ID ่ญ˜ๅˆฅ FHIR ่ณ‡ๆบใ€‚ๆœๅฐ‹ๆŸฅ่ฉขๆœƒไฝฟ็”จ Observation ็š„ ID (ABC-12345 ไธญ็š„ my-code-system) ๆฏ”ๅฐไธฆๅˆช้™ค Observation ่ณ‡ๆบใ€‚

REST

่ซ‹ไฝฟ็”จ projects.locations.datasets.fhirStores.fhir.conditionalDelete ๆ–นๆณ•ใ€‚

ไฝฟ็”จไปปไฝ•่ฆๆฑ‚่ณ‡ๆ–™ไน‹ๅ‰๏ผŒ่ซ‹ๅ…ˆๆ›ฟๆ›ไปฅไธ‹้ …็›ฎ๏ผš

  • PROJECT_ID๏ผšๆ‚จ็š„ Google Cloud ๅฐˆๆกˆ ID
  • LOCATION๏ผš่ณ‡ๆ–™้›†ไฝ็ฝฎ
  • DATASET_ID๏ผšFHIR ๅ„ฒๅญ˜ๅบซ็š„็ˆถ้ …่ณ‡ๆ–™้›†
  • FHIR_STORE_ID๏ผšFHIR ๅ„ฒๅญ˜ๅบซ ID

ๅฆ‚่ฆๅ‚ณ้€่ฆๆฑ‚๏ผŒ่ซ‹้ธๆ“‡ไปฅไธ‹ๅ…ถไธญไธ€ๅ€‹้ธ้ …๏ผš

curl

ๅŸท่กŒไธ‹ๅˆ—ๆŒ‡ไปค๏ผš

curl -X DELETE \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/fhirStores/FHIR_STORE_ID/fhir/Observation?identifier=my-code-system|ABC-12345"

PowerShell

ๅŸท่กŒไธ‹ๅˆ—ๆŒ‡ไปค๏ผš

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method DELETE `
-Headers $headers `
-Uri "https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/fhirStores/FHIR_STORE_ID/fhir/Observation?identifier=my-code-system|ABC-12345" | Select-Object -Expand Content

APIs Explorer

้–‹ๅ•Ÿๆ–นๆณ•ๅƒ่€ƒ้ ้ขใ€‚็ณป็ตฑๆœƒๅœจ้ ้ขๅณๅด้–‹ๅ•Ÿ APIs Explorer ้ขๆฟใ€‚ๆ‚จๅฏไปฅไฝฟ็”จ้€™้ …ๅทฅๅ…ทไพ†ๅ‚ณ้€่ฆๆฑ‚ใ€‚ๅฎŒๆˆไปปไฝ•ๅฟ…ๅกซๆฌ„ไฝ๏ผŒ็„ถๅพŒๆŒ‰ไธ€ไธ‹ใ€ŒๅŸท่กŒใ€ใ€‚

ๆ‚จๆ‡‰่ฉฒๆœƒๆ”ถๅˆฐๅŸท่กŒๆˆๅŠŸ็š„็‹€ๆ…‹็ขผ (2xx) ๅ’Œ็ฉบ็™ฝๅ›žๆ‡‰ใ€‚

ๅˆช้™ค FHIR ่ณ‡ๆบ็š„ๆญทๅฒ็‰ˆๆœฌ

ไธ‹ๅˆ—็ฏ„ไพ‹่ชชๆ˜Žๅฆ‚ไฝ•ไฝฟ็”จ projects.locations.datasets.fhirStores.fhir.Resource-purge ๆ–นๆณ•๏ผŒๅˆช้™ค FHIR ่ณ‡ๆบ็š„ๆ‰€ๆœ‰ๆญทๅฒ็‰ˆๆœฌใ€‚

ๅชๆœ‰ๅ…ทๅ‚™ roles/healthcare.fhirStoreAdmin ่ง’่‰ฒ็š„ไฝฟ็”จ่€… (ๅ‘ผๅซ่€…) ๆ‰่ƒฝๅ‘ผๅซ projects.locations.datasets.fhirStores.fhir.Resource-purge ๆ–นๆณ•๏ผ›ๅ…ทๅ‚™ roles/healthcare.fhirResourceEditor ่ง’่‰ฒ็š„ไฝฟ็”จ่€…็„กๆณ•ๅ‘ผๅซ้€™ๅ€‹ๆ–นๆณ•ใ€‚ๅฆ‚่ฆๅ…่จฑๅ‘ผๅซ็ซฏๅˆช้™ค FHIR ่ณ‡ๆบ็š„ๆญทๅฒ็‰ˆๆœฌ๏ผŒ่ซ‹ๆŽกๅ–ไธ‹ๅˆ—ไปปไธ€ๅšๆณ•๏ผš

  • ็ขบ่ชๅ‘ผๅซ่€…ๅ…ทๅ‚™ roles/healthcare.fhirStoreAdmin ่ง’่‰ฒใ€‚
  • ๅปบ็ซ‹ๅ…ทๆœ‰ healthcare.fhirResources.purge ๆฌŠ้™็š„่‡ช่จ‚ IAM ่ง’่‰ฒ๏ผŒไธฆๅฐ‡่ฉฒ่ง’่‰ฒๆŒ‡ๆดพ็ตฆๅ‘ผๅซ่€…ใ€‚

้€™ไบ›็ฏ„ไพ‹ๆœƒไฝฟ็”จใ€Œๅปบ็ซ‹ FHIR ่ณ‡ๆบใ€ไธญๅปบ็ซ‹็š„่ณ‡ๆบ๏ผŒไธฆ่ชชๆ˜Žๅฆ‚ไฝ•ๅˆช้™ค Observation ่ณ‡ๆบ็š„ๆญทๅฒ็‰ˆๆœฌใ€‚

ไธ‹ๅˆ— REST ็ฏ„ไพ‹้ฉ็”จๆ–ผ R4 FHIR ๅ„ฒๅญ˜ๅบซใ€‚Goใ€Javaใ€Node.js ๅ’Œ Python ็ฏ„ไพ‹้ฉ็”จๆ–ผ STU3 FHIR ๅญ˜ๆ”พๅ€ใ€‚

REST

่ซ‹ไฝฟ็”จ projects.locations.datasets.fhirStores.fhir.Resource-purge ๆ–นๆณ•ใ€‚

ไฝฟ็”จไปปไฝ•่ฆๆฑ‚่ณ‡ๆ–™ไน‹ๅ‰๏ผŒ่ซ‹ๅ…ˆๆ›ฟๆ›ไปฅไธ‹้ …็›ฎ๏ผš

  • PROJECT_ID๏ผšๆ‚จ็š„ Google Cloud ๅฐˆๆกˆ ID
  • LOCATION๏ผš่ณ‡ๆ–™้›†ไฝ็ฝฎ
  • DATASET_ID๏ผšFHIR ๅ„ฒๅญ˜ๅบซ็š„็ˆถ้ …่ณ‡ๆ–™้›†
  • FHIR_STORE_ID๏ผšFHIR ๅ„ฒๅญ˜ๅบซ ID
  • RESOURCE_TYPE๏ผšFHIR ่ณ‡ๆบ้กžๅž‹
  • RESOURCE_ID๏ผšFHIR ่ณ‡ๆบ ID

ๅฆ‚่ฆๅ‚ณ้€่ฆๆฑ‚๏ผŒ่ซ‹้ธๆ“‡ไปฅไธ‹ๅ…ถไธญไธ€ๅ€‹้ธ้ …๏ผš

curl

ๅŸท่กŒไธ‹ๅˆ—ๆŒ‡ไปค๏ผš

curl -X DELETE \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/fhirStores/FHIR_STORE_ID/fhir/RESOURCE_TYPE/RESOURCE_ID/$purge"

PowerShell

ๅŸท่กŒไธ‹ๅˆ—ๆŒ‡ไปค๏ผš

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method DELETE `
-Headers $headers `
-Uri "https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/fhirStores/FHIR_STORE_ID/fhir/RESOURCE_TYPE/RESOURCE_ID/$purge" | Select-Object -Expand Content

ๆ‚จๆ‡‰่ฉฒๆœƒๆ”ถๅˆฐๅŸท่กŒๆˆๅŠŸ็š„็‹€ๆ…‹็ขผ (2xx) ๅ’Œ็ฉบ็™ฝๅ›žๆ‡‰ใ€‚

Go

import (
	"context"
	"fmt"
	"io"

	healthcare "google.golang.org/api/healthcare/v1"
)

// purgeFHIRResource purges an FHIR resources.
func purgeFHIRResource(w io.Writer, projectID, location, datasetID, fhirStoreID, resourceType, fhirResourceID string) error {
	ctx := context.Background()

	healthcareService, err := healthcare.NewService(ctx)
	if err != nil {
		return fmt.Errorf("healthcare.NewService: %w", err)
	}

	fhirService := healthcareService.Projects.Locations.Datasets.FhirStores.Fhir

	name := fmt.Sprintf("projects/%s/locations/%s/datasets/%s/fhirStores/%s/fhir/%s/%s", projectID, location, datasetID, fhirStoreID, resourceType, fhirResourceID)

	if _, err := fhirService.ResourcePurge(name).Do(); err != nil {
		return fmt.Errorf("ResourcePurge: %w", err)
	}

	fmt.Fprintf(w, "Resource Purged: %q", name)

	return nil
}

Java

import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.gson.GsonFactory;
import com.google.api.services.healthcare.v1.CloudHealthcare;
import com.google.api.services.healthcare.v1.CloudHealthcareScopes;
import com.google.auth.http.HttpCredentialsAdapter;
import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.Collections;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.client.methods.RequestBuilder;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.impl.client.HttpClients;

public class FhirResourceDeletePurge {
  private static final String FHIR_NAME =
      "projects/%s/locations/%s/datasets/%s/fhirStores/%s/fhir/%s/%s";
  private static final JsonFactory JSON_FACTORY = new GsonFactory();
  private static final NetHttpTransport HTTP_TRANSPORT = new NetHttpTransport();

  public static void fhirResourceDeletePurge(String resourceName)
      throws IOException, URISyntaxException {
    // String resourceName =
    //    String.format(
    //        FHIR_NAME, "project-id", "region-id", "dataset-id", "store-id", "resource-type",
    // "resource-id");

    // Initialize the client, which will be used to interact with the service.
    CloudHealthcare client = createClient();

    HttpClient httpClient = HttpClients.createDefault();
    String uri = String.format("%sv1/%s/$purge", client.getRootUrl(), resourceName);
    URIBuilder uriBuilder = new URIBuilder(uri).setParameter("access_token", getAccessToken());

    HttpUriRequest request =
        RequestBuilder.delete()
            .setUri(uriBuilder.build())
            .addHeader("Content-Type", "application/fhir+json")
            .addHeader("Accept-Charset", "utf-8")
            .addHeader("Accept", "application/fhir+json; charset=utf-8")
            .build();

    // Execute the request and process the results.
    HttpResponse response = httpClient.execute(request);
    HttpEntity responseEntity = response.getEntity();
    if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
      String errorMessage =
          String.format(
              "Exception purging FHIR resource: %s\n", response.getStatusLine().toString());
      System.err.print(errorMessage);
      responseEntity.writeTo(System.err);
      throw new RuntimeException(errorMessage);
    }
    System.out.println("FHIR resource history purged (excluding current version).");
    responseEntity.writeTo(System.out);
  }

  private static CloudHealthcare createClient() throws IOException {
    // Use Application Default Credentials (ADC) to authenticate the requests
    // For more information see https://cloud.google.com/docs/authentication/production
    GoogleCredentials credential =
        GoogleCredentials.getApplicationDefault()
            .createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));

    // Create a HttpRequestInitializer, which will provide a baseline configuration to all requests.
    HttpRequestInitializer requestInitializer =
        request -> {
          new HttpCredentialsAdapter(credential).initialize(request);
          request.setConnectTimeout(60000); // 1 minute connect timeout
          request.setReadTimeout(60000); // 1 minute read timeout
        };

    // Build the client for interacting with the service.
    return new CloudHealthcare.Builder(HTTP_TRANSPORT, JSON_FACTORY, requestInitializer)
        .setApplicationName("your-application-name")
        .build();
  }

  private static String getAccessToken() throws IOException {
    GoogleCredentials credential =
        GoogleCredentials.getApplicationDefault()
            .createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));

    return credential.refreshAccessToken().getTokenValue();
  }
}

Node.js

const google = require('@googleapis/healthcare');
const healthcare = google.healthcare({
  version: 'v1',
  auth: new google.auth.GoogleAuth({
    scopes: ['https://www.googleapis.com/auth/cloud-platform'],
  }),
});

const deleteFhirResourcePurge = async () => {
  // TODO(developer): uncomment these lines before running the sample
  // const cloudRegion = 'us-central1';
  // const projectId = 'adjective-noun-123';
  // const datasetId = 'my-dataset';
  // const fhirStoreId = 'my-fhir-store';
  // const resourceType = 'Patient';
  // const resourceId = '9a664e07-79a4-4c2e-04ed-e996c75484e1';
  const name = `projects/${projectId}/locations/${cloudRegion}/datasets/${datasetId}/fhirStores/${fhirStoreId}/fhir/${resourceType}/${resourceId}`;
  const request = {name};

  await healthcare.projects.locations.datasets.fhirStores.fhir.ResourcePurge(
    request
  );
  console.log('Deleted all historical versions of resource');
};

deleteFhirResourcePurge();

Python

def delete_resource_purge(
    project_id: str,
    location: str,
    dataset_id: str,
    fhir_store_id: str,
    resource_type: str,
    resource_id: str,
) -> dict:
    """Deletes all versions of a FHIR resource (excluding the current version).

    See
    https://github.com/GoogleCloudPlatform/python-docs-samples/tree/main/healthcare/api-client/v1/fhir
    before running the sample.
    See
    https://googleapis.github.io/google-api-python-client/docs/dyn/healthcare_v1.projects.locations.datasets.fhirStores.fhir.html#Resource_purge
    for the Python API reference.

    Args:
      project_id: The project ID or project number of the Cloud project you want
        to use.
      location: The name of the parent dataset's location.
      dataset_id: The name of the parent dataset.
      fhir_store_id: The name of the FHIR store.
      resource_type: The type of the FHIR resource.
      resource_id: The "logical id" of the resource. The ID is assigned by the
        server.

    Returns:
      An empty dict.
    """
    # Imports the Google API Discovery Service.
    from googleapiclient import discovery

    api_version = "v1"
    service_name = "healthcare"

    # Returns an authorized API client by discovering the Healthcare API
    # and using GOOGLE_APPLICATION_CREDENTIALS environment variable.
    client = discovery.build(service_name, api_version)

    # TODO(developer): Uncomment these lines and replace with your values.
    # project_id = 'my-project'
    # location = 'us-central1'
    # dataset_id = 'my-dataset'
    # fhir_store_id = 'my-fhir-store'
    # resource_type = 'Patient'
    # resource_id = 'b682d-0e-4843-a4a9-78c9ac64'
    fhir_store_parent = (
        f"projects/{project_id}/locations/{location}/datasets/{dataset_id}"
    )
    fhir_resource_path = f"{fhir_store_parent}/fhirStores/{fhir_store_id}/fhir/{resource_type}/{resource_id}"

    request = (
        client.projects()
        .locations()
        .datasets()
        .fhirStores()
        .fhir()
        .Resource_purge(name=fhir_resource_path)
    )
    response = request.execute()
    print(
        f"Deleted all versions of {resource_type} resource with ID"
        f" {resource_id} (excluding current version)."
    )
    return response