Skip to content

Commit

Permalink
GSoC 2019: Patient search criteria added in openmrs core
Browse files Browse the repository at this point in the history
  • Loading branch information
Reyano132 committed Aug 9, 2019
1 parent 4a0a626 commit acf9b3a
Show file tree
Hide file tree
Showing 22 changed files with 353 additions and 143 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
language: java
jdk:
- oraclejdk8
- openjdk8
script: mvn clean install --batch-mode
matrix:
- jdk: oraclejdk8
- jdk: openjdk8
branches:
only:
- master
Expand Down
13 changes: 13 additions & 0 deletions api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,11 @@
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
Expand Down Expand Up @@ -239,6 +244,14 @@
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
</dependency>
</dependencies>
<build>
<resources>
Expand Down
24 changes: 24 additions & 0 deletions api/src/main/java/org/openmrs/Drug.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public class Drug extends BaseChangeableOpenmrsMetadata {

private String strength;

private Concept doseLimitUnits;

@IndexedEmbedded(includeEmbeddedObjectId = true)
private Concept concept;

Expand Down Expand Up @@ -276,4 +278,26 @@ public void addDrugReferenceMap(DrugReferenceMap drugReferenceMap) {
getDrugReferenceMaps().add(drugReferenceMap);
}
}

/**
* Gets the doseLimitUnits which represents the units of the existing maximumDailyDose and
* minimumDailyDose
*
* @param Returns the doseLimitUnits.
* @since 2.3.0
*/
public Concept getDoseLimitUnits() {
return doseLimitUnits;
}

/**
* Sets the doseLimitUnits which represents the units of the existing maximumDailyDose and
* minimumDailyDose
*
* @param doseLimitUnits The doseLimitUnits to set.
* @since 2.3.0
*/
public void setDoseLimitUnits(Concept doseLimitUnits) {
this.doseLimitUnits = doseLimitUnits;
}
}
43 changes: 43 additions & 0 deletions api/src/main/java/org/openmrs/FullTextSessionFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under
* the terms of the Healthcare Disclaimer located at http://openmrs.org/license.
*
* Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS
* graphic logo is a trademark of OpenMRS Inc.
*/
package org.openmrs;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.search.FullTextSession;
import org.hibernate.search.Search;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
* An instance of this class provides a factory for obtaining {@link FullTextSession} instances.
* Having this factory as a spring bean provides a mechanism that allows external code and modules
* to advise the factory. It is highly recommended to use this factory to create instances of the
* {@link FullTextSession} rather than directly calling {@link Search#getFullTextSession(Session)}
* for proper functionality.
*
* @since 2.2.1
*/
@Component("fullTextSessionFactory")
public class FullTextSessionFactory {

@Autowired
private SessionFactory sessionFactory;

/**
* Obtains a {@link FullTextSession} instance.
*
* @return {@link FullTextSession} object
*/
public FullTextSession getFullTextSession() {
return Search.getFullTextSession(sessionFactory.getCurrentSession());
}

}
75 changes: 73 additions & 2 deletions api/src/main/java/org/openmrs/Obs.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,28 @@
import java.util.Locale;
import java.util.Set;

import javax.persistence.Access;
import javax.persistence.AccessType;
import javax.persistence.AssociationOverride;
import javax.persistence.AttributeOverride;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.SecondaryTable;
import javax.persistence.Table;

import org.apache.commons.lang3.StringUtils;
import org.hibernate.annotations.BatchSize;
import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;
import org.openmrs.annotation.AllowDirectAccess;
import org.openmrs.api.APIException;
import org.openmrs.api.context.Context;
Expand Down Expand Up @@ -61,6 +82,12 @@
*
* @see Encounter
*/
@Entity
@Table(name = "obs")
@BatchSize(size = 25)
@SecondaryTable(name = "obs_unused_fields")
@AssociationOverride(name = "changedBy", joinColumns = @JoinColumn(table = "obs_unused_fields", name = "changed_by"))
@AttributeOverride(name = "dateChanged", column = @Column(table = "obs_unused_fields", name = "date_changed"))
public class Obs extends BaseChangeableOpenmrsData {

/**
Expand Down Expand Up @@ -91,12 +118,19 @@ public enum Status {

private static final int FORM_NAMESPACE_PATH_MAX_LENGTH = 255;

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "obs_id")
protected Integer obsId;

@JoinColumn(name = "concept_id")
@ManyToOne(optional = false)
protected Concept concept;

@Column(name = "obs_datetime", nullable = false, length = 19)
protected Date obsDatetime;

@Column(name = "accession_number")
protected String accessionNumber;

/**
Expand All @@ -106,55 +140,92 @@ public enum Status {
*
* @see #isObsGrouping() (??)
*/
@JoinColumn(name = "obs_group_id")
@ManyToOne
protected Obs obsGroup;

/**
* The list of obs grouped under this obs.
*/
@AllowDirectAccess
@OneToMany(mappedBy = "obsGroup")
@Cascade(CascadeType.DELETE)
@OrderBy("obs_id")
@BatchSize(size = 25)
@Access(AccessType.FIELD)
protected Set<Obs> groupMembers;

@JoinColumn(name = "value_coded")
@ManyToOne
protected Concept valueCoded;

@JoinColumn(name = "value_coded_name_id")
@ManyToOne
protected ConceptName valueCodedName;

@JoinColumn(name = "value_drug")
@ManyToOne
protected Drug valueDrug;

@Column(name = "value_group_id")
protected Integer valueGroupId;

@Column(name = "value_datetime", length = 19)
protected Date valueDatetime;

@Column(name = "value_numeric", length = 22)
protected Double valueNumeric;

@Column(name = "value_modifier", length = 2)
protected String valueModifier;

@Column(name = "value_text", length = 65535)
protected String valueText;

@Column(name = "value_complex")
protected String valueComplex;

// ComplexData is not persisted in the database.
protected transient ComplexData complexData;

@Column(name = "comments")
protected String comment;

protected transient Integer personId;
@Column(name = "person_id", nullable = false, insertable = false, updatable = false)
protected Integer personId;

@JoinColumn(name = "person_id")
@ManyToOne(optional = false)
protected Person person;

@JoinColumn(name = "order_id")
@ManyToOne
protected Order order;

@JoinColumn(name = "location_id")
@ManyToOne
protected Location location;

@JoinColumn(name = "encounter_id")
@ManyToOne
protected Encounter encounter;

@JoinColumn(name = "previous_version", unique = true)
@ManyToOne
private Obs previousVersion;

@Column(name = "form_namespace_and_path")
@Access(AccessType.FIELD)
private String formNamespaceAndPath;

private Boolean dirty = Boolean.FALSE;
private transient Boolean dirty = Boolean.FALSE;

@Enumerated(EnumType.STRING)
@Column(length = 32)
private Interpretation interpretation;

@Enumerated(EnumType.STRING)
@Column(nullable = false, length = 16)
private Status status = Status.FINAL;

/** default constructor */
Expand Down
24 changes: 23 additions & 1 deletion api/src/main/java/org/openmrs/OrderSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public enum Operator {

private List<OrderSetMember> orderSetMembers;

private Concept category;

/**
* Gets the orderSetId
*
Expand Down Expand Up @@ -96,7 +98,27 @@ public List<OrderSetMember> getOrderSetMembers() {
public void setOrderSetMembers(List<OrderSetMember> orderSetMembers) {
this.orderSetMembers = orderSetMembers;
}


/**
* Gets the category
*
* @return the category
* @since 2.3.0
*/
public Concept getCategory () {
return category;
}

/**
* Sets the category
*
* @param category category to set
* @since 2.3.0
*/
public void setCategory(Concept category) {
this.category = category;
}

/**
* Adds an orderSetMember to the existing list of orderSetMembers
*
Expand Down
2 changes: 2 additions & 0 deletions api/src/main/java/org/openmrs/Patient.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.hibernate.annotations.SortNatural;
import org.hibernate.search.annotations.ContainedIn;
import org.hibernate.search.annotations.Field;
import org.hibernate.search.annotations.Indexed;

/**
* Defines a Patient in the system. A patient is simply an extension of a person and all that that
Expand All @@ -41,6 +42,7 @@
@Entity
@Table(name = "patient")
@PrimaryKeyJoinColumn(name = "patient_id")
@Indexed
public class Patient extends Person {

public static final long serialVersionUID = 93123L;
Expand Down
10 changes: 9 additions & 1 deletion api/src/main/java/org/openmrs/Person.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,14 @@
import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;
import org.hibernate.annotations.SortNatural;
import org.hibernate.search.annotations.Analyze;
import org.hibernate.search.annotations.ContainedIn;
import org.hibernate.search.annotations.DateBridge;
import org.hibernate.search.annotations.DocumentId;
import org.hibernate.search.annotations.Field;
import org.hibernate.search.annotations.Index;
import org.hibernate.search.annotations.Indexed;
import org.hibernate.search.annotations.Resolution;
import org.openmrs.util.OpenmrsUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -65,6 +70,7 @@
@Entity
@Table(name = "person")
@Inheritance(strategy = InheritanceType.JOINED)
@Indexed
public class Person extends BaseChangeableOpenmrsData {

public static final long serialVersionUID = 2L;
Expand Down Expand Up @@ -102,10 +108,12 @@ public class Person extends BaseChangeableOpenmrsData {
@ContainedIn
private Set<PersonAttribute> attributes = null;

@Field
@Field(name="gender",index=Index.YES, analyze=Analyze.YES)
@Column(length = 50)
private String gender;

@Field(name="birthdate",index=Index.YES, analyze=Analyze.YES)
@DateBridge(resolution = Resolution.MILLISECOND)
@Column(name = "birthdate", length = 10)
private Date birthdate;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.hibernate.EmptyInterceptor;
import org.hibernate.type.Type;
import org.openmrs.Auditable;
import org.openmrs.Obs;
import org.openmrs.OpenmrsObject;
import org.openmrs.api.context.Context;
import org.slf4j.Logger;
Expand Down Expand Up @@ -83,6 +84,10 @@ public boolean onFlushDirty(Object entity, Serializable id, Object[] currentStat
}

Map<String, Object> propertyValues = getPropertyValuesToUpdate();
if (entity instanceof Obs) {
propertyValues.remove("changedBy");
propertyValues.remove("dateChanged");
}
objectWasChanged = changeProperties(currentState, propertyNames, objectWasChanged, propertyValues, false);
}
return objectWasChanged;
Expand Down
Loading

0 comments on commit acf9b3a

Please sign in to comment.