Search in sources :

Example 16 with Hl7V2Stores

use of com.google.api.services.healthcare.v1.CloudHealthcare.Projects.Locations.Datasets.Hl7V2Stores 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 17 with Hl7V2Stores

use of com.google.api.services.healthcare.v1.CloudHealthcare.Projects.Locations.Datasets.Hl7V2Stores 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)

Example 18 with Hl7V2Stores

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

the class HL7v2IOTest method test_HL7v2IO_failedWrites.

@Test
public void test_HL7v2IO_failedWrites() {
    Message msg = new Message().setData("");
    List<HL7v2Message> emptyMessages = Collections.singletonList(HL7v2Message.fromModel(msg));
    PCollection<HL7v2Message> messages = pipeline.apply(Create.of(emptyMessages).withCoder(new HL7v2MessageCoder()));
    HL7v2IO.Write.Result writeResult = messages.apply(HL7v2IO.ingestMessages("projects/foo/locations/us-central1/datasets/bar/hl7V2Stores/baz"));
    PCollection<HealthcareIOError<HL7v2Message>> failedInserts = writeResult.getFailedInsertsWithErr();
    PCollection<Long> failedMsgs = failedInserts.apply(Count.globally());
    PAssert.thatSingleton(failedMsgs).isEqualTo(1L);
    pipeline.run();
}
Also used : Message(com.google.api.services.healthcare.v1.model.Message) Test(org.junit.Test)

Aggregations

CloudHealthcare (com.google.api.services.healthcare.v1.CloudHealthcare)13 Hl7V2Stores (com.google.api.services.healthcare.v1.CloudHealthcare.Projects.Locations.Datasets.Hl7V2Stores)7 Message (com.google.api.services.healthcare.v1.model.Message)6 Messages (com.google.api.services.healthcare.v1.CloudHealthcare.Projects.Locations.Datasets.Hl7V2Stores.Messages)5 Hl7V2Store (com.google.api.services.healthcare.v1.model.Hl7V2Store)4 ListMessagesResponse (com.google.api.services.healthcare.v1.model.ListMessagesResponse)3 CreateMessageRequest (com.google.api.services.healthcare.v1.model.CreateMessageRequest)2 IngestMessageRequest (com.google.api.services.healthcare.v1.model.IngestMessageRequest)2 Policy (com.google.api.services.healthcare.v1.model.Policy)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Binding (com.google.api.services.healthcare.v1.model.Binding)1 Hl7V2NotificationConfig (com.google.api.services.healthcare.v1.model.Hl7V2NotificationConfig)1 IngestMessageResponse (com.google.api.services.healthcare.v1.model.IngestMessageResponse)1 ListHl7V2StoresResponse (com.google.api.services.healthcare.v1.model.ListHl7V2StoresResponse)1 SetIamPolicyRequest (com.google.api.services.healthcare.v1.model.SetIamPolicyRequest)1 Test (org.junit.Test)1