Example #1
0
 /*
  * Recursive descent into subclusters.
  */
 private static void flatten(ArrayList<Cluster> flattened, Collection<Cluster> clusters) {
   for (Cluster c : clusters) {
     flattened.add(c);
     final List<Cluster> subclusters = c.getSubclusters();
     if (!subclusters.isEmpty()) {
       flatten(flattened, subclusters);
     }
   }
 }
  public static List<PatientSearchResult> getDynamicSearch(
      List<DynamicSearchCriteria> criteria, String stateRelation, String userToken) {
    // Use a form because there are an unknown number of values
    MultivaluedMap form = new MultivaluedMapImpl();
    // stateRelation is how the criteria are logically related "AND", "OR"
    form.add("stateRelation", stateRelation);
    int i = 0;
    // Step through all criteria given, the form fields are appended with an integer
    // to maintain grouping in REST call (dataGroup0, dataGroup1...)
    for (DynamicSearchCriteria dcriteria : criteria) {
      form.add("sourceName" + i, dcriteria.getDataGroup());
      form.add("itemName" + i, dcriteria.getField());
      form.add("operator" + i, dcriteria.getOperator().getValue());
      form.add("value" + i, dcriteria.getValue());
      i++;
    }

    ClientConfig cc = new DefaultClientConfig();
    cc.getClasses().add(JacksonJsonProvider.class);
    Client client = Client.create();
    WebResource resource =
        client.resource(APIURLHolder.getUrl() + "/nbia-api/services/getDynamicSearch");
    ClientResponse response =
        resource
            .accept(MediaType.APPLICATION_JSON)
            .type(MediaType.APPLICATION_FORM_URLENCODED)
            .header("Authorization", "Bearer " + userToken)
            .post(ClientResponse.class, form);
    // check response status code
    if (response.getStatus() != 200) {
      throw new RuntimeException("Failed : HTTP error code : " + response.getStatus());
    }

    // display response
    String output = response.getEntity(String.class);
    List<PatientSearchResultImpl> myObjects;
    try {
      //	Object json = mapper.readValue(output, Object.class);
      //   String indented = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(json);
      //   logger.info("Returned JSON\n"+indented);
      myObjects = mapper.readValue(output, new TypeReference<List<PatientSearchResultImpl>>() {});
    } catch (Exception e) {
      e.printStackTrace();
      return null;
    }
    List<PatientSearchResult> returnValue = new ArrayList<PatientSearchResult>();
    for (PatientSearchResultImpl result : myObjects) {
      returnValue.add(result);
    }
    return returnValue;
  }
Example #3
0
 /**
  * If there are unclustered documents, appends the "Other Topics" group to the <code>clusters
  * </code>.
  *
  * @see #buildOtherTopics(List, List, String)
  */
 public static void appendOtherTopics(
     List<Document> allDocuments, List<Cluster> clusters, String label) {
   final Cluster otherTopics = buildOtherTopics(allDocuments, clusters, label);
   if (!otherTopics.getDocuments().isEmpty()) {
     clusters.add(otherTopics);
   }
 }
  public static List<PatientSearchResult> getTextSearch(String textValue, String userToken) {

    Form form = new Form();
    form.add("textValue", textValue);

    ClientConfig cc = new DefaultClientConfig();
    cc.getClasses().add(JacksonJsonProvider.class);
    Client client = Client.create();
    WebResource resource =
        client.resource(APIURLHolder.getUrl() + "/nbia-api/services/getTextSearch");
    ClientResponse response =
        resource
            .accept(MediaType.APPLICATION_JSON)
            .type(MediaType.APPLICATION_FORM_URLENCODED)
            .header("Authorization", "Bearer " + userToken)
            .post(ClientResponse.class, form);
    // check response status code
    if (response.getStatus() != 200) {
      throw new RuntimeException("Failed : HTTP error code : " + response.getStatus());
    }

    // display response
    String output = response.getEntity(String.class);
    List<PatientTextSearchResult> myObjects;
    try {
      // Object json = mapper.readValue(output, Object.class);
      //  String indented = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(json);
      // logger.info("Returned JSON\n"+indented);
      myObjects =
          mapper.readValue(output, new TypeReference<List<PatientTextSearchResultImpl>>() {});
    } catch (Exception e) {
      e.printStackTrace();
      return null;
    }
    List<PatientSearchResult> returnValue = new ArrayList<PatientSearchResult>();
    for (PatientTextSearchResult result : myObjects) {
      returnValue.add(result);
    }
    return returnValue;
  }
  public static DefaultOAuth2AccessToken getToken(String userName, String password) {

    Form form = new Form();
    form.add("username", userName);
    form.add("password", password);
    form.add("client_id", "nbiaRestAPIClient");
    form.add("client_secret", "ItsBetweenUAndMe");
    form.add("grant_type", "password");

    ClientConfig cc = new DefaultClientConfig();
    cc.getClasses().add(JacksonJsonProvider.class);
    Client client = Client.create();
    WebResource resource = client.resource(APIURLHolder.getUrl() + "/nbia-api/oauth/token");
    ClientResponse response =
        resource
            .accept(MediaType.APPLICATION_JSON)
            .type(MediaType.APPLICATION_FORM_URLENCODED)
            .post(ClientResponse.class, form);
    // check response status code
    if (response.getStatus() != 200) {
      throw new RuntimeException("Failed : HTTP error code : " + response.getStatus());
    }

    // display response
    String output = response.getEntity(String.class);
    output = "[" + output + "]";
    List<DefaultOAuth2AccessToken> myObjects;
    try {
      myObjects = mapper.readValue(output, new TypeReference<List<DefaultOAuth2AccessToken>>() {});
    } catch (Exception e) {
      e.printStackTrace();
      return null;
    }

    return myObjects.get(0);
  }
  public static String getJNLP(
      List<BasketSeriesItemBean> seriesItems,
      String password,
      boolean annotation,
      String userToken) {
    // Use a form because there are an unknown number of values
    MultivaluedMap form = new MultivaluedMapImpl();
    if ((seriesItems == null) || (seriesItems.size() == 0)) {
      return "";
    }
    // Step through all data in series items for display in download manager
    for (BasketSeriesItemBean item : seriesItems) {
      form.add("list", item.getSeriesId());
    }
    form.add("password", password);
    String annotationString = "false";
    if (annotation) {
      annotationString = "true";
    }
    form.add("includeAnnotation", annotationString);
    ClientConfig cc = new DefaultClientConfig();
    cc.getClasses().add(JacksonJsonProvider.class);
    Client client = Client.create();
    WebResource resource =
        client.resource(APIURLHolder.getUrl() + "/nbia-api/services/getJNLPText");
    ClientResponse response =
        resource
            .accept(MediaType.TEXT_PLAIN)
            .type(MediaType.APPLICATION_FORM_URLENCODED)
            .header("Authorization", "Bearer " + userToken)
            .post(ClientResponse.class, form);
    // check response status code
    if (response.getStatus() != 200) {
      throw new RuntimeException("Failed : HTTP error code : " + response.getStatus());
    }

    // display response
    String output = response.getEntity(String.class);
    return output;
  }
  public static void getSimpleSearch(List<Criteria> criteria, String userToken) {
    // Use a form because there are an unknown number of values
    MultivaluedMap form = new MultivaluedMapImpl();

    int i = 0;
    // Step through all criteria given, the form fields are appended with an integer
    // to maintain grouping in REST call (dataGroup0, dataGroup1...)
    for (Criteria scriteria : criteria) {
      if (scriteria instanceof CollectionCriteria) {
        CollectionCriteria cri = (CollectionCriteria) scriteria;
        for (String collection : ((CollectionCriteria) scriteria).getCollectionObjects()) {
          form.add("criteriaType" + i, "CollectionCriteria");
          form.add("value" + i, collection);
        }
      }
      if (scriteria instanceof ImageModalityCriteria) {
        ImageModalityCriteria cri = (ImageModalityCriteria) scriteria;
        for (String value : ((ImageModalityCriteria) scriteria).getImageModalityObjects()) {
          form.add("criteriaType" + i, "ImageModalityCriteria");
          form.add("value" + i, value);
        }
      }
      if (scriteria instanceof AnatomicalSiteCriteria) {
        AnatomicalSiteCriteria cri = (AnatomicalSiteCriteria) scriteria;
        for (String value : ((AnatomicalSiteCriteria) scriteria).getAnatomicalSiteValueObjects()) {
          form.add("criteriaType" + i, "AnatomicalSiteCriteria");
          form.add("value" + i, value);
        }
      }
      if (scriteria instanceof ManufacturerCriteria) {
        ManufacturerCriteria cri = (ManufacturerCriteria) scriteria;
        for (String value : ((ManufacturerCriteria) scriteria).getManufacturerObjects()) {
          form.add("criteriaType" + i, "ManufacturerCriteria");
          form.add("value" + i, value);
        }
      }
      if (scriteria instanceof DateRangeCriteria) {
        DateRangeCriteria cri = (DateRangeCriteria) scriteria;
        form.add("criteriaType" + i, "DateRangeCriteria");
        SimpleDateFormat formatter = new SimpleDateFormat("dd/mm/yyyy");
        form.add("fromDate" + i, formatter.format(cri.getFromDate()));
        form.add("toDate" + i, formatter.format(cri.getToDate()));
      }
      if (scriteria instanceof PatientCriteria) {
        PatientCriteria cri = (PatientCriteria) scriteria;
        for (String value : ((PatientCriteria) scriteria).getPatientIdObjects()) {
          form.add("criteriaType" + i, "PatientCriteria");
          form.add("value" + i, value);
        }
      }
      if (scriteria instanceof MinNumberOfStudiesCriteria) {
        MinNumberOfStudiesCriteria cri = (MinNumberOfStudiesCriteria) scriteria;
        form.add("criteriaType" + i, "MinNumberOfStudiesCriteria");
        form.add("value" + i, cri.getMinNumberOfStudiesValue().toString());
      }
      i++;
    }

    ClientConfig cc = new DefaultClientConfig();
    cc.getClasses().add(JacksonJsonProvider.class);
    Client client = Client.create();
    WebResource resource =
        client.resource(APIURLHolder.getUrl() + "/nbia-api/services/getSimpleSearch");
    ClientResponse response =
        resource
            .accept(MediaType.APPLICATION_JSON)
            .type(MediaType.APPLICATION_FORM_URLENCODED)
            .header("Authorization", "Bearer " + userToken)
            .post(ClientResponse.class, form);
    // check response status code
    if (response.getStatus() != 200) {
      throw new RuntimeException("Failed : HTTP error code : " + response.getStatus());
    }

    // display response
    String output = response.getEntity(String.class);
    List<PatientSearchResultImpl> myObjects;
    try {
      //    Object json = mapper.readValue(output, Object.class);
      //   String indented = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(json);
      //   logger.info("Returned JSON\n"+indented);
      myObjects = mapper.readValue(output, new TypeReference<List<PatientSearchResultImpl>>() {});
    } catch (Exception e) {
      e.printStackTrace();
      return;
    }
    List<PatientSearchResult> returnValue = new ArrayList<PatientSearchResult>();
    for (PatientSearchResultImpl result : myObjects) {
      returnValue.add(result);
    }
    return;
  }
Example #8
0
 /** For JSON serialization only. */
 @JsonProperty("clusters")
 @SuppressWarnings("unused")
 private List<Cluster> getSubclustersForSerialization() {
   return subclustersView.isEmpty() ? null : subclustersView;
 }