Patchen Sie eine Nachricht in einem HL7v2-Speicher.
Dokumentationsseiten mit diesem Codebeispiel
Das Codebeispiel im Kontext finden Sie in der folgenden Dokumentation:
Codebeispiel
Go
import (
"context"
"encoding/base64"
"fmt"
"io"
"io/ioutil"
healthcare "google.golang.org/api/healthcare/v1"
)
// patchHL7V2Message patches an HL7V2 message.
func patchHL7V2Message(w io.Writer, projectID, location, datasetID, hl7V2StoreID, hl7V2MessageID, messageFile string) error {
ctx := context.Background()
hl7v2message, err := ioutil.ReadFile(messageFile)
if err != nil {
return fmt.Errorf("ReadFile: %v", err)
}
healthcareService, err := healthcare.NewService(ctx)
if err != nil {
return fmt.Errorf("healthcare.NewService: %v", err)
}
messagesService := healthcareService.Projects.Locations.Datasets.Hl7V2Stores.Messages
name := fmt.Sprintf("projects/%s/locations/%s/datasets/%s/hl7V2Stores/%s/messages/%s", projectID, location, datasetID, hl7V2StoreID, hl7V2MessageID)
message := &healthcare.Message{
Data: base64.StdEncoding.EncodeToString(hl7v2message),
Labels: map[string]string{"my-label": "true"},
}
call := messagesService.Patch(name, message)
call.UpdateMask("labels")
resp, err := call.Do()
if err != nil {
return fmt.Errorf("Patch: %v", err)
}
fmt.Fprintf(w, "Patched HL7V2 message: %q\n", resp.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.jackson2.JacksonFactory;
import com.google.api.services.healthcare.v1.CloudHealthcare;
import com.google.api.services.healthcare.v1.CloudHealthcare.Projects.Locations.Datasets.Hl7V2Stores.Messages;
import com.google.api.services.healthcare.v1.CloudHealthcareScopes;
import com.google.api.services.healthcare.v1.model.Message;
import com.google.auth.http.HttpCredentialsAdapter;
import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@SuppressWarnings("checkstyle:AbbreviationAsWordInName")
public class HL7v2MessagePatch {
private static final String MESSAGE_NAME =
"projects/%s/locations/%s/datasets/%s/hl7V2Stores/%s/messages/%s";
private static final JsonFactory JSON_FACTORY = new JacksonFactory();
private static final NetHttpTransport HTTP_TRANSPORT = new NetHttpTransport();
public static void hl7v2MessagePatch(String hl7v2MessageName) throws IOException {
// String hl7v2MessageName =
// String.format(
// MESSAGE_NAME, "project-id", "region-id", "dataset-id", "hl7v2-id", "message-id");
// Initialize the client, which will be used to interact with the service.
CloudHealthcare client = createClient();
// Fetch the initial state of the message.
Messages.Get getRequest =
client.projects().locations().datasets().hl7V2Stores().messages().get(hl7v2MessageName);
Message message = getRequest.execute();
// Update the Message fields as needed as needed. For a full list of Message fields, see:
// https://cloud.google.com/healthcare/docs/reference/rest/v1/projects.locations.datasets.hl7V2Stores.messages
Map<String, String> labels = new HashMap<>();
labels.put("key1", "value1");
labels.put("key2", "value2");
message.setLabels(labels);
// Create request and configure any parameters.
Messages.Patch request =
client
.projects()
.locations()
.datasets()
.hl7V2Stores()
.messages()
.patch(hl7v2MessageName, message)
.setUpdateMask("labels");
// Execute the request and process the results.
message = request.execute();
System.out.println("HL7v2 message patched: \n" + message.toPrettyString());
}
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();
}
}
Node.js
const {google} = require('googleapis');
const healthcare = google.healthcare('v1');
const patchHl7v2Message = 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 hl7v2StoreId = 'my-hl7v2-store';
// const hl7v2MessageId = 'qCnewKno44gTt3oBn4dQ0u8ZA23ibDdV9GpifD2E=';
// const labelKey = 'status';
// const labelValue = 'processed';
const name = `projects/${projectId}/locations/${cloudRegion}/datasets/${datasetId}/hl7V2Stores/${hl7v2StoreId}/messages/${hl7v2MessageId}`;
const request = {
name,
updateMask: 'labels',
resource: {
labels: {
labelKey: labelValue,
},
},
};
await healthcare.projects.locations.datasets.hl7V2Stores.messages.patch(
request
);
console.log('Patched HL7v2 message');
};
patchHl7v2Message();
Python
def patch_hl7v2_message(
project_id,
cloud_region,
dataset_id,
hl7v2_store_id,
hl7v2_message_id,
label_key,
label_value,
):
"""Updates the message."""
client = get_client()
hl7v2_message_parent = "projects/{}/locations/{}".format(
project_id, cloud_region
)
hl7v2_message_name = "{}/datasets/{}/hl7V2Stores/{}/messages/{}".format(
hl7v2_message_parent, dataset_id, hl7v2_store_id, hl7v2_message_id
)
patch = {"labels": {label_key: label_value}}
request = (
client.projects()
.locations()
.datasets()
.hl7V2Stores()
.messages()
.patch(name=hl7v2_message_name, updateMask="labels", body=patch)
)
response = request.execute()
print(
"Patched HL7v2 message {} with labels:\n\t{}: {}".format(
hl7v2_message_id, label_key, label_value
)
)
return response
Nächste Schritte
Informationen zum Suchen und Filtern von Codebeispielen für andere Google Cloud-Produkte finden Sie im Google Cloud-Beispielbrowser