FHIR 리소스를 삭제합니다.
이 코드 샘플이 포함된 문서 페이지
컨텍스트에서 사용된 코드 샘플을 보려면 다음 문서를 참조하세요.
코드 샘플
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: %v", 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: %v", err)
}
fmt.Fprintf(w, "Deleted %q", name)
return nil
}
자바
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.jackson2.JacksonFactory;
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 JacksonFactory();
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');
const healthcare = google.healthcare('v1');
const deleteFhirResource = async () => {
const auth = await google.auth.getClient({
scopes: ['https://www.googleapis.com/auth/cloud-platform'],
});
google.options({auth});
// 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(
service_account_json,
base_url,
project_id,
cloud_region,
dataset_id,
fhir_store_id,
resource_type,
resource_id,
):
"""
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.
"""
url = "{}/projects/{}/locations/{}".format(base_url, project_id, cloud_region)
resource_path = "{}/datasets/{}/fhirStores/{}/fhir/{}/{}".format(
url, dataset_id, fhir_store_id, resource_type, resource_id
)
# Make an authenticated API request
session = get_session(service_account_json)
response = session.delete(resource_path)
print("Deleted {} resource with ID {}.".format(resource_type, resource_id))
return response