Search in sources :

Example 1 with ListMessagesResponse

use of com.google.api.services.healthcare.v1.model.ListMessagesResponse in project beam by apache.

the class HL7V2MessagePagesTest method test_EmptyStoreEmptyIterator.

/**
 * Test empty store.
 */
@Test
public void test_EmptyStoreEmptyIterator() throws IOException {
    Mockito.doReturn(new ListMessagesResponse()).when(client).makeSendTimeBoundHL7v2ListRequest("foo", null, null, null, null, null);
    HL7v2MessagePages emptyPages = new HL7v2MessagePages(client, "foo", null, null);
    // In the case that the store is empty we should return a single empty list.
    assertFalse(emptyPages.iterator().hasNext());
}
Also used : ListMessagesResponse(com.google.api.services.healthcare.v1.model.ListMessagesResponse) HL7v2MessagePages(org.apache.beam.sdk.io.gcp.healthcare.HttpHealthcareApiClient.HL7v2MessagePages) Test(org.junit.Test)

Example 2 with ListMessagesResponse

use of com.google.api.services.healthcare.v1.model.ListMessagesResponse 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 3 with ListMessagesResponse

use of com.google.api.services.healthcare.v1.model.ListMessagesResponse 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 4 with ListMessagesResponse

use of com.google.api.services.healthcare.v1.model.ListMessagesResponse in project beam by apache.

the class HL7V2MessagePagesTest method test_NonEmptyExpectedIterator.

/**
 * Test Non-empty with beta store list response store. This tests backwards compatibility with
 * Stores that return the deprecated messages field in list requests.
 */
@Test
public void test_NonEmptyExpectedIterator() throws IOException {
    ListMessagesResponse page0 = new ListMessagesResponse().setHl7V2Messages(Stream.of("foo0", "foo1", "foo2").map(HL7v2IOTestUtil::testMessage).collect(Collectors.toList())).setNextPageToken("page1");
    ListMessagesResponse page1 = new ListMessagesResponse().setHl7V2Messages(Stream.of("foo3", "foo4", "foo5").map(HL7v2IOTestUtil::testMessage).collect(Collectors.toList()));
    Mockito.doReturn(page0).when(client).makeSendTimeBoundHL7v2ListRequest("foo", null, null, null, null, null);
    Mockito.doReturn(page1).when(client).makeSendTimeBoundHL7v2ListRequest("foo", null, null, null, null, "page1");
    HL7v2MessagePages pages = new HL7v2MessagePages(client, "foo", null, null);
    assertTrue(pages.iterator().hasNext());
    Iterator<List<HL7v2Message>> pagesIterator = pages.iterator();
    assertEquals(page0.getHl7V2Messages().stream().map(Message::getName).collect(Collectors.toList()), pagesIterator.next().stream().map(HL7v2Message::getName).collect(Collectors.toList()));
    assertEquals(page1.getHl7V2Messages().stream().map(Message::getName).collect(Collectors.toList()), pagesIterator.next().stream().map(HL7v2Message::getName).collect(Collectors.toList()));
    assertFalse(pagesIterator.hasNext());
}
Also used : ListMessagesResponse(com.google.api.services.healthcare.v1.model.ListMessagesResponse) Message(com.google.api.services.healthcare.v1.model.Message) List(java.util.List) HL7v2MessagePages(org.apache.beam.sdk.io.gcp.healthcare.HttpHealthcareApiClient.HL7v2MessagePages) Test(org.junit.Test)

Example 5 with ListMessagesResponse

use of com.google.api.services.healthcare.v1.model.ListMessagesResponse in project java-docs-samples by GoogleCloudPlatform.

the class HL7v2MessageList method hl7v2MessageList.

public static void hl7v2MessageList(String hl7v2StoreName) 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();
    // Results are paginated, so multiple queries may be required.
    String pageToken = null;
    do {
        // Create request and execute.
        ListMessagesResponse messageResponse = client.projects().locations().datasets().hl7V2Stores().messages().list(hl7v2StoreName).setPageSize(100).setPageToken(pageToken).execute();
        if (messageResponse.getHl7V2Messages() != null) {
            // Print results.
            System.out.printf("Retrieved %s HL7v2 messages: \n", messageResponse.getHl7V2Messages().size());
            for (Message message : messageResponse.getHl7V2Messages()) {
                System.out.println(message);
            }
        }
        // Update the page token for the next request.
        pageToken = messageResponse.getNextPageToken();
    } while (pageToken != null);
}
Also used : ListMessagesResponse(com.google.api.services.healthcare.v1.model.ListMessagesResponse) Message(com.google.api.services.healthcare.v1.model.Message) CloudHealthcare(com.google.api.services.healthcare.v1.CloudHealthcare)

Aggregations

ListMessagesResponse (com.google.api.services.healthcare.v1.model.ListMessagesResponse)5 Message (com.google.api.services.healthcare.v1.model.Message)2 HL7v2MessagePages (org.apache.beam.sdk.io.gcp.healthcare.HttpHealthcareApiClient.HL7v2MessagePages)2 Test (org.junit.Test)2 CloudHealthcare (com.google.api.services.healthcare.v1.CloudHealthcare)1 List (java.util.List)1