Skip to content

Commit

Permalink
Supported search history at API and Database levels
Browse files Browse the repository at this point in the history
  • Loading branch information
k-joseph committed May 28, 2015
1 parent dbb8f56 commit 9fb3d40
Show file tree
Hide file tree
Showing 7 changed files with 243 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/**
* 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 com.openmrs.module.chartsearch.saving;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Access;
import javax.persistence.AccessType;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.openmrs.BaseOpenmrsObject;
import org.openmrs.Patient;
import org.openmrs.User;

@Entity
@Table(name = "chartsearch_history")
@SuppressWarnings("serial")
public class ChartSearchHistory extends BaseOpenmrsObject implements Serializable {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "search_id")
private Integer searchId;

/**
* Should be not save searches for the same phrase but rather just updated lastSearchedAt
*/
@Column(name = "search_phrase", nullable = false, unique = true)
private String searchPhrase;

@Column(name = "last_searched_at", nullable = false)
private Date lastSearchedAt;

@ManyToOne
@JoinColumn(name = "patient_id", nullable = false)
private Patient patient;

@ManyToOne
@JoinColumn(name = "user_id", nullable = false)
private User historyOwner;

/**
* @see org.openmrs.BaseOpenmrsObject#getUuid()
*/
@Basic
@Access(AccessType.PROPERTY)
@Column(name = "uuid", length = 38, unique = true)
@Override
public String getUuid() {
return super.getUuid();
}

@Override
public Integer getId() {
return getSearchId();
}

@Override
public void setId(Integer id) {
setSearchId(id);
}

public Integer getSearchId() {
return searchId;
}

public void setSearchId(Integer searchId) {
this.searchId = searchId;
}

public String getSearchPhrase() {
return searchPhrase;
}

public void setSearchPhrase(String searchPhrase) {
this.searchPhrase = searchPhrase;
}

public Date getLastSearchedAt() {
return lastSearchedAt;
}

public void setLastSearchedAt(Date lastSearchedAt) {
this.lastSearchedAt = lastSearchedAt;
}

public Patient getPatient() {
return patient;
}

public void setPatient(Patient patient) {
this.patient = patient;
}

public User getHistoryOwner() {
return historyOwner;
}

public void setHistoryOwner(User historyOwner) {
this.historyOwner = historyOwner;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import org.openmrs.module.chartsearch.synonyms.SynonymGroup;
import org.springframework.transaction.annotation.Transactional;

import com.openmrs.module.chartsearch.saving.ChartSearchHistory;

/**
* This service exposes module's core functionality. It is a Spring managed bean which is configured
* in moduleApplicationContext.xml.
Expand Down Expand Up @@ -184,4 +186,14 @@ public interface ChartSearchService extends OpenmrsService {
void indexAllPatientData(Integer numberOfResults, SolrServer solrServer, Class showProgressToClass);

public List<String> getAllPossibleSearchSuggestions(Integer patientId);

public ChartSearchHistory getSearchHistory(Integer searchId);

public void saveSearchHistory(ChartSearchHistory searchHistory);

public void deleteSearchHistory(ChartSearchHistory searchHistory);

public ChartSearchHistory getSearchHistoryByIUuid(String uuid);

public List<ChartSearchHistory> getAllSearchesInHistory();
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,28 @@
*/
package org.openmrs.module.chartsearch.api.db;

import java.util.List;

import org.apache.solr.client.solrj.SolrServer;
import org.openmrs.module.chartsearch.api.ChartSearchService;

import com.openmrs.module.chartsearch.saving.ChartSearchHistory;

/**
* Database methods for {@link ChartSearchService}.
*/
public interface ChartSearchDAO {

public void indexAllPatientData(Integer numberOfResults, SolrServer solrServer,
@SuppressWarnings("rawtypes") Class showProgressToClass);

public ChartSearchHistory getSearchHistory(Integer searchId);

public void saveSearchHistory(ChartSearchHistory searchHistory);

public void deleteSearchHistory(ChartSearchHistory searchHistory);

public ChartSearchHistory getSearchHistoryByIUuid(String uuid);

public List<ChartSearchHistory> getAllSearchesInHistory();
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
Expand All @@ -28,6 +29,8 @@
import org.openmrs.module.chartsearch.api.db.ChartSearchDAO;
import org.openmrs.module.chartsearch.solr.ChartSearchCustomIndexer;

import com.openmrs.module.chartsearch.saving.ChartSearchHistory;

/**
* It is a default implementation of {@link ChartSearchDAO}.
*/
Expand Down Expand Up @@ -157,4 +160,33 @@ private static void addResultsFieldValuesToADocument(SolrInputDocument doc) {
doc.addField("concept_class_name", ChartSearchCustomIndexer.getConceptClassName());
}

@Override
public ChartSearchHistory getSearchHistory(Integer searchId) {
return (ChartSearchHistory) sessionFactory.getCurrentSession().get(ChartSearchHistory.class, searchId);
}

@Override
public void saveSearchHistory(ChartSearchHistory searchHistory) {
sessionFactory.getCurrentSession().saveOrUpdate(searchHistory);
}

@Override
public void deleteSearchHistory(ChartSearchHistory searchHistory) {
sessionFactory.getCurrentSession().delete(searchHistory);
}

@Override
public ChartSearchHistory getSearchHistoryByIUuid(String uuid) {
ChartSearchHistory history = (ChartSearchHistory) sessionFactory.getCurrentSession()
.createQuery("from ChartSearchHistory h where h.uuid = :uuid").setString("uuid", uuid).uniqueResult();

return history;
}

@SuppressWarnings("unchecked")
@Override
public List<ChartSearchHistory> getAllSearchesInHistory() {
return sessionFactory.getCurrentSession().createCriteria(ChartSearchHistory.class).list();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
import org.openmrs.util.PrivilegeConstants;
import org.springframework.transaction.annotation.Transactional;

import com.openmrs.module.chartsearch.saving.ChartSearchHistory;

/**
* It is a default implementation of {@link ChartSearchService}.
*/
Expand Down Expand Up @@ -342,4 +344,29 @@ public List<String> getAllPossibleSearchSuggestions(Integer patientId) {

return conceptNameSuggestions;
}

@Override
public ChartSearchHistory getSearchHistory(Integer searchId) {
return dao.getSearchHistory(searchId);
}

@Override
public void saveSearchHistory(ChartSearchHistory searchHistory) {
dao.saveSearchHistory(searchHistory);
}

@Override
public void deleteSearchHistory(ChartSearchHistory searchHistory) {
dao.deleteSearchHistory(searchHistory);
}

@Override
public ChartSearchHistory getSearchHistoryByIUuid(String uuid) {
return dao.getSearchHistoryByIUuid(uuid);
}

@Override
public List<ChartSearchHistory> getAllSearchesInHistory() {
return dao.getAllSearchesInHistory();
}
}
37 changes: 37 additions & 0 deletions api/src/main/resources/liquibase.xml
Original file line number Diff line number Diff line change
Expand Up @@ -189,5 +189,42 @@
<column name="uuid" value="21ac0fec-947f-4a76-aeee-2e17d9d0cb13" />
</insert>
</changeSet>

<changeSet id="CSM-102_28052015_1742" author="k-joseph">
<preConditions onFail="MARK_RAN">
<not>
<tableExists tableName="chartsearch_history" />
</not>
</preConditions>
<comment>
Create chartsearch_history table
</comment>
<createTable tableName="chartsearch_history">
<column name="search_id" type="int" autoIncrement="true">
<constraints primaryKey="true" nullable="false" />
</column>
<column name="search_phrase" type="text">
<constraints nullable="false" />
</column>
<column name="last_searched_at" type="date">
<constraints nullable="false" />
</column>
<column name="uuid" type="char(38)">
<constraints nullable="false" />
</column>
<column name="user_id" type="int(11)" >
<constraints nullable="false" />
</column>
<column name="patient_id" type="int(11)" >
<constraints nullable="false" />
</column>
</createTable>
<addForeignKeyConstraint constraintName="history_owner-fk"
baseTableName="chartsearch_history" baseColumnNames="user_id"
referencedTableName="users" referencedColumnNames="user_id"/>
<addForeignKeyConstraint constraintName="patient-fk"
baseTableName="chartsearch_history" baseColumnNames="patient_id"
referencedTableName="patient" referencedColumnNames="patient_id"/>
</changeSet>

</databaseChangeLog>
3 changes: 2 additions & 1 deletion omod/src/main/webapp/fragments/topArea.gsp
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@
//if (searchText.value != "") {
hideSearchSuggestions();
jq("#chart-previous-searches-display").hide();
jq(".obsgroup_view").empty();
jq("#found-results-summary").html('');
jq("#obsgroups_results").html('<img class="search-spinner" src="../ms/uiframework/resource/uicommons/images/spinner.gif">');
Expand Down Expand Up @@ -474,7 +475,7 @@
position: absolute;
z-index: 1;
height: 250px;
width: 784px;
width: 781px;
overflow: scroll;
background-color: white;
padding-left: 10px;
Expand Down

0 comments on commit 9fb3d40

Please sign in to comment.