Skip to content

Commit

Permalink
if possible, filter homepage search based on current country
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Zurek committed Jul 7, 2015
1 parent bf63039 commit 9a6b081
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 9 deletions.
28 changes: 28 additions & 0 deletions app/femr/business/helpers/QueryHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@
*/
package femr.business.helpers;

import com.avaje.ebean.ExpressionList;
import com.avaje.ebean.Query;
import femr.data.daos.IRepository;
import femr.data.models.core.IPatient;
import femr.data.models.core.IPatientEncounterVital;
import femr.data.models.mysql.Patient;
import femr.data.models.mysql.PatientEncounterVital;

import java.util.List;
Expand Down Expand Up @@ -71,4 +74,29 @@ public static Integer findPatientHeightInches(IRepository<IPatientEncounterVital
}
return heightInches;
}

/**
* finds all patients with a country filter
*/
public static List<? extends IPatient> findPatients(IRepository<IPatient> patientRepository, String country){

ExpressionList<Patient> patientExpressionList = QueryProvider.getPatientQuery()
.select("*")
.fetch("patientEncounters")
.fetch("patientEncounters.missionTrip")
.fetch("patientEncounters.missionTrip.missionCity")
.fetch("patientEncounters.missionTrip.missionCity.missionCountry")
.where()
.eq("patientEncounters.missionTrip.missionCity.missionCountry.name", country);

return patientExpressionList.findList();
}

/**
* finds all patients without a country filter
*/
public static List<? extends IPatient> findPatients(IRepository<IPatient> patientRepository){

return patientRepository.findAll(Patient.class);
}
}
38 changes: 32 additions & 6 deletions app/femr/business/services/system/SearchService.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,11 @@
import femr.common.IItemModelMapper;
import femr.common.dtos.ServiceResponse;
import femr.common.models.*;
import femr.data.IDataModelMapper;
import femr.data.daos.IRepository;
import femr.data.models.core.*;
import femr.data.models.mysql.*;
import femr.util.calculations.LocaleUnitConverter;
import femr.util.stringhelpers.StringUtils;

import java.util.*;

public class SearchService implements ISearchService {
Expand Down Expand Up @@ -96,7 +94,7 @@ public ServiceResponse<PatientItem> retrievePatientItemByPatientId(int patientId

String pathToPhoto = null;
Integer photoId = null;
if (savedPatient.getPhoto() != null){
if (savedPatient.getPhoto() != null) {
pathToPhoto = savedPatient.getPhoto().getFilePath();
photoId = savedPatient.getPhoto().getId();
}
Expand Down Expand Up @@ -158,7 +156,7 @@ public ServiceResponse<PatientItem> retrievePatientItemByEncounterId(int encount

String pathToPhoto = null;
Integer photoId = null;
if (patient.getPhoto() != null){
if (patient.getPhoto() != null) {
pathToPhoto = patient.getPhoto().getFilePath();
photoId = patient.getPhoto().getId();
}
Expand Down Expand Up @@ -404,6 +402,7 @@ public ServiceResponse<List<PatientItem>> retrievePatientsFromQueryString(String


//Build the Query
//TODO: filter these by the current country of the team
Query<Patient> query = null;
if (id != null) {
//if we have an id, that is all we need.
Expand Down Expand Up @@ -510,7 +509,33 @@ public ServiceResponse<List<PatientItem>> retrievePatientsForSearch() {
ServiceResponse<List<PatientItem>> response = new ServiceResponse<>();

try {
List<? extends IPatient> allPatients = patientRepository.findAll(Patient.class);
ExpressionList<SystemSetting> expressionList = QueryProvider.getSystemSettingQuery()
.where()
.eq("name", "Country Filter");
ISystemSetting systemSetting = systemSettingRepository.findOne(expressionList);

ExpressionList<MissionTrip> missionTripExpressionList = QueryProvider.getMissionTripQuery()
.where()
.eq("isCurrent", true);
IMissionTrip missionTrip = missionTripExpressionList.findUnique();

List<? extends IPatient> allPatients;

//Make sure that none of the values we will be checking are null.
//If they are, just get all of the possible patients.
if (systemSetting != null &&
systemSetting.isActive() &&
missionTrip != null &&
missionTrip.getMissionCity() != null &&
missionTrip.getMissionCity().getMissionCountry() != null &&
StringUtils.isNotNullOrWhiteSpace(missionTrip.getMissionCity().getMissionCountry().getName())){

allPatients = QueryHelper.findPatients(patientRepository, missionTrip.getMissionCity().getMissionCountry().getName());
}else{

allPatients = QueryHelper.findPatients(patientRepository);
}

List<PatientItem> patientItems = new ArrayList<>();

for (IPatient patient : allPatients) {
Expand Down Expand Up @@ -570,7 +595,7 @@ public ServiceResponse<List<String>> findDiagnosisForSearch() {
List<? extends IDiagnosis> allDiagnoses = diagnosisRepository.findAll(Diagnosis.class);
List<String> diagnoses = new ArrayList<>();

for (IDiagnosis d : allDiagnoses){
for (IDiagnosis d : allDiagnoses) {
if (StringUtils.isNotNullOrWhiteSpace(d.getName()))
diagnoses.add(d.getName());
}
Expand All @@ -586,6 +611,7 @@ public ServiceResponse<List<String>> findDiagnosisForSearch() {

/**
* Gets isActive of the metric setting
*
* @return
*/
private boolean isMetric() {
Expand Down
6 changes: 6 additions & 0 deletions app/femr/data/models/core/IPatient.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
*/
package femr.data.models.core;

import femr.data.models.mysql.PatientEncounter;
import java.util.Date;
import java.util.List;

public interface IPatient {

Expand Down Expand Up @@ -57,4 +59,8 @@ public interface IPatient {
IPhoto getPhoto();

void setPhoto(IPhoto photo);

List<PatientEncounter> getPatientEncounters();

void setPatientEncounters(List<PatientEncounter> patientEncounters);
}
13 changes: 13 additions & 0 deletions app/femr/data/models/mysql/Patient.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import javax.persistence.*;
import java.util.Date;
import java.util.List;

@Entity
@Table(name = "patients")
Expand All @@ -47,6 +48,8 @@ public class Patient implements IPatient {
@OneToOne(fetch = FetchType.EAGER)
@JoinColumn(name= "photo_id", nullable = true)
private Photo photo;
@OneToMany(mappedBy = "patient", fetch = FetchType.LAZY)
private List<PatientEncounter> patientEncounters;

@Override
public int getId() {
Expand Down Expand Up @@ -137,4 +140,14 @@ public IPhoto getPhoto() {
public void setPhoto(IPhoto photo) {
this.photo = (Photo) photo;
}

@Override
public List<PatientEncounter> getPatientEncounters() {
return patientEncounters;
}

@Override
public void setPatientEncounters(List<PatientEncounter> patientEncounters) {
this.patientEncounters = patientEncounters;
}
}
2 changes: 1 addition & 1 deletion app/femr/data/models/mysql/PatientEncounter.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class PatientEncounter implements IPatientEncounter {
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "patient_age_classification_id")
private PatientAgeClassification patientAgeClassification;
@ManyToOne(fetch = FetchType.LAZY)
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "mission_trip_id")
private MissionTrip missionTrip;

Expand Down
11 changes: 9 additions & 2 deletions app/femr/util/startup/DatabaseSeeder.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@
import femr.util.calculations.dateUtils;
import femr.util.encryptions.BCryptPasswordEncryptor;
import femr.util.encryptions.IPasswordEncryptor;
import org.h2.expression.ExpressionList;
import play.Play;

import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -734,9 +732,18 @@ private void seedSystemSettings() {
if (systemSettings != null && !containSetting(systemSettings, "Metric System Option")) {
systemSetting = new SystemSetting();
systemSetting.setName("Metric System Option");
systemSetting.setActive(true);
systemSettingRepository.create(systemSetting);
}

//Filters the patient search based on which country the team is currently in
if (systemSettings != null && !containSetting(systemSettings, "Country Filter")) {
systemSetting = new SystemSetting();
systemSetting.setName("Country Filter");
systemSetting.setActive(false);
systemSettingRepository.create(systemSetting);
}

}

/**
Expand Down

0 comments on commit 9a6b081

Please sign in to comment.