Skip to content

Commit

Permalink
TRUNK-4426 Search widget should find concepts by mappings
Browse files Browse the repository at this point in the history
  • Loading branch information
rkorytkowski committed Aug 19, 2014
1 parent f38b8ad commit 4be239e
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 3 deletions.
1 change: 1 addition & 0 deletions api/src/main/java/org/openmrs/Concept.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ public class Concept extends BaseOpenmrsObject implements Auditable, Retireable,

private Collection<ConceptDescription> descriptions;

@IndexedEmbedded
private Collection<ConceptMap> conceptMappings;

/**
Expand Down
9 changes: 8 additions & 1 deletion api/src/main/java/org/openmrs/ConceptMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
*/
package org.openmrs;

import org.hibernate.search.annotations.ContainedIn;
import org.hibernate.search.annotations.DocumentId;
import org.hibernate.search.annotations.Indexed;
import org.hibernate.search.annotations.IndexedEmbedded;
import org.simpleframework.xml.Attribute;
import org.simpleframework.xml.Element;
import org.simpleframework.xml.Root;
Expand All @@ -22,16 +26,19 @@
* N mappings to any and all concept sources in the database.
*/
@Root
@Indexed
public class ConceptMap extends BaseConceptMap implements java.io.Serializable {

public static final long serialVersionUID = 754677L;

// Fields

@DocumentId
private Integer conceptMapId;

@ContainedIn
private Concept concept;

@IndexedEmbedded
private ConceptReferenceTerm conceptReferenceTerm;

// Constructors
Expand Down
1 change: 1 addition & 0 deletions api/src/main/java/org/openmrs/ConceptName.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public class ConceptName extends BaseOpenmrsObject implements Auditable, Voidabl

private Collection<ConceptNameTag> tags;

@Field
private ConceptNameType conceptNameType;

@Field
Expand Down
8 changes: 8 additions & 0 deletions api/src/main/java/org/openmrs/ConceptReferenceTerm.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,30 @@
import java.util.LinkedHashSet;
import java.util.Set;

import org.hibernate.search.annotations.DocumentId;
import org.hibernate.search.annotations.Field;
import org.hibernate.search.annotations.Index;
import org.hibernate.search.annotations.Indexed;

/**
* A concept reference term is typically name for a concept by which it is referred in another
* institution like ICD9, ICD10, SNOMED that keeps a concept dictionary or any other OpenMRS
* implementation
*
* @since 1.9
*/
@Indexed
public class ConceptReferenceTerm extends BaseOpenmrsMetadata implements java.io.Serializable {

private static final long serialVersionUID = 1L;

@DocumentId
private Integer conceptReferenceTermId;

private ConceptSource conceptSource;

//The unique code used to identify the reference term in it's reference terminology
@Field(index = Index.UN_TOKENIZED)
private String code;

private String version;
Expand Down
1 change: 1 addition & 0 deletions api/src/main/java/org/openmrs/api/ConceptService.java
Original file line number Diff line number Diff line change
Expand Up @@ -1338,6 +1338,7 @@ public interface ConceptService extends OpenmrsService {
* @should return a search result for phrase with stop words
* @should not return concepts with matching names that are voided
* @should return preferred names higher
* @should find concept by full code
* @since 1.8
*/
@Authorized(PrivilegeConstants.GET_CONCEPTS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -606,10 +606,10 @@ private String newConceptNameQuery(final String name, final boolean searchKeywor

final StringBuilder query = new StringBuilder();

query.append("((");
query.append("(concept.conceptMappings.conceptReferenceTerm.code:(").append(escapedName).append(")^0.4 OR (");
final StringBuilder nameQuery = newNameQuery(tokenizedName, escapedName, searchKeywords);
query.append(nameQuery);
query.append(" localePreferred:true)^0.8 OR (");
query.append(" (localePreferred:true OR conceptNameType:FULLY_SPECIFIED))^0.4 OR (");
query.append(nameQuery);
query.append(")^0.2)");

Expand Down
22 changes: 22 additions & 0 deletions api/src/test/java/org/openmrs/api/ConceptServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3244,4 +3244,26 @@ public void getConcepts_shouldReturnPreferredNamesHigher() throws Exception {

assertThat(concepts, contains(hasConcept(is(mdrTbProgram)), hasConcept(is(hivProgram))));
}

/**
* @see ConceptService#getConcepts(String,List,boolean,List,List,List,List,Concept,Integer,Integer)
* @verifies find concept by full code
*/
@Test
public void getConcepts_shouldFindConceptByFullCode() throws Exception {
//given
String code1 = "CD41003";
String code2 = "7345693";
Concept concept = conceptService.getConceptByMapping(code2, "SNOMED CT");

//when
List<ConceptSearchResult> concepts1 = conceptService.getConcepts(code1, Arrays.asList(Context.getLocale()), false,
null, null, null, null, null, null, null);
List<ConceptSearchResult> concepts2 = conceptService.getConcepts(code2, Arrays.asList(Context.getLocale()), false,
null, null, null, null, null, null, null);

//then
assertThat(concepts1, contains(hasConcept(is(concept))));
assertThat(concepts2, contains(hasConcept(is(concept))));
}
}

0 comments on commit 4be239e

Please sign in to comment.