Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RAD-380: Search by report template creator #501

Merged
merged 1 commit into from
Dec 5, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ public List<MrrtReportTemplate> getMrrtReportTemplates(MrrtReportTemplateSearchC
if (searchCriteria.getLicense() != null) {
crit.add(Restrictions.ilike("dcTermsLicense", searchCriteria.getLicense() + "%", MatchMode.ANYWHERE));
}
if (searchCriteria.getCreator() != null) {
crit.add(Restrictions.ilike("dcTermsCreator", searchCriteria.getCreator() + "%", 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 @@ -21,6 +21,8 @@ public class MrrtReportTemplateSearchCriteria {

private final String license;

private final String creator;

/**
* @return the title of the mrrt report template
*/
Expand All @@ -44,6 +46,13 @@ public String getLicense() {
return license;
}

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

public static class Builder {


Expand All @@ -53,6 +62,8 @@ public static class Builder {

private String license;

private String creator;

/**
* @param title the title of the mrrt report template
* @return this builder instance
Expand Down Expand Up @@ -82,13 +93,23 @@ public Builder withLicense(String license) {
return this;
}

/**
* @param creator the creator of the mrrt report template
* @return this builder instance
*/
public Builder withCreator(String creator) {
this.creator = creator;
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
* @should create an mrrt report template search criteria instance with creator if creator is set
*/
public MrrtReportTemplateSearchCriteria build() {
return new MrrtReportTemplateSearchCriteria(this);
Expand All @@ -100,5 +121,6 @@ private MrrtReportTemplateSearchCriteria(Builder builder) {
this.title = builder.title;
this.publisher = builder.publisher;
this.license = builder.license;
this.creator = builder.creator;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ public interface MrrtReportTemplateService extends OpenmrsService {
* @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
* @should return all mrrt report templates that match given creator anywhere in dcterms creator insensitive to case
* @should return an empty list if no match for creator 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 @@ -61,4 +61,16 @@ public void build_shouldCreateAnMrrtReportTemplateSearchCriteriaInstanceWithLice
.build();
assertThat(mrrtReportTemplateSearchCriteria.getLicense(), is(license));
}

/**
* @see MrrtReportTemplateSearchCriteria.Builder#build()
* @verifies create an mrrt report template search criteria instance with creator if creator is set
*/
@Test
public void build_shouldCreateAnMrrtReportTemplateSearchCriteriaInstanceWithCreatorIfCreatorIsSet() throws Exception {
String creator = "creator1";
mrrtReportTemplateSearchCriteria = new MrrtReportTemplateSearchCriteria.Builder().withCreator(creator)
.build();
assertThat(mrrtReportTemplateSearchCriteria.getCreator(), is(creator));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ public class MrrtReportTemplateServiceComponentTest extends BaseModuleContextSen

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

private static final String EXISTING_TEMPLATE_CREATOR = "creator1";

private static final String NON_EXISTING_TEMPLATE_CREATOR = "Non existing creator";

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 @@ -533,6 +537,52 @@ public void getMrrtReportTemplates_shouldReturnAnEmptyListIfNoMatchForLicenseWas
assertTrue(templates.isEmpty());
}

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

assertNotNull(templates);
assertThat(templates.size(), is(1));
assertThat(templates.get(0)
.getDcTermsCreator(),
is(EXISTING_TEMPLATE_CREATOR));

searchCriteria = new MrrtReportTemplateSearchCriteria.Builder().withCreator("CREATOR")
.build();
templates = mrrtReportTemplateService.getMrrtReportTemplates(searchCriteria);
List<String> creators = new ArrayList<>();
templates.forEach(template -> creators.add(template.getDcTermsCreator()));

assertNotNull(creators);
assertThat(creators.size(), is(2));
assertThat(creators, hasItem("creator1"));
assertThat(creators, hasItem("creator2"));
}

/**
* @see MrrtReportTemplateService#getMrrtReportTemplates(MrrtReportTemplateSearchCriteria)
* @verifies return an empty list if no match for creator was found
*/
@Test
public void getMrrtReportTemplates_shouldReturnAnEmptyListIfNoMatchForCreatorWasFound() throws Exception {
MrrtReportTemplateSearchCriteria searchCriteria =
new MrrtReportTemplateSearchCriteria.Builder().withCreator(NON_EXISTING_TEMPLATE_CREATOR)
.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" 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 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" dcterms_creator="creator1" 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" dcterms_creator="creator2" 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 @@ -42,12 +42,14 @@ public class MrrtReportTemplateSearchHandler implements SearchHandler {

public static final String REQUEST_PARAM_LICENSE = "license";

public static final String REQUEST_PARAM_CREATOR = "creator";

@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_LICENSE,
REQUEST_PARAM_TOTAL_COUNT })
REQUEST_PARAM_CREATOR, REQUEST_PARAM_TOTAL_COUNT })
.build();

private final SearchConfig searchConfig = new SearchConfig("default", RestConstants.VERSION_1 + "/mrrtreporttemplate",
Expand All @@ -70,17 +72,22 @@ public SearchConfig getSearchConfig() {
* @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
* @should return all report templates that match given creator
* @should return empty search result if creator 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 String templateCreator = context.getParameter("creator");

final MrrtReportTemplateSearchCriteria searchCriteria =
new MrrtReportTemplateSearchCriteria.Builder().withTitle(templateTitle)
.withPublisher(publisher)
.withLicense(templateLicense)
.withCreator(templateCreator)
.build();

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

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

private static final String CREATOR_QUERY = "creator1";

private static final String NON_EXISTING_CREATOR = "Non existing creator";

@Autowired
MrrtReportTemplateService mrrtReportTemplateService;

Expand Down Expand Up @@ -219,4 +223,42 @@ public void search_shouldReturnEmptySearchResultIfLicenseDoesNotExist() throws E
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 creator
*/
@Test
public void search_shouldReturnAllReportTemplatesThatMatchGivenCreator() throws Exception {
MockHttpServletRequest mrrtReportTemplateRequest = request(RequestMethod.GET, getURI());
mrrtReportTemplateRequest.setParameter(MrrtReportTemplateSearchHandler.REQUEST_PARAM_CREATOR, CREATOR_QUERY);
SimpleObject resultMrrtReportTemplate = deserialize(handle(mrrtReportTemplateRequest));

assertNotNull(resultMrrtReportTemplate);
List<Object> hits = (List<Object>) resultMrrtReportTemplate.get("results");
MrrtReportTemplateSearchCriteria searchCriteria =
new MrrtReportTemplateSearchCriteria.Builder().withCreator(CREATOR_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 creator does not exist
*/
@Test
public void search_shouldReturnEmptySearchResultIfCreatorDoesNotExist() throws Exception {
MockHttpServletRequest mockRequest = request(RequestMethod.GET, getURI());
mockRequest.setParameter(MrrtReportTemplateSearchHandler.REQUEST_PARAM_CREATOR, NON_EXISTING_CREATOR);
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 @@ -62,6 +62,10 @@ public class MrrtReportTemplateSearchHandlerTest {

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

private static final String CREATOR_QUERY = "creator1";

private static final String NON_EXISTING_CREATOR = "Non existing creator";

@Mock
RestService RestService;

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

/**
* @see MrrtReportTemplateSearchHandler#search(RequestContext)
* @verifies return all report templates that match given creator
*/
@Test
public void search_shouldReturnAllReportTemplatesThatMatchGivenCreator() throws Exception {
request.setParameter(MrrtReportTemplateSearchHandler.REQUEST_PARAM_CREATOR, CREATOR_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 creator does not exist
*/
@Test
public void search_shouldReturnEmptySearchResultIfCreatorDoesNotExist() throws Exception {
request.setParameter(MrrtReportTemplateSearchHandler.REQUEST_PARAM_CREATOR, NON_EXISTING_CREATOR);

PageableResult pageableResult = mrrtReportTemplateSearchHandler.search(requestContext);
assertThat(pageableResult, is(instanceOf(EmptySearchResult.class)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@

-->
<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" 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 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" dcterms_creator="creator1" 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_creator="creator2" 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>