Skip to content

Commit

Permalink
Merge pull request #498 from achabill/RAD-377
Browse files Browse the repository at this point in the history
RAD-377: Search by report template license
  • Loading branch information
teleivo committed Nov 22, 2016
2 parents bb941ce + b032503 commit f072080
Show file tree
Hide file tree
Showing 10 changed files with 174 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ public List<MrrtReportTemplate> getMrrtReportTemplates(MrrtReportTemplateSearchC
if (searchCriteria.getPublisher() != null) {
crit.add(Restrictions.ilike("dcTermsPublisher", searchCriteria.getPublisher() + "%", MatchMode.ANYWHERE));
}
if (searchCriteria.getLicense() != null) {
crit.add(Restrictions.ilike("dcTermsLicense", searchCriteria.getLicense() + "%", MatchMode.ANYWHERE));
}
final List<MrrtReportTemplate> result = (List<MrrtReportTemplate>) crit.list();
return result == null ? new ArrayList<>() : result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public class MrrtReportTemplateSearchCriteria {

private final String publisher;

private final String license;

/**
* @return the title of the mrrt report template
*/
Expand All @@ -35,13 +37,22 @@ public String getPublisher() {
return publisher;
}

/**
* @return the license of the mrrt report template
*/
public String getLicense() {
return license;
}

public static class Builder {


private String title;

private String publisher;

private String license;

/**
* @param title the title of the mrrt report template
* @return this builder instance
Expand All @@ -62,15 +73,24 @@ public Builder withPublisher(String publisher) {
return this;
}

/**
* @param license the license of the mrrt report template
* @return this builder instance
*/
public Builder withLicense(String license) {
this.license = license;
return this;
}

/**
* Creates an {@code MrrtReportTemplateSearchCriteria} with properties of this builder instance.
*
* @return a new search criteria instance
* @should create an mrrt report template search criteria instance with title if title is set
* @should create an mrrt report template search criteria instance with publisher if publisher is set
* @should create an mrrt report template search criteria instance with license if license is set
*/
public MrrtReportTemplateSearchCriteria build() {

return new MrrtReportTemplateSearchCriteria(this);
}
}
Expand All @@ -79,5 +99,6 @@ private MrrtReportTemplateSearchCriteria(Builder builder) {

this.title = builder.title;
this.publisher = builder.publisher;
this.license = builder.license;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ public interface MrrtReportTemplateService extends OpenmrsService {
* @should throw illegal argument exception if given null
* @should return all mrrt report templates that match given publisher anywhere in dcterms publisher insensitive to case
* @should return an empty list if no match for publisher was found
* @should return all mrrt report templates that match given license anywhere in dcterms license insensitive to case
* @should return an empty list if no match for license was found
*/
@Authorized(RadiologyPrivileges.GET_RADIOLOGY_REPORT_TEMPLATES)
public List<MrrtReportTemplate>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,16 @@ public void build_shouldCreateAnMrrtReportTemplateSearchCriteriaInstanceWithPubl
.build();
assertThat(mrrtReportTemplateSearchCriteria.getPublisher(), is(publisher));
}

/**
* @see MrrtReportTemplateSearchCriteria.Builder#build()
* @verifies create an mrrt report template search criteria instance with license if license is set
*/
@Test
public void build_shouldCreateAnMrrtReportTemplateSearchCriteriaInstanceWithLicenseIfLicenseIsSet() throws Exception {
String license = "Mozilla Public License";
mrrtReportTemplateSearchCriteria = new MrrtReportTemplateSearchCriteria.Builder().withLicense(license)
.build();
assertThat(mrrtReportTemplateSearchCriteria.getLicense(), is(license));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
package org.openmrs.module.radiology.report.template;

import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.hasItem;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
Expand All @@ -23,6 +24,7 @@
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.io.FileUtils;
Expand Down Expand Up @@ -78,6 +80,10 @@ public class MrrtReportTemplateServiceComponentTest extends BaseModuleContextSen

private static final String NON_EXISTING_TEMPLATE_TITLE = "invalid";

private static final String EXISTING_TEMPLATE_LICENSE = "General Public License";

private static final String NON_EXISTING_TEMPLATE_LICENSE = "Non existing license";

private static final String TEMPLATE_IDENTIFIER = "1.3.6.1.4.1.21367.13.199.1015";

private static final String NON_EXISTING_PUBLISHER = "Non existing publisher";
Expand Down Expand Up @@ -481,6 +487,52 @@ public void getMrrtRepdortTemplates_shouldReturnAnEmptyListIfNoMatchForPublisher
assertTrue(templates.isEmpty());
}

/**
* @see MrrtReportTemplateService#getMrrtReportTemplates(MrrtReportTemplateSearchCriteria)
* @verifies return all mrrt report templates that match given license anywhere in dcterms license insensitive to case
*/
@Test
public void
getMrrtReportTemplates_shouldReturnAllMrrtReportTemplatesThatMatchGivenLicenseAnywhereInDctermsLicenseInsensitiveToCase()
throws Exception {
MrrtReportTemplateSearchCriteria searchCriteria =
new MrrtReportTemplateSearchCriteria.Builder().withLicense(EXISTING_TEMPLATE_LICENSE)
.build();
List<MrrtReportTemplate> templates = mrrtReportTemplateService.getMrrtReportTemplates(searchCriteria);

assertNotNull(templates);
assertThat(templates.size(), is(1));
assertThat(templates.get(0)
.getDcTermsLicense(),
is(EXISTING_TEMPLATE_LICENSE));

searchCriteria = new MrrtReportTemplateSearchCriteria.Builder().withLicense("public")
.build();
templates = mrrtReportTemplateService.getMrrtReportTemplates(searchCriteria);
List<String> licenses = new ArrayList<>();
templates.forEach(template -> licenses.add(template.getDcTermsLicense()));

assertNotNull(licenses);
assertThat(licenses.size(), is(2));
assertThat(licenses, hasItem("Mozilla Public License"));
assertThat(licenses, hasItem("General Public License"));
}

/**
* @see MrrtReportTemplateService#getMrrtReportTemplates(MrrtReportTemplateSearchCriteria)
* @verifies return an empty list if no match for license was found
*/
@Test
public void getMrrtReportTemplates_shouldReturnAnEmptyListIfNoMatchForLicenseWasFound() throws Exception {
MrrtReportTemplateSearchCriteria searchCriteria =
new MrrtReportTemplateSearchCriteria.Builder().withLicense(NON_EXISTING_TEMPLATE_LICENSE)
.build();
List<MrrtReportTemplate> templates = mrrtReportTemplateService.getMrrtReportTemplates(searchCriteria);

assertNotNull(templates);
assertTrue(templates.isEmpty());
}

/**
* @see MrrtReportTemplateService#getMrrtReportTemplateHtmlBody(MrrtReportTemplate)
* @verifies return the body content of the mrrt report template file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<dataset>
<concept_reference_source concept_source_id="1" name="RADLEX" description="RadLex Playbook is a project of the Radiological Society of North America (RSNA)" creator="1" date_created="2016-08-01 09:00:00" uuid="f689a577-eb63-4e6b-9941-13c7880f5590"/>
<concept_reference_term concept_reference_term_id="1" concept_source_id="1" version="2.1" creator="1" date_created="2016-08-01 09:00:00" uuid="f689a577-eb63-4e6b-9941-13c7880f5590" code="RID10321" name="RADLEX" description="RadLex Playbook is a project of the Radiological Society of North America (RSNA)"/>
<radiology_report_template template_id="1" charset="UTF-8" path="test/test1.html" dcterms_title="CT Chest Pulmonary Embolism" dcterms_description="description1" dcterms_language="en" dcterms_identifier="identifier1" dcterms_publisher="IHE CAT Publisher" creator="1" date_created="2015-02-02 12:26:35.0" uuid="aa551445-def0-4f93-9047-95f0a9afbdce"/>
<radiology_report_template template_id="2" charset="UTF-8" path="test/test2.html" dcterms_title="CT Cardiac Bypass Graft" dcterms_description="description2" dcterms_language="en" dcterms_identifier="identifier2" dcterms_publisher="Some cat organization" creator="1" date_created="2015-02-03 13:17:15.0" uuid="59273e52-33b1-4fcb-8c1f-9b670bb11259"/>
<radiology_report_template template_id="1" charset="UTF-8" path="test/test1.html" dcterms_title="CT Chest Pulmonary Embolism" dcterms_description="description1" dcterms_language="en" dcterms_identifier="identifier1" dcterms_publisher="IHE CAT Publisher" dcterms_license="Mozilla Public License" creator="1" date_created="2015-02-02 12:26:35.0" uuid="aa551445-def0-4f93-9047-95f0a9afbdce"/>
<radiology_report_template template_id="2" charset="UTF-8" path="test/test2.html" dcterms_title="CT Cardiac Bypass Graft" dcterms_description="description2" dcterms_language="en" dcterms_identifier="identifier2" dcterms_publisher="Some cat organization" dcterms_license="General Public License" creator="1" date_created="2015-02-03 13:17:15.0" uuid="59273e52-33b1-4fcb-8c1f-9b670bb11259"/>
<radiology_report_template_reference_term template_id="1" term_id="1"/>
</dataset>
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,14 @@ public class MrrtReportTemplateSearchHandler implements SearchHandler {

public static final String REQUEST_PARAM_TOTAL_COUNT = "totalCount";

public static final String REQUEST_PARAM_LICENSE = "license";

@Autowired
private MrrtReportTemplateService mrrtReportTemplateService;

SearchQuery searchQuery = new SearchQuery.Builder("Allows you to search for MrrtReportTemplate's by title")
.withOptionalParameters(new String[] { REQUEST_PARAM_TITLE, REQUEST_PARAM_PUBLISHER, REQUEST_PARAM_TOTAL_COUNT })
.withOptionalParameters(new String[] { REQUEST_PARAM_TITLE, REQUEST_PARAM_PUBLISHER, REQUEST_PARAM_LICENSE,
REQUEST_PARAM_TOTAL_COUNT })
.build();

private final SearchConfig searchConfig = new SearchConfig("default", RestConstants.VERSION_1 + "/mrrtreporttemplate",
Expand All @@ -65,15 +68,19 @@ public SearchConfig getSearchConfig() {
* @should return all mrrt templates that match given title and totalCount if requested
* @should return all report templates by given publisher
* @should return empty search result if publisher does not exist
* @should return all report templates that match given license
* @should return empty search result if license does not exist
*/
@Override
public PageableResult search(RequestContext context) throws ResponseException {

final String templateTitle = context.getParameter("title");
final String publisher = context.getParameter("publisher");
final String templateLicense = context.getParameter("license");
final MrrtReportTemplateSearchCriteria searchCriteria =
new MrrtReportTemplateSearchCriteria.Builder().withTitle(templateTitle)
.withPublisher(publisher)
.withLicense(templateLicense)
.build();

final List<MrrtReportTemplate> result = mrrtReportTemplateService.getMrrtReportTemplates(searchCriteria);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ public class MrrtReportTemplateSearchHandlerComponentTest extends MainResourceCo

private static final String NON_EXISTING_PUBLISHER = "Non existing publisher";

private static final String LICENSE_QUERY = "General Public License";

private static final String NON_EXISTING_LICENSE = "Non existing license";

@Autowired
MrrtReportTemplateService mrrtReportTemplateService;

Expand Down Expand Up @@ -177,4 +181,42 @@ public void search_shouldReturnEmptySearchResultIfPublisherDoesNotExist() throws
List<Object> hits = (List<Object>) resultMrrtReportTemplate.get("results");
assertThat(hits.size(), is(0));
}

/**
* @see MrrtReportTemplateSearchHandler#search(RequestContext)
* @verifies return all report templates that match given license
*/
@Test
public void search_shouldReturnAllReportTemplatesThatMatchGivenLicense() throws Exception {
MockHttpServletRequest mrrtReportTemplateRequest = request(RequestMethod.GET, getURI());
mrrtReportTemplateRequest.setParameter(MrrtReportTemplateSearchHandler.REQUEST_PARAM_LICENSE, LICENSE_QUERY);
SimpleObject resultMrrtReportTemplate = deserialize(handle(mrrtReportTemplateRequest));

assertNotNull(resultMrrtReportTemplate);
List<Object> hits = (List<Object>) resultMrrtReportTemplate.get("results");
MrrtReportTemplateSearchCriteria searchCriteria =
new MrrtReportTemplateSearchCriteria.Builder().withLicense(LICENSE_QUERY)
.build();
assertThat(hits.size(), is(1));
assertThat(PropertyUtils.getProperty(hits.get(0), "uuid"),
is(mrrtReportTemplateService.getMrrtReportTemplates(searchCriteria)
.get(0)
.getUuid()));
assertNull(PropertyUtils.getProperty(resultMrrtReportTemplate, "totalCount"));
}

/**
* @see MrrtReportTemplateSearchHandler#search(RequestContext)
* @verifies return empty search result if license does not exist
*/
@Test
public void search_shouldReturnEmptySearchResultIfLicenseDoesNotExist() throws Exception {
MockHttpServletRequest mockRequest = request(RequestMethod.GET, getURI());
mockRequest.setParameter(MrrtReportTemplateSearchHandler.REQUEST_PARAM_LICENSE, NON_EXISTING_LICENSE);
SimpleObject resultMrrtReportTemplate = deserialize(handle(mockRequest));

assertNotNull(resultMrrtReportTemplate);
List<Object> hits = (List<Object>) resultMrrtReportTemplate.get("results");
assertThat(hits.size(), is(0));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ public class MrrtReportTemplateSearchHandlerTest {

private static final String NON_EXISTING_PUBLISHER = "Non existing publisher";

private static final String LICENSE_QUERY = "General Public License";

private static final String NON_EXISTING_LICENSE = "Non existing license";

@Mock
RestService RestService;

Expand Down Expand Up @@ -144,4 +148,30 @@ public void search_shouldReturnEmptySearchResultIfPublisherDoesNotExist() throws
PageableResult pageableResult = mrrtReportTemplateSearchHandler.search(requestContext);
assertThat(pageableResult, is(instanceOf(EmptySearchResult.class)));
}

/**
* @see MrrtReportTemplateSearchHandler#search(RequestContext)
* @verifies return all report templates that match given license
*/
@Test
public void search_shouldReturnAllReportTemplatesThatMatchGivenLicense() throws Exception {
request.setParameter(MrrtReportTemplateSearchHandler.REQUEST_PARAM_LICENSE, LICENSE_QUERY);
when(mrrtReportTemplateService.getMrrtReportTemplates(any(MrrtReportTemplateSearchCriteria.class)))
.thenReturn(mrrtReportTemplates);

PageableResult pageableResult = mrrtReportTemplateSearchHandler.search(requestContext);
assertThat(pageableResult, is(instanceOf(NeedsPaging.class)));
}

/**
* @see MrrtReportTemplateSearchHandler#search(RequestContext)
* @verifies return empty search result if license does not exist
*/
@Test
public void search_shouldReturnEmptySearchResultIfLicenseDoesNotExist() throws Exception {
request.setParameter(MrrtReportTemplateSearchHandler.REQUEST_PARAM_LICENSE, NON_EXISTING_LICENSE);

PageableResult pageableResult = mrrtReportTemplateSearchHandler.search(requestContext);
assertThat(pageableResult, is(instanceOf(EmptySearchResult.class)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
-->
<dataset>
<radiology_report_template template_id="1" charset="UTF-8" path="test/test1.html" dcterms_title="Cardiac MRI: Adenosine Stress Protocol" dcterms_description="description1" dcterms_language="en" dcterms_identifier="org/radrep/0001" creator="1" date_created="2015-02-02 12:26:35.0" uuid="2379d290-96f7-408a-bbae-270387e3b92e"/>
<radiology_report_template template_id="2" charset="UTF-8" path="test/test2.html" dcterms_title="Cardiac MRI: Function and Viability" dcterms_description="description2" dcterms_language="en" dcterms_identifier="org/radrep/0002" dcterms_publisher="IHE CAT Publisher" creator="1" date_created="2015-02-03 13:17:15.0" uuid="59273e52-33b1-4fcb-8c1f-9b670bb11259"/>
<radiology_report_template template_id="2" charset="UTF-8" path="test/test2.html" dcterms_title="Cardiac MRI: Function and Viability" dcterms_description="description2" dcterms_language="en" dcterms_identifier="org/radrep/0002" dcterms_publisher="IHE CAT Publisher" dcterms_license="General Public License" creator="1" date_created="2015-02-03 13:17:15.0" uuid="59273e52-33b1-4fcb-8c1f-9b670bb11259"/>
</dataset>

0 comments on commit f072080

Please sign in to comment.