Search in sources :

Example 1 with Messages

use of com.google.api.services.healthcare.v1.CloudHealthcare.Projects.Locations.Datasets.Hl7V2Stores.Messages in project java-docs-samples by GoogleCloudPlatform.

the class HL7v2MessageIngest method hl7v2MessageIngest.

public static void hl7v2MessageIngest(String hl7v2StoreName, String filePath) throws IOException {
    // String hl7v2StoreName =
    // String.format(
    // HL7v2_NAME, "your-project-id", "your-region-id", "your-dataset-id", "your-hl7v2-id");
    // Initialize the client, which will be used to interact with the service.
    CloudHealthcare client = createClient();
    // Load the data from file and format it into an ingest request.
    List<String> lines = Files.readAllLines(Paths.get(filePath), Charset.defaultCharset());
    String data = String.join("\n", lines);
    Message message = new Message().setData(data);
    IngestMessageRequest ingestRequest = new IngestMessageRequest().setMessage(message);
    // Create request and configure any parameters.
    Messages.Ingest request = client.projects().locations().datasets().hl7V2Stores().messages().ingest(hl7v2StoreName, ingestRequest);
    // Execute the request and process the results.
    IngestMessageResponse response = request.execute();
    System.out.println("HL7v2 message ingested: " + response.toPrettyString());
}
Also used : Messages(com.google.api.services.healthcare.v1.CloudHealthcare.Projects.Locations.Datasets.Hl7V2Stores.Messages) Message(com.google.api.services.healthcare.v1.model.Message) CloudHealthcare(com.google.api.services.healthcare.v1.CloudHealthcare) IngestMessageRequest(com.google.api.services.healthcare.v1.model.IngestMessageRequest) IngestMessageResponse(com.google.api.services.healthcare.v1.model.IngestMessageResponse)

Example 2 with Messages

use of com.google.api.services.healthcare.v1.CloudHealthcare.Projects.Locations.Datasets.Hl7V2Stores.Messages in project java-docs-samples by GoogleCloudPlatform.

the class HL7v2MessagePatch method hl7v2MessagePatch.

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());
}
Also used : Messages(com.google.api.services.healthcare.v1.CloudHealthcare.Projects.Locations.Datasets.Hl7V2Stores.Messages) Message(com.google.api.services.healthcare.v1.model.Message) HashMap(java.util.HashMap) CloudHealthcare(com.google.api.services.healthcare.v1.CloudHealthcare)

Example 3 with Messages

use of com.google.api.services.healthcare.v1.CloudHealthcare.Projects.Locations.Datasets.Hl7V2Stores.Messages in project java-docs-samples by GoogleCloudPlatform.

the class HL7v2MessageCreate method hl7v2MessageCreate.

public static void hl7v2MessageCreate(String hl7v2StoreName, String messageId, String filePath) throws IOException {
    // String hl7v2StoreName =
    // String.format(
    // HL7v2_NAME, "your-project-id", "your-region-id", "your-dataset-id", "your-hl7v2-id");
    // String messageId = "your-message-id";
    // String filePath = "path/to/file.txt";
    // Initialize the client, which will be used to interact with the service.
    CloudHealthcare client = createClient();
    // Load the data from file representing the message.
    List<String> lines = Files.readAllLines(Paths.get(filePath), Charset.defaultCharset());
    String data = String.join("\n", lines);
    Message message = new Message().setData(data).setName(messageId);
    CreateMessageRequest createRequest = new CreateMessageRequest().setMessage(message);
    // Create request and configure any parameters.
    Messages.Create request = client.projects().locations().datasets().hl7V2Stores().messages().create(hl7v2StoreName, createRequest);
    // Execute the request and process the results.
    Message response = request.execute();
    System.out.println("HL7v2 message created: " + response.toPrettyString());
}
Also used : Messages(com.google.api.services.healthcare.v1.CloudHealthcare.Projects.Locations.Datasets.Hl7V2Stores.Messages) Message(com.google.api.services.healthcare.v1.model.Message) CloudHealthcare(com.google.api.services.healthcare.v1.CloudHealthcare) CreateMessageRequest(com.google.api.services.healthcare.v1.model.CreateMessageRequest)

Example 4 with Messages

use of com.google.api.services.healthcare.v1.CloudHealthcare.Projects.Locations.Datasets.Hl7V2Stores.Messages in project beam by apache.

the class HttpHealthcareApiClient method getEarliestHL7v2SendTime.

@Override
public Instant getEarliestHL7v2SendTime(String hl7v2Store, @Nullable String filter) throws IOException {
    ListMessagesResponse response = client.projects().locations().datasets().hl7V2Stores().messages().list(hl7v2Store).setFilter(filter).set("view", // needed to retrieve the value for sendtime
    "full").setOrderBy(// default order is ascending
    "sendTime").setPageSize(// Only interested in the earliest sendTime
    1).execute();
    if (response.isEmpty()) {
        throw new IllegalArgumentException(String.format("Could not find earliest send time. The filter %s  matched no results on " + "HL7v2 Store: %s", filter, hl7v2Store));
    }
    String sendTime = response.getHl7V2Messages().get(0).getSendTime();
    if (Strings.isNullOrEmpty(sendTime)) {
        LOG.warn(String.format("Earliest message in %s has null or empty sendTime defaulting to Epoch.", hl7v2Store));
        return Instant.ofEpochMilli(0);
    }
    // https://cloud.google.com/healthcare/docs/reference/rest/v1/projects.locations.datasets.hl7V2Stores.messages#Message
    return Instant.parse(sendTime);
}
Also used : ListMessagesResponse(com.google.api.services.healthcare.v1.model.ListMessagesResponse)

Example 5 with Messages

use of com.google.api.services.healthcare.v1.CloudHealthcare.Projects.Locations.Datasets.Hl7V2Stores.Messages in project beam by apache.

the class HttpHealthcareApiClient method getLatestHL7v2SendTime.

@Override
public Instant getLatestHL7v2SendTime(String hl7v2Store, @Nullable String filter) throws IOException {
    ListMessagesResponse response = client.projects().locations().datasets().hl7V2Stores().messages().list(hl7v2Store).setFilter(filter).set("view", // needed to retrieve the value for sendTime
    "full").setOrderBy("sendTime desc").setPageSize(// Only interested in the earliest sendTime
    1).execute();
    if (response.isEmpty()) {
        throw new IllegalArgumentException(String.format("Could not find latest send time. The filter %s  matched no results on " + "HL7v2 Store: %s", filter, hl7v2Store));
    }
    String sendTime = response.getHl7V2Messages().get(0).getSendTime();
    if (Strings.isNullOrEmpty(sendTime)) {
        LOG.warn(String.format("Latest message in %s has null or empty sendTime defaulting to now.", hl7v2Store));
        return Instant.now();
    }
    // https://cloud.google.com/healthcare/docs/reference/rest/v1/projects.locations.datasets.hl7V2Stores.messages#Message
    return Instant.parse(sendTime);
}
Also used : ListMessagesResponse(com.google.api.services.healthcare.v1.model.ListMessagesResponse)

Aggregations

Message (com.google.api.services.healthcare.v1.model.Message)7 CloudHealthcare (com.google.api.services.healthcare.v1.CloudHealthcare)6 Messages (com.google.api.services.healthcare.v1.CloudHealthcare.Projects.Locations.Datasets.Hl7V2Stores.Messages)5 ListMessagesResponse (com.google.api.services.healthcare.v1.model.ListMessagesResponse)4 CreateMessageRequest (com.google.api.services.healthcare.v1.model.CreateMessageRequest)2 IngestMessageRequest (com.google.api.services.healthcare.v1.model.IngestMessageRequest)2 Test (org.junit.Test)2 IngestMessageResponse (com.google.api.services.healthcare.v1.model.IngestMessageResponse)1 HashMap (java.util.HashMap)1 List (java.util.List)1 HL7v2MessagePages (org.apache.beam.sdk.io.gcp.healthcare.HttpHealthcareApiClient.HL7v2MessagePages)1