Skip to content

Commit

Permalink
Merge pull request I-TECH-UW#1095 from rahul6603/mapping
Browse files Browse the repository at this point in the history
Add mapping for indexing Patient and Person entities
  • Loading branch information
mozzy11 authored Jun 25, 2024
2 parents b0f3b14 + e4ab89f commit 75fe9c5
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.openelisglobal.hibernate.search.analysis;

import org.hibernate.search.backend.lucene.analysis.LuceneAnalysisConfigurationContext;
import org.hibernate.search.backend.lucene.analysis.LuceneAnalysisConfigurer;

public class CustomLuceneAnalysisConfigurer implements LuceneAnalysisConfigurer {
@Override
public void configure(LuceneAnalysisConfigurationContext context) {
context.normalizer("lowercase").custom().tokenFilter("lowercase").tokenFilter("asciifolding");
}
}
15 changes: 12 additions & 3 deletions src/main/java/org/openelisglobal/patient/valueholder/Patient.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,31 @@
import java.sql.Date;
import java.sql.Timestamp;
import java.util.UUID;
import org.hibernate.search.engine.backend.types.ObjectStructure;
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.GenericField;
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.Indexed;
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.IndexedEmbedded;
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.KeywordField;
import org.openelisglobal.common.util.DateUtil;
import org.openelisglobal.common.valueholder.BaseObject;
import org.openelisglobal.common.valueholder.ValueHolder;
import org.openelisglobal.common.valueholder.ValueHolderInterface;
import org.openelisglobal.person.valueholder.Person;

@Indexed
public class Patient extends BaseObject<String> {

private static final long serialVersionUID = 1L;

private String id;
@GenericField private String id;

private String race;

private String gender;
@GenericField private String gender;

private Timestamp birthDate;

private String birthDateForDisplay;
@GenericField private String birthDateForDisplay;

private String epiFirstName;

Expand All @@ -50,6 +56,7 @@ public class Patient extends BaseObject<String> {

private String deathDateForDisplay;

@KeywordField(normalizer = "lowercase")
private String nationalId;

private String ethnicity;
Expand All @@ -62,8 +69,10 @@ public class Patient extends BaseObject<String> {

private String birthPlace;

@IndexedEmbedded(structure = ObjectStructure.NESTED)
private ValueHolderInterface person;

@KeywordField(normalizer = "lowercase")
private String externalId;

private String upidCode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
import java.util.Set;
import javax.validation.constraints.Email;
import javax.validation.constraints.Pattern;
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.AssociationInverseSide;
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.KeywordField;
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.ObjectPath;
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.PropertyValue;
import org.openelisglobal.common.validator.ValidationHelper;
import org.openelisglobal.common.valueholder.BaseObject;
import org.openelisglobal.patient.valueholder.Patient;
Expand All @@ -29,9 +33,11 @@ public class Person extends BaseObject<String> {
private String id;

@ValidName(nameType = NameType.LAST_NAME)
@KeywordField(normalizer = "lowercase")
private String lastName;

@ValidName(nameType = NameType.FIRST_NAME)
@KeywordField(normalizer = "lowercase")
private String firstName;

private String middleName;
Expand Down Expand Up @@ -63,6 +69,7 @@ public class Person extends BaseObject<String> {
private String fax;
@Email private String email;

@AssociationInverseSide(inversePath = @ObjectPath(@PropertyValue(propertyName = "person")))
private Set<Patient> patients = new HashSet<>(0);

public Person() {
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/persistence/persistence.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
value="classpath:hibernate/hibernate.cfg.xml" />
<property name="hibernate.search.backend.directory.type" value="local-filesystem" />
<property name="hibernate.search.backend.directory.root" value="/var/lib/lucene_index" />
<property name="hibernate.search.backend.analysis.configurer" value="class:org.openelisglobal.hibernate.search.analysis.CustomLuceneAnalysisConfigurer"/>
</properties>

</persistence-unit>
Expand Down
1 change: 1 addition & 0 deletions src/test/resources/persistence/test-persistence.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
<properties>
<property name="hibernate.ejb.cfgfile"
value="hibernate/test-hibernate.cfg.xml" />
<property name="hibernate.search.backend.analysis.configurer" value="class:org.openelisglobal.hibernate.search.analysis.CustomLuceneAnalysisConfigurer"/>
</properties>

</persistence-unit>
Expand Down

0 comments on commit 75fe9c5

Please sign in to comment.