From f0b09545b9483c39216698b5b8f3090eeccba93b Mon Sep 17 00:00:00 2001 From: Tarang Date: Tue, 24 Jul 2012 16:46:43 +0530 Subject: [PATCH 1/2] RAXAJSS-261,262 Temp pull request --- .../org/raxa/module/raxacore/RaxaAlert.java | 355 ++++++++++++++++++ .../raxacore/RaxaAlertProviderRecipient.java | 68 ++++ .../module/raxacore/RaxaAlertService.java | 165 ++++++++ .../raxa/module/raxacore/db/RaxaAlertDAO.java | 154 ++++++++ .../db/hibernate/HibernateRaxaAlertDAO.java | 208 ++++++++++ .../raxacore/impl/PatientListServiceImpl.java | 67 +--- .../raxacore/impl/RaxaAlertServiceImpl.java | 173 +++++++++ .../main/resources/RaxacoreRaxaAlert.hbm.xml | 41 ++ api/src/main/resources/liquibase.xml | 138 ++++++- .../resources/moduleApplicationContext.xml | 34 ++ .../hibernate/HibernateRaxaAlertDAOTest.java | 264 +++++++++++++ .../resources/TestingApplicationContext.xml | 33 ++ api/src/test/resources/test-hibernate.cfg.xml | 1 + .../resources/TestingApplicationContext.xml | 33 ++ .../src/test/resources/test-hibernate.cfg.xml | 1 + pom.xml | 1 - 16 files changed, 1684 insertions(+), 52 deletions(-) create mode 100644 api/src/main/java/org/raxa/module/raxacore/RaxaAlert.java create mode 100644 api/src/main/java/org/raxa/module/raxacore/RaxaAlertProviderRecipient.java create mode 100644 api/src/main/java/org/raxa/module/raxacore/RaxaAlertService.java create mode 100644 api/src/main/java/org/raxa/module/raxacore/db/RaxaAlertDAO.java create mode 100644 api/src/main/java/org/raxa/module/raxacore/db/hibernate/HibernateRaxaAlertDAO.java create mode 100644 api/src/main/java/org/raxa/module/raxacore/impl/RaxaAlertServiceImpl.java create mode 100644 api/src/main/resources/RaxacoreRaxaAlert.hbm.xml create mode 100644 api/src/test/java/org/raxa/module/raxacore/db/hibernate/HibernateRaxaAlertDAOTest.java diff --git a/api/src/main/java/org/raxa/module/raxacore/RaxaAlert.java b/api/src/main/java/org/raxa/module/raxacore/RaxaAlert.java new file mode 100644 index 0000000000..6464719a81 --- /dev/null +++ b/api/src/main/java/org/raxa/module/raxacore/RaxaAlert.java @@ -0,0 +1,355 @@ +package org.raxa.module.raxacore; + +/** + * Copyright 2012, Raxa + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +import java.io.Serializable; +import java.util.*; +import org.openmrs.BaseOpenmrsData; +import org.openmrs.Obs; +import org.openmrs.Patient; +import org.openmrs.Provider; + +public class RaxaAlert extends BaseOpenmrsData implements Serializable { + + private Integer raxaAlertId; + + private String name; + + private String description; + + private Patient patient; + + private Integer patientId; + + private Boolean seen; + + private String alertType; + + private Date time; + + private Set obs; + + private String defaultTask; + + private Provider providerSent; + + private Integer providerSentId; + + private Provider providerRecipient; + + private Integer providerRecipientId; + + public RaxaAlert() { + } + + /** Sets id + * + * @param id: id to set + */ + @Override + public void setId(Integer id) { + setRaxaAlertId(id); + } + + /** Gets id + * + * @return the RaxaAlertId + */ + @Override + public Integer getId() { + return getRaxaAlertId(); + } + + /** Compares two RaxaAlert objects for similarity + * + * @param obj RaxaAlert object to compare to + * @return boolean true/false whether or not they are the same objects + * @see java.lang.Object#equals(java.lang.Object) + * @should equal RaxaAlert with same raxaAlertID + * @should not equal RaxaAlert with different raxaAlertID + * @should not equal on null + * @should have equal patientList objects with no raxaAlertIDs + * @should not have equal RaxaAlert objects when one has null raxaAlertID + */ + @Override + public boolean equals(Object obj) { + if (obj instanceof RaxaAlert) { + RaxaAlert pList = (RaxaAlert) obj; + if (this.getRaxaAlertId() != null && pList.getRaxaAlertId() != null) + return (this.getRaxaAlertId().equals(pList.getRaxaAlertId())); + } + return this == obj; + } + + /** + * @see java.lang.Object#hashCode() + * @should have same hashcode when equal + * @should have different hash code when not equal + * @should get hash code with null attributes + */ + @Override + public int hashCode() { + if (this.getRaxaAlertId() == null) + return super.hashCode(); + return this.getRaxaAlertId().hashCode(); + } + + /** + * @return the raxaAlertId + */ + public Integer getRaxaAlertId() { + return raxaAlertId; + } + + /** + * @param raxaAlertID the raxaAlertID to set + */ + public void setRaxaAlertId(Integer raxaAlertId) { + this.raxaAlertId = raxaAlertId; + } + + /** + * @return the patientId + */ + public Integer getPatientId() { + return patientId; + } + + /** + * @param patientId the patientId to set + */ + public void setPatientId(Integer patientId) { + this.patientId = patientId; + } + + /** + * @return the seen + */ + public Boolean seen() { + return seen; + } + + /** + * @param seen the seen to set + */ + public void setSeen(Boolean seen) { + this.seen = seen; + } + + /** + * @return the alertType + */ + public String getAlertType() { + return alertType; + } + + /** + * @param alertType the alertType to set + */ + public void setAlertType(String alertType) { + this.alertType = alertType; + } + + /** + * @return the description + */ + public String getDescription() { + return description; + } + + /** + * @param description the description to set + */ + public void setDescription(String description) { + this.description = description; + } + + /** + * @return the name + */ + public String getName() { + return name; + } + + /** + * @param alertType the name to set + */ + public void setName(String name) { + this.name = name; + } + + /** + * @return the time + */ + public Date getTime() { + return time; + } + + /** + * @param time the time to set + */ + public void setTime(Date time) { + this.time = time; + } + + /** + * @return Returns a Set of all non-voided, non-obsGroup children Obs of this Alert + * @should not return null with null obs set + * @should get obs + * @should not get voided obs + * @should only get child obs + * @should not get child obs if child also on Alert + * @should get both child and parent obs after removing child from parent grouping + * @should get obs with two levels of hierarchy + * @should get obs with three levels of hierarchy + * @should not get voided obs with three layers of hierarchy + */ + public Set getObs() { + Set ret = new HashSet(); + if (this.obs != null) { + for (Obs o : this.obs) + ret.addAll(getObsLeaves(o)); + // this should be all thats needed unless the alert has been built by hand + //if (o.isVoided() == false && o.isObsGrouping() == false) + // ret.add(o); + } + return ret; + } + + /** + * Convenience method to recursively get all leaf obs of this Alert. This method goes down + * into each obs and adds all non-grouping obs to the return list + * + * @param obsParent current obs to loop over + * @return list of leaf obs + */ + private List getObsLeaves(Obs obsParent) { + List leaves = new ArrayList(); + if (obsParent.hasGroupMembers()) { + for (Obs child : obsParent.getGroupMembers()) { + if (child.isVoided() == false) { + if (child.isObsGrouping() == false) + leaves.add(child); + else + // recurse if this is a grouping obs + leaves.addAll(getObsLeaves(child)); + } + } + } else if (obsParent.isVoided() == false) { + leaves.add(obsParent); + } + return leaves; + } + + /** + * Returns all Obs where Obs.encounterId = Encounter.encounterId In practice, this method should + * not be used very often... + * + * @param includeVoided specifies whether or not to include voided Obs + * @return Returns the all Obs. + * @should not return null with null obs set + * @should get obs + * @should get both parent and child obs + * @should get both parent and child with child directly + * @should get both child and parent obs after removing child from parent grouping + */ + public Set getAllObs(boolean includeVoided) { + if (includeVoided && obs != null) + return obs; + Set ret = new HashSet(); + if (this.obs != null) { + for (Obs o : this.obs) { + if (includeVoided) + ret.add(o); + else if (!o.isVoided()) + ret.add(o); + } + } + return ret; + } + + /** + * Returns a Set of all root-level Obs of an Alert, including obsGroups + * + * @param includeVoided specifies whether or not to include voided Obs + * @return Returns all obs at top level -- will not be null + * @should not return null with null obs set + * @should get obs + * @should not get voided obs + * @should only get parents obs + * @should only return the grouped top level obs + * @should get both child and parent obs after removing child from parent grouping + */ + public Set getObsAtTopLevel(boolean includeVoided) { + Set ret = new HashSet(); + for (Obs o : getAllObs(includeVoided)) { + if (o.getObsGroup() == null) + ret.add(o); + } + return ret; + } + + /** + * @param obs The obs to set. + */ + public void setObs(Set obs) { + this.obs = obs; + } + + /** + * @return the defaultTask + */ + public String getDefaultTask() { + return defaultTask; + } + + /** + * @param defaultTask the defaultTask to set + */ + public void setDefaultTask(String defaultTask) { + this.defaultTask = defaultTask; + } + + /** + * @return the providerSentId + */ + public Integer getProviderSentId() { + return providerSentId; + } + + /** + * @param providerSentId the providerSentId to set + */ + public void setProviderSentId(Integer providerSentId) { + this.providerSentId = providerSentId; + } + + /** + * @return the providerRecipientId + */ + public Integer getProviderRecipientId() { + return providerRecipientId; + } + + /** + * @param providerRecipientId the providerRecipientId to set + */ + public void setProviderRecipientId(Integer providerRecipientId) { + this.providerRecipientId = providerRecipientId; + } + +} diff --git a/api/src/main/java/org/raxa/module/raxacore/RaxaAlertProviderRecipient.java b/api/src/main/java/org/raxa/module/raxacore/RaxaAlertProviderRecipient.java new file mode 100644 index 0000000000..84f4bbc5a6 --- /dev/null +++ b/api/src/main/java/org/raxa/module/raxacore/RaxaAlertProviderRecipient.java @@ -0,0 +1,68 @@ +package org.raxa.module.raxacore; + +/** + * Copyright 2012, Raxa + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +import java.io.Serializable; +import org.openmrs.BaseOpenmrsData; + +public class RaxaAlertProviderRecipient extends BaseOpenmrsData implements Serializable { + + private Integer raxaAlertProviderRecipientId; + + private Integer providerRecipentId; + + public RaxaAlertProviderRecipient() { + } + + @Override + public Integer getId() { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public void setId(Integer intgr) { + throw new UnsupportedOperationException("Not supported yet."); + } + + /** + * @return the raxaAlertProviderRecipientId + */ + public Integer getRaxaAlertProviderRecipientId() { + return raxaAlertProviderRecipientId; + } + + /** + * @param raxaAlertProviderRecipientId the raxaAlertProviderRecipientId to set + */ + public void setRaxaAlertProviderRecipientId(Integer raxaAlertProviderRecipientId) { + this.raxaAlertProviderRecipientId = raxaAlertProviderRecipientId; + } + + /** + * @return the providerRecipentId + */ + public Integer getProviderRecipentId() { + return providerRecipentId; + } + + /** + * @param providerRecipentId the providerRecipentId to set + */ + public void setProviderRecipentId(Integer providerRecipentId) { + this.providerRecipentId = providerRecipentId; + } +} diff --git a/api/src/main/java/org/raxa/module/raxacore/RaxaAlertService.java b/api/src/main/java/org/raxa/module/raxacore/RaxaAlertService.java new file mode 100644 index 0000000000..33509e541f --- /dev/null +++ b/api/src/main/java/org/raxa/module/raxacore/RaxaAlertService.java @@ -0,0 +1,165 @@ +package org.raxa.module.raxacore; + +/** + * Copyright 2012, Raxa + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +import java.util.List; +import org.openmrs.annotation.Authorized; +import org.openmrs.api.OpenmrsService; +import org.raxa.module.raxacore.db.RaxaAlertDAO; +import org.springframework.transaction.annotation.Transactional; + +/* + * Interface for interacting with the RaxaAlert + */ +@Transactional +public interface RaxaAlertService extends OpenmrsService { + + /** + * Sets Raxa Alert DAO + * + * @param dao + */ + public void setRaxaAlertDAO(RaxaAlertDAO dao); + + /** + * Saves RaxaAlert + * + * @param raxaAlert + * @return RaxaAlert + */ + @Authorized( { "Add Raxa Alerts" }) + public RaxaAlert saveRaxaAlert(RaxaAlert raxaAlert); + + /** + * Gets a RaxaAlert by Id + * + * @param id + * @return RaxaAlerts + */ + @Authorized( { "View Raxa Alerts" }) + public RaxaAlert getRaxaAlert(Integer id); + + /** + * Gets a RaxaAlert by PatientId + * + * @param patientId + * @return RaxaAlerts + */ + @Authorized( { "View Raxa Alerts" }) + public List getRaxaAlertByPatientId(Integer patientId); + + /** + * Gets a RaxaAlert by ProviderSentId + * + * @param providerSentId + * @return RaxaAlerts + */ + @Authorized( { "View Raxa Alerts" }) + public List getRaxaAlertByProviderSentId(Integer providerSentId); + + /** + * Gets a RaxaAlert by ProviderRecipientId + * + * @param providerRecipientId + * @return RaxaAlerts + */ + @Authorized( { "View Raxa Alerts" }) + public List getRaxaAlertByProviderRecipientId(Integer providerRecipientId); + + /** + * Gets a RaxaAlert by PatientUuid + * + * @param patientUuid + * @return RaxaAlerts + */ + @Authorized( { "View Raxa Alerts" }) + public List getRaxaAlertsByPatientUuid(String patientUuid); + + /** + * Gets a RaxaAlert by ProviderSentUuid + * + * @param providerSentUuid + * @return RaxaAlerts + */ + @Authorized( { "View Raxa Alerts" }) + public List getRaxaAlertsByProviderSentUuid(String providerSentUuid); + + /** + * Gets a RaxaAlert by ProviderRecipientUuid + * + * @param providerRecipientUuid + * @return RaxaAlerts + */ + @Authorized( { "View Raxa Alerts" }) + public List getRaxaAlertsByProviderRecipientUuid(String providerRecipientUuid); + + /** + * Gets a RaxaAlert by Name + * + * @param name + * @return list of RaxaAlerts + */ + @Authorized( { "View Raxa Alerts" }) + public RaxaAlert getRaxaAlertsByName(String name); + + /** + * Gets RaxaAlert by uuid + * + * @param uuid + * @return RaxaAlert + */ + @Authorized( { "View Raxa Alerts" }) + public RaxaAlert getRaxaAlertByUuid(String uuid); + + /** + * Gets RaxaAlert by alertType + * + * @param uuid + * @return RaxaAlert + */ + @Authorized( { "View Raxa Alerts" }) + public List getRaxaAlertsByAlertType(String alertType); + + /** + * Gets all RaxaAlerts + * + * @return list of RaxaAlerts + */ + @Authorized( { "View Raxa Alerts" }) + public List getAllRaxaAlerts(boolean includeSeen); + + /** + * Mark RaxaAlert as seen + * + * @param seen + */ + @Authorized( { "Edit Raxa Alerts" }) + RaxaAlert markRaxaAlertAsSeen(RaxaAlert raxaAlert); + + /** + * Updates RaxaAlert + * + * @param raxaAlert + * @return RaxaAlert + */ + @Authorized( { "Edit Raxa Alerts" }) + RaxaAlert updateRaxaAlert(RaxaAlert raxaAlert); + + /** + * Deletes RaxaAlert + * + * @param raxaAlert + */ + @Authorized( { "Delete Raxa Alerts" }) + public void deleteRaxaAlert(RaxaAlert raxaAlert); +} diff --git a/api/src/main/java/org/raxa/module/raxacore/db/RaxaAlertDAO.java b/api/src/main/java/org/raxa/module/raxacore/db/RaxaAlertDAO.java new file mode 100644 index 0000000000..08636d8efa --- /dev/null +++ b/api/src/main/java/org/raxa/module/raxacore/db/RaxaAlertDAO.java @@ -0,0 +1,154 @@ +package org.raxa.module.raxacore.db; + +/** + * Copyright 2012, Raxa + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +import java.util.List; +import org.openmrs.api.db.DAOException; +import org.raxa.module.raxacore.RaxaAlert; + +/** + * Interface for accessing raxacore_raxa_alert_list + */ +public interface RaxaAlertDAO { + + /** + * Saves a RaxaAlert + * + * @param RaxaAlert to be saved + * @throws DAOException + * @should save a raxa alert list + */ + public RaxaAlert saveRaxaAlert(RaxaAlert raxaAlert) throws DAOException; + + /** + * Purge a RaxaAlert from database. + * + * @param RaxaAlert object to be purged + */ + public void deleteRaxaAlert(RaxaAlert raxaAlert) throws DAOException; + + /** + * Get raxaAlert by internal identifier + * + * @param raxaAlertID raxaAlert id + * @return raxaAlert with given internal identifier + * @throws DAOException + * @should get a raxa alert list + */ + public RaxaAlert getRaxaAlert(Integer raxaAlertID) throws DAOException; + + /** + * Find {@link RaxaAlert} matching a patientId + * + * @param patient + * @return {@link RaxaAlert} + * @should get a raxa alert list by patientId + */ + public List getRaxaAlertByPatientId(Integer patientId); + + /** + * Find {@link RaxaAlert} matching a patientUuid + * + * @param patient + * @return {@link RaxaAlert} + * @should get a raxa alert list by patientUuid + */ + public List getRaxaAlertByPatientUuid(String patientUuid); + + /** + * Find {@link RaxaAlert} matching a uuid + * + * @param uuid + * @return {@link RaxaAlert} + * @should get a raxa alert list by uuid + */ + public RaxaAlert getRaxaAlertByUuid(String uuid); + + /** + * Find {@link RaxaAlert} matching a name + * + * @param name + * @return {@link RaxaAlert} + * @should get a raxa alert list by name + */ + public RaxaAlert getRaxaAlertByName(String name); + + /** + * Find {@link RaxaAlert} matching a alertType + * + * @param alertType + * @return {@link RaxaAlert} + * @should get a raxa alert list by alertType + */ + public List getRaxaAlertByAlertType(String alertType); + + /** + * Find {@link RaxaAlert} matching providerSentId + * + * @param providerSent + * @return List of RaxaAlerts + * @should get a raxa alert list by providerSentId + */ + public List getRaxaAlertByProviderSentId(Integer providerSentId); + + /** + * Find {@link RaxaAlert} matching a providerSentUuid + * + * @param providerSent + * @return {@link RaxaAlert} + * @should get a raxa alert list by providerSentUuid + */ + public List getRaxaAlertByProviderSentUuid(String providerSentUuid); + + /** + * Find {@link RaxaAlert} matching providerRecipientId + * + * @param providerRecipient + * @return List of RaxaAlerts + * @should get a raxa alert list by providerRecipientId + */ + public List getRaxaAlertByProviderRecipientId(Integer providerRecipientId); + + /** + * Find {@link RaxaAlert} matching a providerRecipientUuid + * + * @param providerRecipient + * @return {@link RaxaAlert} + * @should get a raxa alert list by providerRecipientUuid + */ + public List getRaxaAlertByProviderRecipientUuid(String providerRecipientUuid); + + /** + * Update RaxaAlert + * @return {@link RaxaAlert} + * @should update a RaxaAlert + */ + RaxaAlert updateRaxaAlert(RaxaAlert raxaAlert) throws DAOException; + + /** + *Get all RaxaAlert + *@param includeSeen + *@return List of RaxaAlerts + */ + public List getAllRaxaAlerts(boolean includeSeen) throws DAOException; + + /** + *Mark RaxaLert as seen + *@param Seen + */ + RaxaAlert markRaxaAlertAsSeen(RaxaAlert raxaAlert); + +} diff --git a/api/src/main/java/org/raxa/module/raxacore/db/hibernate/HibernateRaxaAlertDAO.java b/api/src/main/java/org/raxa/module/raxacore/db/hibernate/HibernateRaxaAlertDAO.java new file mode 100644 index 0000000000..5b5f550cfc --- /dev/null +++ b/api/src/main/java/org/raxa/module/raxacore/db/hibernate/HibernateRaxaAlertDAO.java @@ -0,0 +1,208 @@ +package org.raxa.module.raxacore.db.hibernate; + +/** + * Copyright 2012, Raxa + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ + +import java.util.ArrayList; +import java.util.List; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.Criteria; +import org.hibernate.SessionFactory; +import org.hibernate.criterion.Restrictions; +import org.openmrs.api.db.DAOException; +import org.raxa.module.raxacore.RaxaAlert; +import org.raxa.module.raxacore.RaxaAlertProviderRecipient; +import org.raxa.module.raxacore.db.RaxaAlertDAO; + +/** + * Accesses raxacore_patient_list from RaxaAlert + */ +public class HibernateRaxaAlertDAO implements RaxaAlertDAO { + + protected final Log log = LogFactory.getLog(getClass()); + + /** + * Hibernate session factory + */ + private SessionFactory sessionFactory; + + /** + * Set session factory + * + * @param sessionFactory1 + */ + public void setSessionFactory(SessionFactory sessionFactory) { + this.sessionFactory = sessionFactory; + } + + /** + * @see org.raxa.module.db.RaxaAlertDAO#saveRaxaAlert(org.raxa.module.raxacore.RaxaAlert) + */ + @Override + public RaxaAlert saveRaxaAlert(RaxaAlert raxaAlert) throws DAOException { + sessionFactory.getCurrentSession().saveOrUpdate(raxaAlert); + return raxaAlert; + } + + /** + * @see org.raxa.module.db.RaxaAlertDAO#deleteRaxaAlert(org.raxa.module.raxacore.RaxaAlert) + */ + @Override + public void deleteRaxaAlert(RaxaAlert raxaAlert) throws DAOException { + sessionFactory.getCurrentSession().delete(raxaAlert); + } + + /** + * @see org.raxa.module.db.RaxaAlertDAO#getRaxaAlert(Integer) + */ + @Override + public RaxaAlert getRaxaAlert(Integer raxaAlertId) throws DAOException { + return (RaxaAlert) sessionFactory.getCurrentSession().get(RaxaAlert.class, raxaAlertId); + } + + /** + * @see org.raxa.module.db.RaxaAlertDAO#getRaxaAlertByUuid(String) + */ + @Override + public RaxaAlert getRaxaAlertByUuid(String uuid) throws DAOException { + Criteria criteria = sessionFactory.getCurrentSession().createCriteria(RaxaAlert.class); + criteria.add(Restrictions.eq("uuid", uuid)); + return (RaxaAlert) criteria.uniqueResult(); + } + + /** + * @see org.raxa.module.db.RaxaAlertDAO#getRaxaAlertByName(String) + */ + @Override + public RaxaAlert getRaxaAlertByName(String name) throws DAOException { + Criteria criteria = sessionFactory.getCurrentSession().createCriteria(RaxaAlert.class); + criteria.add(Restrictions.eq("name", name)); + return (RaxaAlert) criteria.uniqueResult(); + } + + /** + * @see org.raxa.module.db.RaxaAlertDAO#getRaxaAlertByAlertType(String) + */ + @Override + public List getRaxaAlertByAlertType(String alertType) throws DAOException { + Criteria criteria = sessionFactory.getCurrentSession().createCriteria(RaxaAlert.class); + criteria.add(Restrictions.like("alertType", alertType)); + List alerts = new ArrayList(); + alerts.addAll(criteria.list()); + return alerts; + } + + /** + * @see org.raxa.module.db.RaxaAlertDAO#getRaxaAlertByPatientId(Integer) + */ + @Override + public List getRaxaAlertByPatientId(Integer patientId) throws DAOException { + Criteria criteria = sessionFactory.getCurrentSession().createCriteria(RaxaAlert.class); + criteria.add(Restrictions.eq("patientId", patientId)); + List alerts = new ArrayList(); + alerts.addAll(criteria.list()); + return alerts; + } + + /** + * @see org.raxa.module.db.RaxaAlertDAO#getRaxaAlertByPatientUuid(String) + */ + @Override + public List getRaxaAlertByPatientUuid(String patientUuid) throws DAOException { + Criteria criteria = sessionFactory.getCurrentSession().createCriteria(RaxaAlert.class); + criteria.add(Restrictions.eq("patientUuid", patientUuid)); + List alerts = new ArrayList(); + alerts.addAll(criteria.list()); + return alerts; + } + + /** + * @see org.raxa.module.db.RaxaAlertDAO#getRaxaAlertByProviderSentId(Integer) + */ + @Override + public List getRaxaAlertByProviderSentId(Integer providerSentId) throws DAOException { + Criteria criteria = sessionFactory.getCurrentSession().createCriteria(RaxaAlert.class); + criteria.add(Restrictions.eq("providerSentId", providerSentId)); + List alerts = new ArrayList(); + alerts.addAll(criteria.list()); + return alerts; + } + + /** + * @see org.raxa.module.db.RaxaAlertDAO#getRaxaAlertByProviderSentUuid(String) + */ + @Override + public List getRaxaAlertByProviderSentUuid(String providerSentUuid) throws DAOException { + Criteria criteria = sessionFactory.getCurrentSession().createCriteria(RaxaAlert.class); + criteria.add(Restrictions.eq("providerSentUuid", providerSentUuid)); + List alerts = new ArrayList(); + alerts.addAll(criteria.list()); + return alerts; + } + + /** + * @see org.raxa.module.db.RaxaAlertDAO#getRaxaAlertByProviderRecipientId(Integer) + */ + @Override + public List getRaxaAlertByProviderRecipientId(Integer providerRecipientId) throws DAOException { + Criteria criteria = sessionFactory.getCurrentSession().createCriteria(RaxaAlertProviderRecipient.class); + criteria.add(Restrictions.eq("providerRecipientId", providerRecipientId)); + List alerts = new ArrayList(); + alerts.addAll(criteria.list()); + return alerts; + } + + /** + * @see org.raxa.module.db.RaxaAlertDAO#getRaxaAlertByProviderRecipientUuid(String) + */ + @Override + public List getRaxaAlertByProviderRecipientUuid(String providerRecipientUuid) throws DAOException { + Criteria criteria = sessionFactory.getCurrentSession().createCriteria(RaxaAlert.class); + criteria.add(Restrictions.eq("providerRecipientUuid", providerRecipientUuid)); + List alerts = new ArrayList(); + alerts.addAll(criteria.list()); + return alerts; + } + + /** + * @see org.raxa.module.db.RaxaAlertDAO#getAllRaxaAlert() + */ + @Override + public List getAllRaxaAlerts(boolean includeSeen) throws DAOException { + Criteria criteria = sessionFactory.getCurrentSession().createCriteria(RaxaAlert.class); + if (includeSeen == false) { + criteria.add(Restrictions.eq("seen", false)); + } + return criteria.list(); + } + + /** + * @see org.raxa.module.db.RaxaAlertDAO#updateRaxaAlert(Integer) + */ + @Override + public RaxaAlert updateRaxaAlert(RaxaAlert raxaAlert) throws DAOException { + sessionFactory.getCurrentSession().update(raxaAlert); + return raxaAlert; + } + + /** + * @see org.raxa.module.db.RaxaAlertDAO#markRaxaAlertAsSeen(boolean) + */ + @Override + public RaxaAlert markRaxaAlertAsSeen(RaxaAlert raxaAlert) { + raxaAlert.setSeen(true); + return raxaAlert; + } + +} diff --git a/api/src/main/java/org/raxa/module/raxacore/impl/PatientListServiceImpl.java b/api/src/main/java/org/raxa/module/raxacore/impl/PatientListServiceImpl.java index 9829d9f7e5..e1349d03f2 100644 --- a/api/src/main/java/org/raxa/module/raxacore/impl/PatientListServiceImpl.java +++ b/api/src/main/java/org/raxa/module/raxacore/impl/PatientListServiceImpl.java @@ -3,17 +3,14 @@ /** * Copyright 2012, Raxa * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. */ import java.text.SimpleDateFormat; import java.util.ArrayList; @@ -24,9 +21,6 @@ import org.apache.commons.logging.LogFactory; import org.openmrs.Encounter; import org.openmrs.EncounterType; -import org.openmrs.User; -import org.openmrs.Provider; -import org.openmrs.Person; import org.openmrs.Patient; import org.openmrs.api.context.Context; import org.raxa.module.raxacore.PatientList; @@ -34,8 +28,8 @@ import org.raxa.module.raxacore.db.PatientListDAO; /* - * Implements PatientListService.java Note the PatientList query must be in the - * form of: + * Implements PatientListService.java + * Note the PatientList query must be in the form of: * "?encounterType=&startDate=2012-05-07&endDate=2012-05-08&inlist=¬inlist=" */ public class PatientListServiceImpl implements PatientListService { @@ -69,8 +63,7 @@ public PatientList getPatientList(Integer id) { } /** - * @see - * org.raxa.module.raxacore.PatientListService#getPatientListByName(String) + * @see org.raxa.module.raxacore.PatientListService#getPatientListByName(String) */ @Override public List getPatientListByName(String name) { @@ -78,8 +71,7 @@ public List getPatientListByName(String name) { } /** - * @see - * org.raxa.module.raxacore.PatientListService#getPatientListByUuid(String) + * @see org.raxa.module.raxacore.PatientListService#getPatientListByUuid(String) */ @Override public PatientList getPatientListByUuid(String uuid) { @@ -87,8 +79,7 @@ public PatientList getPatientListByUuid(String uuid) { } /** - * @see - * org.raxa.module.raxacore.PatientListService#getPatientListByEncounterType + * @see org.raxa.module.raxacore.PatientListService#getPatientListByEncounterType */ @Override public List getPatientListByEncounterType(EncounterType encounterType) { @@ -127,8 +118,7 @@ private Date getDateFromString(String str) { } /** - * @see - * org.raxa.module.raxacore.PatientListService#getEncountersInPatientList + * @see org.raxa.module.raxacore.PatientListService#getEncountersInPatientList */ @Override public List getEncountersInPatientList(PatientList patientList) { @@ -143,12 +133,10 @@ public List getEncountersInPatientList(PatientList patientList) { EncounterType encType = null; Date startDate = null; Date endDate = null; - Provider provid = null; - String uuid = null; //the return value can only choose encounters from this list (if not null) List inListEncounters = null; - //the return value can not contain any patients from this list - List notInListPatients = new ArrayList(); + //the return value can not contain any encounters from this list + List notInListEncounters = new ArrayList(); String[] queryFields = query.split("&"); //if we have an encountertype in our search query, set it for (int i = 0; i < queryFields.length; i++) { @@ -168,25 +156,16 @@ public List getEncountersInPatientList(PatientList patientList) { } else if (queryFields[i].indexOf("notInList=") != -1) { String[] notInListUuids = queryFields[i].substring(10).split(","); for (int k = 0; k < notInListUuids.length; k++) { - notInListPatients.addAll(getPatientsInPatientList(getPatientListByUuid(notInListUuids[k]))); + notInListEncounters.addAll(getEncountersInPatientList(getPatientListByUuid(notInListUuids[k]))); } - } else if (queryFields[i].indexOf("provider=") != -1) { - uuid = queryFields[i].substring(9); - provid = Context.getProviderService().getProviderByUuid(uuid); } } + List encTypes = new ArrayList(); - List provids = new ArrayList(); - List encs = new ArrayList(); encTypes.add(encType); - provids.add(provid); - if (uuid != null) { - encs = Context.getEncounterService().getEncounters(null, null, startDate, endDate, null, encTypes, provids, - null, null, Boolean.FALSE); - } else { - encs = Context.getEncounterService().getEncounters(null, null, startDate, endDate, null, encTypes, null, null, - null, Boolean.FALSE); - } + List encs = Context.getEncounterService().getEncounters(null, null, startDate, endDate, null, encTypes, + null, Boolean.FALSE); + encs.removeAll(notInListEncounters); if (inListEncounters != null) { Iterator iter = encs.iterator(); //if encounter is not in inListEncounters, remove it @@ -197,16 +176,6 @@ public List getEncountersInPatientList(PatientList patientList) { } } } - if (notInListPatients != null) { - Iterator iter = encs.iterator(); - //if patient is in notInListPatients, remove the encounter - while (iter.hasNext()) { - Encounter currEnc = iter.next(); - if (notInListPatients.contains(currEnc.getPatient())) { - iter.remove(); - } - } - } return encs; } diff --git a/api/src/main/java/org/raxa/module/raxacore/impl/RaxaAlertServiceImpl.java b/api/src/main/java/org/raxa/module/raxacore/impl/RaxaAlertServiceImpl.java new file mode 100644 index 0000000000..cda013287b --- /dev/null +++ b/api/src/main/java/org/raxa/module/raxacore/impl/RaxaAlertServiceImpl.java @@ -0,0 +1,173 @@ +package org.raxa.module.raxacore.impl; + +/** + * Copyright 2012, Raxa + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.Iterator; +import java.util.List; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.raxa.module.raxacore.RaxaAlert; +import org.raxa.module.raxacore.RaxaAlertService; +import org.raxa.module.raxacore.db.RaxaAlertDAO; + +/* + * Implements RaxaAlertService.java + */ +public class RaxaAlertServiceImpl implements RaxaAlertService { + + private RaxaAlertDAO dao; + + private Log log = LogFactory.getLog(this.getClass()); + + /** + * @see org.raxa.module.raxacore.RaxaAlertService#setRaxaAlertDAO + */ + @Override + public void setRaxaAlertDAO(RaxaAlertDAO dao) { + this.dao = dao; + } + + /** + * @see org.raxa.module.raxacore.RaxaAlertService#saveRaxaAlert + */ + @Override + public RaxaAlert saveRaxaAlert(RaxaAlert raxaAlert) { + return dao.saveRaxaAlert(raxaAlert); + } + + /** + * @see org.raxa.module.raxacore.RaxaAlertService#getRaxaAlert(Integer) + */ + @Override + public RaxaAlert getRaxaAlert(Integer id) { + return dao.getRaxaAlert(id); + } + + /** + * @see org.raxa.module.raxacore.RaxaAlertService#getRaxaAlertByName(String) + */ + @Override + public RaxaAlert getRaxaAlertsByName(String name) { + return dao.getRaxaAlertByName(name); + } + + /** + * @see org.raxa.module.raxacore.RaxaAlertService#getRaxaAlertByAlertType(String) + */ + @Override + public List getRaxaAlertsByAlertType(String alertType) { + return (List) dao.getRaxaAlertByAlertType(alertType); + } + + /** + * @see org.raxa.module.raxacore.RaxaAlertService#getRaxaAlertByUuid(String) + */ + @Override + public RaxaAlert getRaxaAlertByUuid(String uuid) { + return dao.getRaxaAlertByUuid(uuid); + } + + /** + * @see org.raxa.module.raxacore.RaxaAlertService#getRaxaAlertByPatientId(Integer) + */ + @Override + public List getRaxaAlertByPatientId(Integer patientId) { + return dao.getRaxaAlertByPatientId(patientId); + } + + /** + * @see org.raxa.module.raxacore.RaxaAlertService#getRaxaAlertByPatientUuid(String) + */ + @Override + public List getRaxaAlertsByPatientUuid(String patientUuid) { + return dao.getRaxaAlertByPatientUuid(patientUuid); + } + + /** + * @see org.raxa.module.raxacore.RaxaAlertService#getRaxaAlertByProviderRecipientId(Integer) + */ + @Override + public List getRaxaAlertByProviderRecipientId(Integer providerRecipientId) { + return dao.getRaxaAlertByProviderRecipientId(providerRecipientId); + } + + /** + * @see org.raxa.module.raxacore.RaxaAlertService#getRaxaAlertByProviderRecipientUuid(String) + */ + @Override + public List getRaxaAlertsByProviderRecipientUuid(String providerRecipientUuid) { + return dao.getRaxaAlertByProviderRecipientUuid(providerRecipientUuid); + } + + /** + * @see org.raxa.module.raxacore.RaxaAlertService#getRaxaAlertByProviderSentId(Integer) + */ + @Override + public List getRaxaAlertByProviderSentId(Integer providerSentId) { + return dao.getRaxaAlertByProviderSentId(providerSentId); + } + + /** + * @see org.raxa.module.raxacore.RaxaAlertService#getRaxaAlertByProviderSentUuid(String) + */ + @Override + public List getRaxaAlertsByProviderSentUuid(String providerSentUuid) { + return dao.getRaxaAlertByProviderSentUuid(providerSentUuid); + } + + /** + * @see org.raxa.module.raxacore.RaxaAlertService#getAllRaxaAlert + */ + @Override + public List getAllRaxaAlerts(boolean includeSeen) { + return dao.getAllRaxaAlerts(includeSeen); + } + + /** + * @see org.raxa.module.raxacore.RaxaAlertService#markRaxaAlertAsSeen + */ + @Override + public RaxaAlert markRaxaAlertAsSeen(RaxaAlert raxaAlert) { + return dao.markRaxaAlertAsSeen(raxaAlert); + } + + /** + * @see org.raxa.module.raxacore.RaxaAlertService#updateRaxaAlert + */ + @Override + public RaxaAlert updateRaxaAlert(RaxaAlert raxaAlert) { + return dao.updateRaxaAlert(raxaAlert); + } + + /** + * @see org.raxa.module.raxacore.RaxaAlertService#deleteRaxaAlert + */ + @Override + public void deleteRaxaAlert(RaxaAlert raxaAlert) { + dao.deleteRaxaAlert(raxaAlert); + } + + @Override + public void onStartup() { + log.info("Starting raxa alert service"); + } + + @Override + public void onShutdown() { + log.info("Stopping raxa alert service"); + } + +} diff --git a/api/src/main/resources/RaxacoreRaxaAlert.hbm.xml b/api/src/main/resources/RaxacoreRaxaAlert.hbm.xml new file mode 100644 index 0000000000..c7e9b0652c --- /dev/null +++ b/api/src/main/resources/RaxacoreRaxaAlert.hbm.xml @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/api/src/main/resources/liquibase.xml b/api/src/main/resources/liquibase.xml index 7ec6a51668..e553b28111 100644 --- a/api/src/main/resources/liquibase.xml +++ b/api/src/main/resources/liquibase.xml @@ -5,7 +5,7 @@ xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog/1.9 http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-1.9.xsd"> - + @@ -21,7 +21,6 @@ - @@ -41,6 +40,7 @@ + @@ -66,4 +66,138 @@ referencedColumnNames="user_id"/> + + + + + + + + Schema for raxacore_raxaalert table + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Adding constraints for auditing Raxaalert--making sure + anyone who creates/voids a Raxaalert table is a user + + + + + + + + + + + + + + + Schema for raxacore_raxalaert_providerrecipient table + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Adding constraints for auditing Raxaalertproviderrecipient--making sure + anyone who creates/voids a Raxaalertproviderrecipient table is a user + + + + + \ No newline at end of file diff --git a/api/src/main/resources/moduleApplicationContext.xml b/api/src/main/resources/moduleApplicationContext.xml index b6c463abe6..1115394ab4 100644 --- a/api/src/main/resources/moduleApplicationContext.xml +++ b/api/src/main/resources/moduleApplicationContext.xml @@ -54,4 +54,38 @@ + + + + + + + + + org.raxa.module.raxacore.RaxaAlertService + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/api/src/test/java/org/raxa/module/raxacore/db/hibernate/HibernateRaxaAlertDAOTest.java b/api/src/test/java/org/raxa/module/raxacore/db/hibernate/HibernateRaxaAlertDAOTest.java new file mode 100644 index 0000000000..d8bc703e7c --- /dev/null +++ b/api/src/test/java/org/raxa/module/raxacore/db/hibernate/HibernateRaxaAlertDAOTest.java @@ -0,0 +1,264 @@ +package org.raxa.module.raxacore.db.hibernate; + +/** + * Copyright 2012, Raxa + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +import java.util.List; +import static org.junit.Assert.*; +import org.junit.Before; +import org.junit.Test; +import org.openmrs.api.context.Context; +import org.openmrs.test.BaseModuleContextSensitiveTest; +import org.raxa.module.raxacore.RaxaAlert; +import org.raxa.module.raxacore.db.RaxaAlertDAO; + +/** + * @author Tarang Mahajan + */ + +public class HibernateRaxaAlertDAOTest extends BaseModuleContextSensitiveTest { + + private static final String TEST_DATA_PATH = "org/raxa/module/raxacore/include/"; + + private static final String MODULE_TEST_DATA_XML = TEST_DATA_PATH + "moduleTestData.xml"; + + private RaxaAlertDAO dao = null; + + @Before + public void setUp() throws Exception { + executeDataSet(MODULE_TEST_DATA_XML); + dao = (HibernateRaxaAlertDAO) applicationContext + .getBean("org.raxa.module.raxacore.db.hibernate.HibernateRaxaAlertDAO"); + } + + /** + * Test of saveRaxaAlert method, of class HibernateRaxaAlertDAO. + */ + @Test + public void testSaveRaxaAlert() { + RaxaAlert rAlert = new RaxaAlert(); + //NOTE: never set Id, will be generated automatically (when saving) + rAlert.setName("TestList3"); + rAlert.setDescription("Third Test List"); + rAlert.setCreator(Context.getUserContext().getAuthenticatedUser()); + rAlert.setDateCreated(new java.util.Date()); + rAlert.setUuid("68547121-1b70-465c-99ee-c9dfd95e7d30"); + rAlert.setVoided(Boolean.FALSE); + rAlert.setProviderSentId(1); + rAlert.setProviderRecipientId(2); + dao.saveRaxaAlert(rAlert); + RaxaAlert result = dao.getRaxaAlertByName("TestList3"); + String name = result.getName(); + assertEquals(name, "TestList4"); + } + + /** + * Test of deleteRaxaAlert method, of class HibernateRaxaAlertDAO. + */ + @Test + public void testDeleteRaxaAlert() { + RaxaAlert rAlert = new RaxaAlert(); + rAlert.setName("TestList2"); + rAlert.setId(2); + rAlert.setDescription("Second Test List"); + rAlert.setCreator(Context.getUserContext().getAuthenticatedUser()); + rAlert.setDateCreated(new java.util.Date()); + rAlert.setUuid("68547121-1b70-465c-99ee-c9dfd95e7d30"); + rAlert.setVoided(Boolean.FALSE); + rAlert.setProviderSentId(1); + rAlert.setProviderRecipientId(2); + dao.deleteRaxaAlert(rAlert); + RaxaAlert result = dao.getRaxaAlert(2); + assertEquals(null, result); + } + + /** + * Test of getRaxaAlert method, of class HibernateRaxaAlertDAO. + */ + @Test + public void testGetRaxaAlert() { + Integer raxaAlertId = 1; + RaxaAlert result = dao.getRaxaAlert(raxaAlertId); + String name = result.getName(); + assertEquals("TestList1", name); + } + + /** + * Test of getRaxaAlertByUuid method, of class HibernateRaxaAlertDAO. + */ + @Test + public void testGetRaxaAlertByUuid() { + String uuid = "68547121-1b70-465e-99ee-c9dfd95e7d30"; + String result = dao.getRaxaAlertByUuid(uuid).getName(); + assertEquals("TestList2", result); + } + + /** + * Test of getRaxaAlertByName method, of class HibernateRaxaAlertDAO. + */ + @Test + public void testGetRaxaAlertByName() { + String name = "TestList1"; + String result = dao.getRaxaAlertByName(name).getName(); + assertEquals(name, result); + } + + /** + * Test of getRaxaAlertByAlertType method, of class HibernateRaxaAlertDAO. + */ + @Test + public void testGetRaxaAlertByAlertType() { + System.out.println("getRaxaAlertByAlertType"); + String alertType = ""; + HibernateRaxaAlertDAO instance = new HibernateRaxaAlertDAO(); + List expResult = null; + List result = instance.getRaxaAlertByAlertType(alertType); + assertEquals(expResult, result); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); + } + + /** + * Test of getRaxaAlertByPatientId method, of class HibernateRaxaAlertDAO. + */ + @Test + public void testGetRaxaAlertByPatientId() { + System.out.println("getRaxaAlertByPatientId"); + Integer patientId = null; + HibernateRaxaAlertDAO instance = new HibernateRaxaAlertDAO(); + List expResult = null; + List result = instance.getRaxaAlertByPatientId(patientId); + assertEquals(expResult, result); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); + } + + /** + * Test of getRaxaAlertByPatientUuid method, of class HibernateRaxaAlertDAO. + */ + @Test + public void testGetRaxaAlertByPatientUuid() { + System.out.println("getRaxaAlertByPatientUuid"); + String patientUuid = ""; + HibernateRaxaAlertDAO instance = new HibernateRaxaAlertDAO(); + List expResult = null; + List result = instance.getRaxaAlertByPatientUuid(patientUuid); + assertEquals(expResult, result); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); + } + + /** + * Test of getRaxaAlertByProviderSentId method, of class HibernateRaxaAlertDAO. + */ + @Test + public void testGetRaxaAlertByProviderSentId() { + System.out.println("getRaxaAlertByProviderSentId"); + Integer providerSentId = null; + HibernateRaxaAlertDAO instance = new HibernateRaxaAlertDAO(); + List expResult = null; + List result = instance.getRaxaAlertByProviderSentId(providerSentId); + assertEquals(expResult, result); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); + } + + /** + * Test of getRaxaAlertByProviderSentUuid method, of class HibernateRaxaAlertDAO. + */ + @Test + public void testGetRaxaAlertByProviderSentUuid() { + System.out.println("getRaxaAlertByProviderSentUuid"); + String providerSentUuid = ""; + HibernateRaxaAlertDAO instance = new HibernateRaxaAlertDAO(); + List expResult = null; + List result = instance.getRaxaAlertByProviderSentUuid(providerSentUuid); + assertEquals(expResult, result); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); + } + + /** + * Test of getRaxaAlertByProviderRecipientId method, of class HibernateRaxaAlertDAO. + */ + @Test + public void testGetRaxaAlertByProviderRecipientId() { + System.out.println("getRaxaAlertByProviderRecipientId"); + Integer providerRecipientId = null; + HibernateRaxaAlertDAO instance = new HibernateRaxaAlertDAO(); + List expResult = null; + List result = instance.getRaxaAlertByProviderRecipientId(providerRecipientId); + assertEquals(expResult, result); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); + } + + /** + * Test of getRaxaAlertByProviderRecipientUuid method, of class HibernateRaxaAlertDAO. + */ + @Test + public void testGetRaxaAlertByProviderRecipientUuid() { + System.out.println("getRaxaAlertByProviderRecipientUuid"); + String providerRecipientUuid = ""; + HibernateRaxaAlertDAO instance = new HibernateRaxaAlertDAO(); + List expResult = null; + List result = instance.getRaxaAlertByProviderRecipientUuid(providerRecipientUuid); + assertEquals(expResult, result); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); + } + + /** + * Test of getAllRaxaAlerts method, of class HibernateRaxaAlertDAO. + */ + @Test + public void testGetAllPatientList_shouldReturnAllRaxaAlertsIncludingVoided() { + List allRaxaAlert = dao.getAllRaxaAlerts(true); + assertEquals(allRaxaAlert.size(), 3); + } + + /** + * Test of getAllRaxaAlerts method, of class HibernateRaxaAlertDAO. + */ + @Test + public void testGetAllPatientList_shouldReturnAllUnvoidedRaxaAlerts() { + List allRaxaAlert = dao.getAllRaxaAlerts(false); + assertEquals(allRaxaAlert.size(), 3); + } + + /** + * Test of updateRaxaAlert method, of class HibernateRaxaAlertDAO. + */ + @Test + public void testUpdateRaxaAlert() { + RaxaAlert raxaAlert = dao.getRaxaAlert(1); + raxaAlert.setName("NewNameList"); + dao.updateRaxaAlert(raxaAlert); + String name = dao.getRaxaAlert(1).getName(); + assertEquals(name, "NewNameList"); + } + + /** + * Test of markRaxaAlertAsSeen method, of class HibernateRaxaAlertDAO. + */ + @Test + public void testMarkRaxaAlertAsSeen() { + RaxaAlert raxaAlert = dao.getRaxaAlert(1); + dao.markRaxaAlertAsSeen(raxaAlert); + Boolean seen = dao.getRaxaAlert(1).seen(); + assertEquals(seen, "TRUE"); + } +} diff --git a/api/src/test/resources/TestingApplicationContext.xml b/api/src/test/resources/TestingApplicationContext.xml index b6c463abe6..c01a2d1103 100644 --- a/api/src/test/resources/TestingApplicationContext.xml +++ b/api/src/test/resources/TestingApplicationContext.xml @@ -54,4 +54,37 @@ + + + + + + + + org.raxa.module.raxacore.RaxaAlertService + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/api/src/test/resources/test-hibernate.cfg.xml b/api/src/test/resources/test-hibernate.cfg.xml index 7e3552d6b9..3bf57401f0 100644 --- a/api/src/test/resources/test-hibernate.cfg.xml +++ b/api/src/test/resources/test-hibernate.cfg.xml @@ -6,5 +6,6 @@ + \ No newline at end of file diff --git a/omod/src/test/resources/TestingApplicationContext.xml b/omod/src/test/resources/TestingApplicationContext.xml index b6c463abe6..4e81de0781 100644 --- a/omod/src/test/resources/TestingApplicationContext.xml +++ b/omod/src/test/resources/TestingApplicationContext.xml @@ -54,4 +54,37 @@ + + + + + + + + org.raxa.module.raxacore.RaxaAlertService + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/omod/src/test/resources/test-hibernate.cfg.xml b/omod/src/test/resources/test-hibernate.cfg.xml index 7e3552d6b9..abd2297608 100644 --- a/omod/src/test/resources/test-hibernate.cfg.xml +++ b/omod/src/test/resources/test-hibernate.cfg.xml @@ -6,5 +6,6 @@ + \ No newline at end of file diff --git a/pom.xml b/pom.xml index 43311de146..b173b56ec0 100644 --- a/pom.xml +++ b/pom.xml @@ -30,7 +30,6 @@ - api omod From 809edfedf1338ae433d46ee723a8cc723af03d71 Mon Sep 17 00:00:00 2001 From: Tarang Date: Wed, 25 Jul 2012 15:28:09 +0530 Subject: [PATCH 2/2] RAXAJSS-261, RAXAJSS-261 RaxaAlert tables, Hibernate CRUD, Service Layers, DAO helper methods and respective tests created. --- .../org/raxa/module/raxacore/RaxaAlert.java | 46 +++++++- .../module/raxacore/RaxaAlertService.java | 29 +---- .../raxa/module/raxacore/db/RaxaAlertDAO.java | 27 ----- .../db/hibernate/HibernateRaxaAlertDAO.java | 41 +------ .../raxacore/impl/RaxaAlertServiceImpl.java | 26 +---- .../main/resources/RaxacoreRaxaAlert.hbm.xml | 23 ++-- api/src/main/resources/liquibase.xml | 5 +- .../resources/moduleApplicationContext.xml | 2 +- .../hibernate/HibernateRaxaAlertDAOTest.java | 105 ++++-------------- .../impl/PatientListServiceImplTest.java | 102 +++++------------ .../raxacore/include/moduleTestData.xml | 1 + api/src/test/resources/test-hibernate.cfg.xml | 2 +- 12 files changed, 110 insertions(+), 299 deletions(-) diff --git a/api/src/main/java/org/raxa/module/raxacore/RaxaAlert.java b/api/src/main/java/org/raxa/module/raxacore/RaxaAlert.java index 6464719a81..6d27a7feb9 100644 --- a/api/src/main/java/org/raxa/module/raxacore/RaxaAlert.java +++ b/api/src/main/java/org/raxa/module/raxacore/RaxaAlert.java @@ -82,7 +82,7 @@ public Integer getId() { * @should equal RaxaAlert with same raxaAlertID * @should not equal RaxaAlert with different raxaAlertID * @should not equal on null - * @should have equal patientList objects with no raxaAlertIDs + * @should have equal raxaList objects with no raxaAlertIDs * @should not have equal RaxaAlert objects when one has null raxaAlertID */ @Override @@ -139,7 +139,7 @@ public void setPatientId(Integer patientId) { /** * @return the seen */ - public Boolean seen() { + public Boolean getSeen() { return seen; } @@ -352,4 +352,46 @@ public void setProviderRecipientId(Integer providerRecipientId) { this.providerRecipientId = providerRecipientId; } + /** + * @return the patient + */ + public Patient getPatient() { + return patient; + } + + /** + * @param patient the patient to set + */ + public void setPatient(Patient patient) { + this.patient = patient; + } + + /** + * @return the providerSent + */ + public Provider getProviderSent() { + return providerSent; + } + + /** + * @param providerSent the providerSent to set + */ + public void setProviderSent(Provider providerSent) { + this.providerSent = providerSent; + } + + /** + * @return the providerRecipient + */ + public Provider getProviderRecipient() { + return providerRecipient; + } + + /** + * @param providerRecipient the providerRecipient to set + */ + public void setProviderRecipient(Provider providerRecipient) { + this.providerRecipient = providerRecipient; + } + } diff --git a/api/src/main/java/org/raxa/module/raxacore/RaxaAlertService.java b/api/src/main/java/org/raxa/module/raxacore/RaxaAlertService.java index 33509e541f..7b313a6501 100644 --- a/api/src/main/java/org/raxa/module/raxacore/RaxaAlertService.java +++ b/api/src/main/java/org/raxa/module/raxacore/RaxaAlertService.java @@ -76,33 +76,6 @@ public interface RaxaAlertService extends OpenmrsService { @Authorized( { "View Raxa Alerts" }) public List getRaxaAlertByProviderRecipientId(Integer providerRecipientId); - /** - * Gets a RaxaAlert by PatientUuid - * - * @param patientUuid - * @return RaxaAlerts - */ - @Authorized( { "View Raxa Alerts" }) - public List getRaxaAlertsByPatientUuid(String patientUuid); - - /** - * Gets a RaxaAlert by ProviderSentUuid - * - * @param providerSentUuid - * @return RaxaAlerts - */ - @Authorized( { "View Raxa Alerts" }) - public List getRaxaAlertsByProviderSentUuid(String providerSentUuid); - - /** - * Gets a RaxaAlert by ProviderRecipientUuid - * - * @param providerRecipientUuid - * @return RaxaAlerts - */ - @Authorized( { "View Raxa Alerts" }) - public List getRaxaAlertsByProviderRecipientUuid(String providerRecipientUuid); - /** * Gets a RaxaAlert by Name * @@ -128,7 +101,7 @@ public interface RaxaAlertService extends OpenmrsService { * @return RaxaAlert */ @Authorized( { "View Raxa Alerts" }) - public List getRaxaAlertsByAlertType(String alertType); + public List getRaxaAlertByAlertType(String alertType); /** * Gets all RaxaAlerts diff --git a/api/src/main/java/org/raxa/module/raxacore/db/RaxaAlertDAO.java b/api/src/main/java/org/raxa/module/raxacore/db/RaxaAlertDAO.java index 08636d8efa..d412d0a701 100644 --- a/api/src/main/java/org/raxa/module/raxacore/db/RaxaAlertDAO.java +++ b/api/src/main/java/org/raxa/module/raxacore/db/RaxaAlertDAO.java @@ -59,15 +59,6 @@ public interface RaxaAlertDAO { */ public List getRaxaAlertByPatientId(Integer patientId); - /** - * Find {@link RaxaAlert} matching a patientUuid - * - * @param patient - * @return {@link RaxaAlert} - * @should get a raxa alert list by patientUuid - */ - public List getRaxaAlertByPatientUuid(String patientUuid); - /** * Find {@link RaxaAlert} matching a uuid * @@ -104,15 +95,6 @@ public interface RaxaAlertDAO { */ public List getRaxaAlertByProviderSentId(Integer providerSentId); - /** - * Find {@link RaxaAlert} matching a providerSentUuid - * - * @param providerSent - * @return {@link RaxaAlert} - * @should get a raxa alert list by providerSentUuid - */ - public List getRaxaAlertByProviderSentUuid(String providerSentUuid); - /** * Find {@link RaxaAlert} matching providerRecipientId * @@ -122,15 +104,6 @@ public interface RaxaAlertDAO { */ public List getRaxaAlertByProviderRecipientId(Integer providerRecipientId); - /** - * Find {@link RaxaAlert} matching a providerRecipientUuid - * - * @param providerRecipient - * @return {@link RaxaAlert} - * @should get a raxa alert list by providerRecipientUuid - */ - public List getRaxaAlertByProviderRecipientUuid(String providerRecipientUuid); - /** * Update RaxaAlert * @return {@link RaxaAlert} diff --git a/api/src/main/java/org/raxa/module/raxacore/db/hibernate/HibernateRaxaAlertDAO.java b/api/src/main/java/org/raxa/module/raxacore/db/hibernate/HibernateRaxaAlertDAO.java index 5b5f550cfc..d786a7274c 100644 --- a/api/src/main/java/org/raxa/module/raxacore/db/hibernate/HibernateRaxaAlertDAO.java +++ b/api/src/main/java/org/raxa/module/raxacore/db/hibernate/HibernateRaxaAlertDAO.java @@ -22,11 +22,10 @@ import org.hibernate.criterion.Restrictions; import org.openmrs.api.db.DAOException; import org.raxa.module.raxacore.RaxaAlert; -import org.raxa.module.raxacore.RaxaAlertProviderRecipient; import org.raxa.module.raxacore.db.RaxaAlertDAO; /** - * Accesses raxacore_patient_list from RaxaAlert + * Accesses raxacore_raxaalert from RaxaAlert */ public class HibernateRaxaAlertDAO implements RaxaAlertDAO { @@ -115,18 +114,6 @@ public List getRaxaAlertByPatientId(Integer patientId) throws DAOExce return alerts; } - /** - * @see org.raxa.module.db.RaxaAlertDAO#getRaxaAlertByPatientUuid(String) - */ - @Override - public List getRaxaAlertByPatientUuid(String patientUuid) throws DAOException { - Criteria criteria = sessionFactory.getCurrentSession().createCriteria(RaxaAlert.class); - criteria.add(Restrictions.eq("patientUuid", patientUuid)); - List alerts = new ArrayList(); - alerts.addAll(criteria.list()); - return alerts; - } - /** * @see org.raxa.module.db.RaxaAlertDAO#getRaxaAlertByProviderSentId(Integer) */ @@ -139,37 +126,13 @@ public List getRaxaAlertByProviderSentId(Integer providerSentId) thro return alerts; } - /** - * @see org.raxa.module.db.RaxaAlertDAO#getRaxaAlertByProviderSentUuid(String) - */ - @Override - public List getRaxaAlertByProviderSentUuid(String providerSentUuid) throws DAOException { - Criteria criteria = sessionFactory.getCurrentSession().createCriteria(RaxaAlert.class); - criteria.add(Restrictions.eq("providerSentUuid", providerSentUuid)); - List alerts = new ArrayList(); - alerts.addAll(criteria.list()); - return alerts; - } - /** * @see org.raxa.module.db.RaxaAlertDAO#getRaxaAlertByProviderRecipientId(Integer) */ @Override public List getRaxaAlertByProviderRecipientId(Integer providerRecipientId) throws DAOException { - Criteria criteria = sessionFactory.getCurrentSession().createCriteria(RaxaAlertProviderRecipient.class); - criteria.add(Restrictions.eq("providerRecipientId", providerRecipientId)); - List alerts = new ArrayList(); - alerts.addAll(criteria.list()); - return alerts; - } - - /** - * @see org.raxa.module.db.RaxaAlertDAO#getRaxaAlertByProviderRecipientUuid(String) - */ - @Override - public List getRaxaAlertByProviderRecipientUuid(String providerRecipientUuid) throws DAOException { Criteria criteria = sessionFactory.getCurrentSession().createCriteria(RaxaAlert.class); - criteria.add(Restrictions.eq("providerRecipientUuid", providerRecipientUuid)); + criteria.add(Restrictions.eq("providerRecipientId", providerRecipientId)); List alerts = new ArrayList(); alerts.addAll(criteria.list()); return alerts; diff --git a/api/src/main/java/org/raxa/module/raxacore/impl/RaxaAlertServiceImpl.java b/api/src/main/java/org/raxa/module/raxacore/impl/RaxaAlertServiceImpl.java index cda013287b..f0ef86e043 100644 --- a/api/src/main/java/org/raxa/module/raxacore/impl/RaxaAlertServiceImpl.java +++ b/api/src/main/java/org/raxa/module/raxacore/impl/RaxaAlertServiceImpl.java @@ -68,7 +68,7 @@ public RaxaAlert getRaxaAlertsByName(String name) { * @see org.raxa.module.raxacore.RaxaAlertService#getRaxaAlertByAlertType(String) */ @Override - public List getRaxaAlertsByAlertType(String alertType) { + public List getRaxaAlertByAlertType(String alertType) { return (List) dao.getRaxaAlertByAlertType(alertType); } @@ -88,14 +88,6 @@ public List getRaxaAlertByPatientId(Integer patientId) { return dao.getRaxaAlertByPatientId(patientId); } - /** - * @see org.raxa.module.raxacore.RaxaAlertService#getRaxaAlertByPatientUuid(String) - */ - @Override - public List getRaxaAlertsByPatientUuid(String patientUuid) { - return dao.getRaxaAlertByPatientUuid(patientUuid); - } - /** * @see org.raxa.module.raxacore.RaxaAlertService#getRaxaAlertByProviderRecipientId(Integer) */ @@ -104,14 +96,6 @@ public List getRaxaAlertByProviderRecipientId(Integer providerRecipie return dao.getRaxaAlertByProviderRecipientId(providerRecipientId); } - /** - * @see org.raxa.module.raxacore.RaxaAlertService#getRaxaAlertByProviderRecipientUuid(String) - */ - @Override - public List getRaxaAlertsByProviderRecipientUuid(String providerRecipientUuid) { - return dao.getRaxaAlertByProviderRecipientUuid(providerRecipientUuid); - } - /** * @see org.raxa.module.raxacore.RaxaAlertService#getRaxaAlertByProviderSentId(Integer) */ @@ -120,14 +104,6 @@ public List getRaxaAlertByProviderSentId(Integer providerSentId) { return dao.getRaxaAlertByProviderSentId(providerSentId); } - /** - * @see org.raxa.module.raxacore.RaxaAlertService#getRaxaAlertByProviderSentUuid(String) - */ - @Override - public List getRaxaAlertsByProviderSentUuid(String providerSentUuid) { - return dao.getRaxaAlertByProviderSentUuid(providerSentUuid); - } - /** * @see org.raxa.module.raxacore.RaxaAlertService#getAllRaxaAlert */ diff --git a/api/src/main/resources/RaxacoreRaxaAlert.hbm.xml b/api/src/main/resources/RaxacoreRaxaAlert.hbm.xml index c7e9b0652c..5d6bfac788 100644 --- a/api/src/main/resources/RaxacoreRaxaAlert.hbm.xml +++ b/api/src/main/resources/RaxacoreRaxaAlert.hbm.xml @@ -10,28 +10,21 @@ - - - - - - - - - - - - - + + + + + + - + - + diff --git a/api/src/main/resources/liquibase.xml b/api/src/main/resources/liquibase.xml index e553b28111..29211efb5e 100644 --- a/api/src/main/resources/liquibase.xml +++ b/api/src/main/resources/liquibase.xml @@ -76,7 +76,7 @@ Schema for raxacore_raxaalert table - + @@ -89,6 +89,9 @@ + + + diff --git a/api/src/main/resources/moduleApplicationContext.xml b/api/src/main/resources/moduleApplicationContext.xml index 1115394ab4..e839228c3a 100644 --- a/api/src/main/resources/moduleApplicationContext.xml +++ b/api/src/main/resources/moduleApplicationContext.xml @@ -69,7 +69,7 @@ - + diff --git a/api/src/test/java/org/raxa/module/raxacore/db/hibernate/HibernateRaxaAlertDAOTest.java b/api/src/test/java/org/raxa/module/raxacore/db/hibernate/HibernateRaxaAlertDAOTest.java index d8bc703e7c..f4765ad199 100644 --- a/api/src/test/java/org/raxa/module/raxacore/db/hibernate/HibernateRaxaAlertDAOTest.java +++ b/api/src/test/java/org/raxa/module/raxacore/db/hibernate/HibernateRaxaAlertDAOTest.java @@ -62,7 +62,7 @@ public void testSaveRaxaAlert() { dao.saveRaxaAlert(rAlert); RaxaAlert result = dao.getRaxaAlertByName("TestList3"); String name = result.getName(); - assertEquals(name, "TestList4"); + assertEquals(name, "TestList3"); } /** @@ -103,7 +103,7 @@ public void testGetRaxaAlert() { public void testGetRaxaAlertByUuid() { String uuid = "68547121-1b70-465e-99ee-c9dfd95e7d30"; String result = dao.getRaxaAlertByUuid(uuid).getName(); - assertEquals("TestList2", result); + assertEquals("TestList1", result); } /** @@ -121,14 +121,9 @@ public void testGetRaxaAlertByName() { */ @Test public void testGetRaxaAlertByAlertType() { - System.out.println("getRaxaAlertByAlertType"); - String alertType = ""; - HibernateRaxaAlertDAO instance = new HibernateRaxaAlertDAO(); - List expResult = null; - List result = instance.getRaxaAlertByAlertType(alertType); - assertEquals(expResult, result); - // TODO review the generated test code and remove the default call to fail. - fail("The test case is a prototype."); + String alertType = "test1"; + String result = dao.getRaxaAlertByAlertType(alertType).get(0).getAlertType(); + assertEquals(alertType, result); } /** @@ -136,29 +131,9 @@ public void testGetRaxaAlertByAlertType() { */ @Test public void testGetRaxaAlertByPatientId() { - System.out.println("getRaxaAlertByPatientId"); - Integer patientId = null; - HibernateRaxaAlertDAO instance = new HibernateRaxaAlertDAO(); - List expResult = null; - List result = instance.getRaxaAlertByPatientId(patientId); - assertEquals(expResult, result); - // TODO review the generated test code and remove the default call to fail. - fail("The test case is a prototype."); - } - - /** - * Test of getRaxaAlertByPatientUuid method, of class HibernateRaxaAlertDAO. - */ - @Test - public void testGetRaxaAlertByPatientUuid() { - System.out.println("getRaxaAlertByPatientUuid"); - String patientUuid = ""; - HibernateRaxaAlertDAO instance = new HibernateRaxaAlertDAO(); - List expResult = null; - List result = instance.getRaxaAlertByPatientUuid(patientUuid); - assertEquals(expResult, result); - // TODO review the generated test code and remove the default call to fail. - fail("The test case is a prototype."); + Integer patientId = 1; + String result = dao.getRaxaAlertByPatientId(patientId).get(0).getName(); + assertEquals("TestList1", result); } /** @@ -166,29 +141,9 @@ public void testGetRaxaAlertByPatientUuid() { */ @Test public void testGetRaxaAlertByProviderSentId() { - System.out.println("getRaxaAlertByProviderSentId"); - Integer providerSentId = null; - HibernateRaxaAlertDAO instance = new HibernateRaxaAlertDAO(); - List expResult = null; - List result = instance.getRaxaAlertByProviderSentId(providerSentId); - assertEquals(expResult, result); - // TODO review the generated test code and remove the default call to fail. - fail("The test case is a prototype."); - } - - /** - * Test of getRaxaAlertByProviderSentUuid method, of class HibernateRaxaAlertDAO. - */ - @Test - public void testGetRaxaAlertByProviderSentUuid() { - System.out.println("getRaxaAlertByProviderSentUuid"); - String providerSentUuid = ""; - HibernateRaxaAlertDAO instance = new HibernateRaxaAlertDAO(); - List expResult = null; - List result = instance.getRaxaAlertByProviderSentUuid(providerSentUuid); - assertEquals(expResult, result); - // TODO review the generated test code and remove the default call to fail. - fail("The test case is a prototype."); + Integer providerSentId = 1; + String result = dao.getRaxaAlertByProviderSentId(providerSentId).get(0).getName(); + assertEquals("TestList1", result); } /** @@ -196,47 +151,27 @@ public void testGetRaxaAlertByProviderSentUuid() { */ @Test public void testGetRaxaAlertByProviderRecipientId() { - System.out.println("getRaxaAlertByProviderRecipientId"); - Integer providerRecipientId = null; - HibernateRaxaAlertDAO instance = new HibernateRaxaAlertDAO(); - List expResult = null; - List result = instance.getRaxaAlertByProviderRecipientId(providerRecipientId); - assertEquals(expResult, result); - // TODO review the generated test code and remove the default call to fail. - fail("The test case is a prototype."); - } - - /** - * Test of getRaxaAlertByProviderRecipientUuid method, of class HibernateRaxaAlertDAO. - */ - @Test - public void testGetRaxaAlertByProviderRecipientUuid() { - System.out.println("getRaxaAlertByProviderRecipientUuid"); - String providerRecipientUuid = ""; - HibernateRaxaAlertDAO instance = new HibernateRaxaAlertDAO(); - List expResult = null; - List result = instance.getRaxaAlertByProviderRecipientUuid(providerRecipientUuid); - assertEquals(expResult, result); - // TODO review the generated test code and remove the default call to fail. - fail("The test case is a prototype."); + Integer providerRecipientId = 1; + String result = dao.getRaxaAlertByProviderRecipientId(providerRecipientId).get(0).getName(); + assertEquals("TestList1", result); } /** * Test of getAllRaxaAlerts method, of class HibernateRaxaAlertDAO. */ @Test - public void testGetAllPatientList_shouldReturnAllRaxaAlertsIncludingVoided() { + public void testGetAllRaxaAlert_shouldReturnAllRaxaAlertsIncludingVoided() { List allRaxaAlert = dao.getAllRaxaAlerts(true); - assertEquals(allRaxaAlert.size(), 3); + assertEquals(allRaxaAlert.size(), 1); } /** * Test of getAllRaxaAlerts method, of class HibernateRaxaAlertDAO. */ @Test - public void testGetAllPatientList_shouldReturnAllUnvoidedRaxaAlerts() { + public void testGetAllRaxaAlert_shouldReturnAllUnvoidedRaxaAlerts() { List allRaxaAlert = dao.getAllRaxaAlerts(false); - assertEquals(allRaxaAlert.size(), 3); + assertEquals(allRaxaAlert.size(), 0); } /** @@ -258,7 +193,7 @@ public void testUpdateRaxaAlert() { public void testMarkRaxaAlertAsSeen() { RaxaAlert raxaAlert = dao.getRaxaAlert(1); dao.markRaxaAlertAsSeen(raxaAlert); - Boolean seen = dao.getRaxaAlert(1).seen(); - assertEquals(seen, "TRUE"); + Boolean seen = dao.getRaxaAlert(1).getSeen(); + assertEquals(seen, true); } } diff --git a/api/src/test/java/org/raxa/module/raxacore/impl/PatientListServiceImplTest.java b/api/src/test/java/org/raxa/module/raxacore/impl/PatientListServiceImplTest.java index 1aa4adfd5e..95c9fdd3aa 100644 --- a/api/src/test/java/org/raxa/module/raxacore/impl/PatientListServiceImplTest.java +++ b/api/src/test/java/org/raxa/module/raxacore/impl/PatientListServiceImplTest.java @@ -3,17 +3,14 @@ /** * Copyright 2012, Raxa * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. */ import java.util.List; import static org.junit.Assert.*; @@ -188,8 +185,7 @@ public void testGetPatientListByUuidShouldReturnPatientList() { } /** - * Test of getPatientListByEncounterType method, of class - * PatientListServiceImpl. + * Test of getPatientListByEncounterType method, of class PatientListServiceImpl. */ @Test public void testGetPatientListByEncounterTypeShouldReturnPatientList() { @@ -200,8 +196,7 @@ public void testGetPatientListByEncounterTypeShouldReturnPatientList() { } /** - * Test of getPatientListByEncounterType method, of class - * PatientListServiceImpl. + * Test of getPatientListByEncounterType method, of class PatientListServiceImpl. */ @Test public void testGetPatientListByEncounterTypeShouldUsePrivileges() { @@ -223,8 +218,7 @@ public void testGetPatientListByEncounterTypeShouldUsePrivileges() { } /** - * Test of getEncountersInPatientList method, of class - * PatientListServiceImpl. + * Test of getEncountersInPatientList method, of class PatientListServiceImpl. */ @Test public void testGetEncountersInPatientListShouldReturnEncounters() { @@ -244,8 +238,7 @@ public void testGetEncountersInPatientListShouldReturnEncounters() { } /** - * Test of getEncountersInPatientList method, of class - * PatientListServiceImpl. + * Test of getEncountersInPatientList method, of class PatientListServiceImpl. */ @Test public void testGetEncountersInPatientListShouldNotReturnEncountersWithInvalidDates() { @@ -260,59 +253,34 @@ public void testGetEncountersInPatientListShouldNotReturnEncountersWithInvalidDa } /** - * Test notInList according to Encounters of getEncountersInPatientList method, of class - * PatientListServiceImpl. + * Test notInList parts of getEncountersInPatientList method, of class PatientListServiceImpl. */ @Test public void testGetEncountersInPatientListShouldNotReturnEncountersAccordingToNotInList() { - PatientList mainList = new PatientList(); - PatientList notInList1 = new PatientList(); - PatientList notInList2 = new PatientList(); - mainList.setName("GetPatientsTestList"); - notInList1.setName("TestPatientsNotInList"); - notInList2.setName("TestPatientsNotInList2"); - notInList1.setSearchQuery("?encounterType=61ae96f4-6afe-4351-b6f8-cd4fc383cce1" + PatientList p = new PatientList(); + PatientList p2 = new PatientList(); + PatientList p3 = new PatientList(); + p.setCreator(Context.getUserContext().getAuthenticatedUser()); + p.setName("GetPatientsTestList"); + p2.setName("TestPatientsNotInList"); + p2.setName("TestPatientsNotInList2"); + p.setSearchQuery("?encounterType=61ae96f4-6afe-4351-b6f8-cd4fc383cce1" + "&startDate=2000-01-01T00:00:00&endDate=2008-08-16T00:00:00"); - notInList2.setSearchQuery("?encounterType=61ae96f4-6afe-4351-b6f8-cd4fc383cce1" + p3.setSearchQuery("?encounterType=61ae96f4-6afe-4351-b6f8-cd4fc383cce1" + "&startDate=2008-08-16T00:00:00&endDate=2012-01-02T00:00:00"); - s.savePatientList(notInList1); - s.savePatientList(notInList2); - mainList.setSearchQuery("?encounterType=61ae96f4-6afe-4351-b6f8-cd4fc383cce1" - + "&startDate=2000-01-01T00:00:00&endDate=2012-01-02T00:00:00¬InList=" + notInList1.getUuid() + "," - + notInList2.getUuid()); - List encs = s.getEncountersInPatientList(mainList); + s.savePatientList(p); + s.savePatientList(p3); + p2 + .setSearchQuery("?encounterType=61ae96f4-6afe-4351-b6f8-cd4fc383cce1" + + "&startDate=2000-01-01T00:00:00&endDate=2012-01-02T00:00:00¬InList=" + p.getUuid() + "," + + p3.getUuid()); + List encs = s.getEncountersInPatientList(p2); //now checking that notInList works assertEquals(encs.size(), 0); } /** - * Test notInList according to Patient of getEncountersInPatientList method, of class - * PatientListServiceImpl. - * All 3 lists have the same start and end dates. - * notInList1 has 1 encounter (type 2) with Patient #7. - * Without the notInList query, mainList would have had 2 encounters of type 1 with Patient #7. - * Because of notInList, mainList has all encounters of type 1 which are not associated with Patient #7. - * Since no such encounter exists in the dataset, the value should be 0. - */ - @Test - public void testGetEncountersInPatientListShouldNotReturnPatientsAccordingToNotInList() { - PatientList mainList = new PatientList(); - PatientList notInList1 = new PatientList(); - mainList.setName("GetPatientsTestList"); - notInList1.setName("TestPatientsNotInList"); - notInList1.setSearchQuery("?encounterType=07000be2-26b6-4cce-8b40-866d8435b613" - + "&startDate=2000-01-01T00:00:00&endDate=2012-01-02T00:00:00"); - s.savePatientList(notInList1); - mainList.setSearchQuery("?encounterType=61ae96f4-6afe-4351-b6f8-cd4fc383cce1" - + "&startDate=2000-01-01T00:00:00&endDate=2012-01-02T00:00:00¬InList=" + notInList1.getUuid()); - List encs = s.getEncountersInPatientList(mainList); - //now checking that notInList works - assertEquals(encs.size(), 0); - } - - /** - * Test inList parts of getEncountersInPatientList method, of class - * PatientListServiceImpl. + * Test inList parts of getEncountersInPatientList method, of class PatientListServiceImpl. */ @Test public void testGetEncountersInPatientListShouldOnlyReturnEncountersAccordingToInList() { @@ -338,22 +306,6 @@ public void testGetEncountersInPatientListShouldOnlyReturnEncountersAccordingToI assertEquals(encs.size(), originalLength - encs2.size()); } - /** - * Test of GetEncountersInPatientList method, of class PatientListServiceImpl given provider uuid. - */ - @Test - public void testGetEncountersInPatientListShouldReturnEncountersOfRequiredProvider() { - PatientList p = new PatientList(); - p.setCreator(new User()); - p.setName("GetPatientsTestList"); - p.setSearchQuery("?encounterType=61ae96f4-6afe-4351-b6f8-cd4fc383ctyr" - + "&provider=3effc802-12dd-4539-87f6-4065ca8e992c"); - List encs = s.getEncountersInPatientList(p); - //testing encounterType - - assertEquals(encs.size(), 1); - } - /** * Test of getPatientsInPatientList method, of class PatientListServiceImpl. */ diff --git a/api/src/test/resources/org/raxa/module/raxacore/include/moduleTestData.xml b/api/src/test/resources/org/raxa/module/raxacore/include/moduleTestData.xml index b51ba41c37..2c1cd90525 100644 --- a/api/src/test/resources/org/raxa/module/raxacore/include/moduleTestData.xml +++ b/api/src/test/resources/org/raxa/module/raxacore/include/moduleTestData.xml @@ -12,4 +12,5 @@ + diff --git a/api/src/test/resources/test-hibernate.cfg.xml b/api/src/test/resources/test-hibernate.cfg.xml index 3bf57401f0..2eb31ab8cd 100644 --- a/api/src/test/resources/test-hibernate.cfg.xml +++ b/api/src/test/resources/test-hibernate.cfg.xml @@ -6,6 +6,6 @@ - + \ No newline at end of file