Skip to content
Browse files

Merging drug info from diegodayan

  • Loading branch information...
1 parent 7556b5c commit 0ba930dcb578d1f16a21ec86c6cee48ab2984be2 @johnstoecker johnstoecker committed with johnstoecker Sep 6, 2012
Showing with 3,428 additions and 1,386 deletions.
  1. +1 −0 .gitignore
  2. +103 −103 api/src/main/java/org/raxa/module/raxacore/DrugGroup.java
  3. +102 −102 api/src/main/java/org/raxa/module/raxacore/DrugGroupService.java
  4. +170 −0 api/src/main/java/org/raxa/module/raxacore/DrugInfo.java
  5. +89 −0 api/src/main/java/org/raxa/module/raxacore/DrugInfoService.java
  6. +81 −81 api/src/main/java/org/raxa/module/raxacore/db/DrugGroupDAO.java
  7. +87 −0 api/src/main/java/org/raxa/module/raxacore/db/DrugInfoDAO.java
  8. +119 −119 api/src/main/java/org/raxa/module/raxacore/db/hibernate/HibernateDrugGroupDAO.java
  9. +118 −0 api/src/main/java/org/raxa/module/raxacore/db/hibernate/HibernateDrugInfoDAO.java
  10. +140 −140 api/src/main/java/org/raxa/module/raxacore/impl/DrugGroupServiceImpl.java
  11. +132 −0 api/src/main/java/org/raxa/module/raxacore/impl/DrugInfoServiceImpl.java
  12. +27 −0 api/src/main/resources/RaxacoreDrugInfo.hbm.xml
  13. +60 −1 api/src/main/resources/liquibase.xml
  14. +33 −0 api/src/main/resources/moduleApplicationContext.xml
  15. +104 −104 api/src/test/java/org/raxa/module/raxacore/db/hibernate/HibernateDrugGroupDAOTest.java
  16. +148 −0 api/src/test/java/org/raxa/module/raxacore/db/hibernate/HibernateDrugInfoDAOTest.java
  17. +222 −222 api/src/test/java/org/raxa/module/raxacore/impl/DrugGroupServiceImplTest.java
  18. +259 −0 api/src/test/java/org/raxa/module/raxacore/impl/DrugInfoServiceImplTest.java
  19. +33 −0 api/src/test/resources/TestingApplicationContext.xml
  20. +6 −0 api/src/test/resources/org/raxa/module/raxacore/include/moduleTestData.xml
  21. +2 −1 api/src/test/resources/test-hibernate.cfg.xml
  22. +318 −318 omod/src/main/java/org/raxa/module/raxacore/web/v1_0/controller/DrugGroupController.java
  23. +296 −0 omod/src/main/java/org/raxa/module/raxacore/web/v1_0/controller/DrugInfoController.java
  24. +276 −0 omod/src/main/java/org/raxa/module/raxacore/web/v1_0/controller/RaxaDrugController.java
  25. +195 −195 omod/src/main/java/org/raxa/module/raxacore/web/v1_0/resource/DrugGroupResource.java
  26. +161 −0 omod/src/main/java/org/raxa/module/raxacore/web/v1_0/resource/DrugInfoResource.java
  27. +128 −0 omod/src/main/java/org/raxa/module/raxacore/web/v1_0/resource/RaxaDrugResource.java
  28. +18 −0 omod/src/main/resources/config.xml
View
1 .gitignore
@@ -1 +1,2 @@
target/
+.DS_Store
View
206 api/src/main/java/org/raxa/module/raxacore/DrugGroup.java
@@ -1,103 +1,103 @@
-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.Set;
-import java.util.HashSet;
-import org.openmrs.BaseOpenmrsMetadata;
-import org.openmrs.Drug;
-
-/**
- * PatientList stores the data needed to lists patients for registration,
- * screener, etc.
- */
-public class DrugGroup extends BaseOpenmrsMetadata implements Serializable {
-
- private Integer drugGroupId;
-
- public DrugGroup() {
- }
-
- /**
- * Sets id
- *
- * @param id: id to set
- */
- @Override
- public void setId(Integer id) {
- setDrugGroupId(id);
- }
-
- /**
- * Gets id
- *
- * @return the patientListId
- */
- @Override
- public Integer getId() {
- return getDrugGroupId();
- }
-
- /**
- * Compares two PatientList objects for similarity
- *
- * @param obj PatientList 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 PatientList
- * with same patientListId @should not equal PatientList with different
- * patientListId @should not equal on null @should have equal patientList
- * objects with no patientListIds @should not have equal PatientList objects
- * when one has null patientListId
- */
- @Override
- public boolean equals(Object obj) {
- if (obj instanceof DrugGroup) {
- DrugGroup pList = (DrugGroup) obj;
- if (this.getDrugGroupId() != null && pList.getDrugGroupId() != null) {
- return (this.getDrugGroupId().equals(pList.getDrugGroupId()));
- }
- }
- 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.getDrugGroupId() == null) {
- return super.hashCode();
- }
- return this.getDrugGroupId().hashCode();
- }
-
- /**
- * @return the patientListId
- */
- public Integer getDrugGroupId() {
- return drugGroupId;
- }
-
- /**
- * @param patientListId the patientListId to set
- */
- public void setDrugGroupId(Integer patientListId) {
- this.drugGroupId = patientListId;
- }
-}
+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.Set;
+import java.util.HashSet;
+import org.openmrs.BaseOpenmrsMetadata;
+import org.openmrs.Drug;
+
+/**
+ * PatientList stores the data needed to lists patients for registration,
+ * screener, etc.
+ */
+public class DrugGroup extends BaseOpenmrsMetadata implements Serializable {
+
+ private Integer drugGroupId;
+
+ public DrugGroup() {
+ }
+
+ /**
+ * Sets id
+ *
+ * @param id: id to set
+ */
+ @Override
+ public void setId(Integer id) {
+ setDrugGroupId(id);
+ }
+
+ /**
+ * Gets id
+ *
+ * @return the patientListId
+ */
+ @Override
+ public Integer getId() {
+ return getDrugGroupId();
+ }
+
+ /**
+ * Compares two PatientList objects for similarity
+ *
+ * @param obj PatientList 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 PatientList
+ * with same patientListId @should not equal PatientList with different
+ * patientListId @should not equal on null @should have equal patientList
+ * objects with no patientListIds @should not have equal PatientList objects
+ * when one has null patientListId
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if (obj instanceof DrugGroup) {
+ DrugGroup pList = (DrugGroup) obj;
+ if (this.getDrugGroupId() != null && pList.getDrugGroupId() != null) {
+ return (this.getDrugGroupId().equals(pList.getDrugGroupId()));
+ }
+ }
+ 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.getDrugGroupId() == null) {
+ return super.hashCode();
+ }
+ return this.getDrugGroupId().hashCode();
+ }
+
+ /**
+ * @return the patientListId
+ */
+ public Integer getDrugGroupId() {
+ return drugGroupId;
+ }
+
+ /**
+ * @param patientListId the patientListId to set
+ */
+ public void setDrugGroupId(Integer patientListId) {
+ this.drugGroupId = patientListId;
+ }
+}
View
204 api/src/main/java/org/raxa/module/raxacore/DrugGroupService.java
@@ -1,102 +1,102 @@
-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.Encounter;
-import org.openmrs.EncounterType;
-import org.openmrs.Patient;
-import org.openmrs.Drug;
-import org.openmrs.annotation.Authorized;
-import org.openmrs.api.OpenmrsService;
-import org.openmrs.util.PrivilegeConstants;
-import org.raxa.module.raxacore.db.DrugGroupDAO;
-import org.springframework.transaction.annotation.Transactional;
-
-/*
- * Interface for interacting with the DrugGroup
- */
-@Transactional
-public interface DrugGroupService extends OpenmrsService {
-
- /**
- * Sets Drug Group DAO
- *
- * @param dao
- */
- public void setDrugGroupDAO(DrugGroupDAO dao);
-
- /**
- * Saves DrugGroup
- *
- * @param drugGroup
- * @return DrugGroup
- */
- @Authorized( { "Add Drug Groups" })
- public DrugGroup saveDrugGroup(DrugGroup drugGroup);
-
- /**
- * Gets a DrugGroup by Id
- *
- * @param id
- * @return DrugGroups
- */
- @Authorized( { "View Drug Groups" })
- public DrugGroup getDrugGroup(Integer id);
-
- /**
- * Gets a DrugGroup by Name
- *
- * @param name
- * @return list of DrugGroups
- */
- @Authorized( { "View Drug Groups" })
- public List<DrugGroup> getDrugGroupByName(String name);
-
- /**
- * Gets DrugGroup by uuid
- *
- * @param uuid
- * @return DrugGroup
- */
- @Authorized( { "View Drug Groups" })
- public DrugGroup getDrugGroupByUuid(String uuid);
-
- /**
- * Gets all DrugGroups
- *
- * @return list of DrugGroups
- */
- @Authorized( { "View Drug Groups" })
- public List<DrugGroup> getAllDrugGroup(boolean includeRetired);
-
- /**
- * Updates DrugGroup
- *
- * @param DrugGroup
- * @return DrugGroup
- */
- @Authorized( { "Edit Drug Groups" })
- DrugGroup updateDrugGroup(DrugGroup drugGroup);
-
- /**
- * Deletes DrugGroup
- *
- * @param DrugGroup
- */
- @Authorized( { "Delete Drug Groups" })
- public void deleteDrugGroup(DrugGroup drugGroup);
-}
+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.Encounter;
+import org.openmrs.EncounterType;
+import org.openmrs.Patient;
+import org.openmrs.Drug;
+import org.openmrs.annotation.Authorized;
+import org.openmrs.api.OpenmrsService;
+import org.openmrs.util.PrivilegeConstants;
+import org.raxa.module.raxacore.db.DrugGroupDAO;
+import org.springframework.transaction.annotation.Transactional;
+
+/*
+ * Interface for interacting with the DrugGroup
+ */
+@Transactional
+public interface DrugGroupService extends OpenmrsService {
+
+ /**
+ * Sets Drug Group DAO
+ *
+ * @param dao
+ */
+ public void setDrugGroupDAO(DrugGroupDAO dao);
+
+ /**
+ * Saves DrugGroup
+ *
+ * @param drugGroup
+ * @return DrugGroup
+ */
+ @Authorized( { "Add Drug Groups" })
+ public DrugGroup saveDrugGroup(DrugGroup drugGroup);
+
+ /**
+ * Gets a DrugGroup by Id
+ *
+ * @param id
+ * @return DrugGroups
+ */
+ @Authorized( { "View Drug Groups" })
+ public DrugGroup getDrugGroup(Integer id);
+
+ /**
+ * Gets a DrugGroup by Name
+ *
+ * @param name
+ * @return list of DrugGroups
+ */
+ @Authorized( { "View Drug Groups" })
+ public List<DrugGroup> getDrugGroupByName(String name);
+
+ /**
+ * Gets DrugGroup by uuid
+ *
+ * @param uuid
+ * @return DrugGroup
+ */
+ @Authorized( { "View Drug Groups" })
+ public DrugGroup getDrugGroupByUuid(String uuid);
+
+ /**
+ * Gets all DrugGroups
+ *
+ * @return list of DrugGroups
+ */
+ @Authorized( { "View Drug Groups" })
+ public List<DrugGroup> getAllDrugGroup(boolean includeRetired);
+
+ /**
+ * Updates DrugGroup
+ *
+ * @param DrugGroup
+ * @return DrugGroup
+ */
+ @Authorized( { "Edit Drug Groups" })
+ DrugGroup updateDrugGroup(DrugGroup drugGroup);
+
+ /**
+ * Deletes DrugGroup
+ *
+ * @param DrugGroup
+ */
+ @Authorized( { "Delete Drug Groups" })
+ public void deleteDrugGroup(DrugGroup drugGroup);
+}
View
170 api/src/main/java/org/raxa/module/raxacore/DrugInfo.java
@@ -0,0 +1,170 @@
+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.BaseOpenmrsMetadata;
+import org.openmrs.Drug;
+
+/**
+ * DrugInfo stores the data needed to lists patients for registration, screener,
+ * etc.
+ */
+public class DrugInfo extends BaseOpenmrsMetadata implements Serializable {
+
+ private Integer id;
+
+ private Integer drugId;
+
+ private Drug drug;
+
+ private double price;
+
+ private double cost;
+
+ private String note;
+
+ public DrugInfo() {
+ }
+
+ /**
+ * Sets id
+ *
+ * @param id: id to set
+ */
+ @Override
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ /**
+ * Gets id
+ *
+ * @return the drugInfoId
+ */
+ @Override
+ public Integer getId() {
+ return id;
+ }
+
+ /**
+ * Compares two DrugInfo objects for similarity
+ *
+ * @param obj DrugInfo 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 DrugInfo with same drugInfoId
+ * @should not equal DrugInfo with different drugInfoId
+ * @should not equal on null
+ * @should have equal drugInfo objects with no drugInfoIds
+ * @should not have equal DrugInfo objects when one has null drugInfoId
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if (obj instanceof DrugInfo) {
+ DrugInfo pList = (DrugInfo) obj;
+ if (this.getId() != null && pList.getId() != null) {
+ return (this.getId().equals(pList.getId()));
+ }
+ }
+ 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.getId() == null) {
+ return super.hashCode();
+ }
+ return this.getId().hashCode();
+ }
+
+ /**
+ * @return the drug
+ */
+ public Drug getDrug() {
+ return drug;
+ }
+
+ /**
+ * @param drug the drug to set
+ */
+ public void setDrug(Drug drug) {
+ this.drug = drug;
+ this.drugId = drug.getId();
+ }
+
+ /**
+ * @return the price
+ */
+ public double getPrice() {
+ return price;
+ }
+
+ /**
+ * @param price the price to set
+ */
+ public void setPrice(double price) {
+ this.price = price;
+ }
+
+ /**
+ * @return the cost
+ */
+ public double getCost() {
+ return cost;
+ }
+
+ /**
+ * @param cost the cost to set
+ */
+ public void setCost(double cost) {
+ this.cost = cost;
+ }
+
+ /**
+ * @return the note
+ */
+ public String getNote() {
+ return note;
+ }
+
+ /**
+ * @param note the note to set
+ */
+ public void setNote(String note) {
+ this.note = note;
+ }
+
+ /**
+ * @return the drugId
+ */
+ public Integer getDrugId() {
+ return drugId;
+ }
+
+ /**
+ * @param drugId the drugId to set
+ */
+ public void setDrugId(Integer drugId) {
+ this.drugId = drugId;
+ }
+}
View
89 api/src/main/java/org/raxa/module/raxacore/DrugInfoService.java
@@ -0,0 +1,89 @@
+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.Encounter;
+import org.openmrs.EncounterType;
+import org.openmrs.Patient;
+import org.openmrs.annotation.Authorized;
+import org.openmrs.api.OpenmrsService;
+import org.openmrs.util.PrivilegeConstants;
+import org.raxa.module.raxacore.db.DrugInfoDAO;
+import org.springframework.transaction.annotation.Transactional;
+
+/*
+ * Interface for interacting with the DrugInfo
+ */
+@Transactional
+public interface DrugInfoService extends OpenmrsService {
+
+ /**
+ * Sets Patient List DAO
+ *
+ * @param dao
+ */
+ public void setDrugInfoDAO(DrugInfoDAO dao);
+
+ /**
+ * Saves DrugInfo
+ *
+ * @param drugInfo
+ * @return DrugInfo
+ */
+ @Authorized( { "Add Drug Info" })
+ public DrugInfo saveDrugInfo(DrugInfo drugInfo);
+
+ /**
+ * Gets a DrugInfo by Id
+ *
+ * @param id
+ * @return DrugInfos
+ */
+ @Authorized( { "View Drug Info" })
+ public DrugInfo getDrugInfo(Integer id);
+
+ /**
+ * Gets DrugInfo by uuid
+ *
+ * @param uuid
+ * @return DrugInfo
+ */
+ @Authorized( { "View Drug Info" })
+ public DrugInfo getDrugInfoByUuid(String uuid);
+
+ /**
+ * Gets all DrugInfos
+ *
+ * @return
+ */
+ @Authorized( { "View Drug Info" })
+ public List<DrugInfo> getAllDrugInfo(boolean includeRetired);
+
+ /**
+ * Updates DrugInfo
+ *
+ * @param drugInfo
+ * @return DrugInfo
+ */
+ @Authorized( { "Edit Drug Info" })
+ DrugInfo updateDrugInfo(DrugInfo drugInfo);
+
+ /**
+ * Deletes DrugInfo
+ *
+ * @param drugInfo
+ */
+ @Authorized( { "Delete Drug Info" })
+ public void deleteDrugInfo(DrugInfo drugInfo);
+}
View
162 api/src/main/java/org/raxa/module/raxacore/db/DrugGroupDAO.java
@@ -1,81 +1,81 @@
-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.EncounterType;
-import org.openmrs.api.db.DAOException;
-import org.raxa.module.raxacore.DrugGroup;
-
-/**
- * Interface for accessing raxacore_patient_list
- */
-public interface DrugGroupDAO {
-
- /**
- * Saves a DrugGroup
- *
- * @param DrugGroup to be saved
- * @throws DAOException @should save a patient list
- */
- public DrugGroup saveDrugGroup(DrugGroup drugGroup) throws DAOException;
-
- /**
- * Purge a DrugGroup from database.
- *
- * @param DrugGroup object to be purged
- */
- public void deleteDrugGroup(DrugGroup drugGroup) throws DAOException;
-
- /**
- * Get patientList by internal identifier
- *
- * @param patientListId patientList id
- * @return patientList with given internal identifier
- * @throws DAOException @should get a patient list
- */
- public DrugGroup getDrugGroup(Integer patientListId) throws DAOException;
-
- /**
- * Find {@link PatientList} matching a uuid
- *
- * @param uuid
- * @return {@link PatientList} @should get a patient list by uuid
- */
- public DrugGroup getDrugGroupByUuid(String uuid);
-
- /**
- * Find {@link PatientList} matching a name
- *
- * @param name
- * @return List of PatientLists @should get a patient list by name
- */
- public List<DrugGroup> getDrugGroupByName(String name);
-
- /**
- * Get all {@link PatientList}
- *
- * @return List of PatientLists @should get all patient lists
- */
- public List<DrugGroup> getAllDrugGroup(boolean includeRetired);
-
- /**
- * Update PatientList
- *
- * @return {@link PatientList} @should update a PatientList
- */
- DrugGroup updateDrugGroup(DrugGroup drugGroup) throws DAOException;
-}
+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.EncounterType;
+import org.openmrs.api.db.DAOException;
+import org.raxa.module.raxacore.DrugGroup;
+
+/**
+ * Interface for accessing raxacore_patient_list
+ */
+public interface DrugGroupDAO {
+
+ /**
+ * Saves a DrugGroup
+ *
+ * @param DrugGroup to be saved
+ * @throws DAOException @should save a patient list
+ */
+ public DrugGroup saveDrugGroup(DrugGroup drugGroup) throws DAOException;
+
+ /**
+ * Purge a DrugGroup from database.
+ *
+ * @param DrugGroup object to be purged
+ */
+ public void deleteDrugGroup(DrugGroup drugGroup) throws DAOException;
+
+ /**
+ * Get patientList by internal identifier
+ *
+ * @param patientListId patientList id
+ * @return patientList with given internal identifier
+ * @throws DAOException @should get a patient list
+ */
+ public DrugGroup getDrugGroup(Integer patientListId) throws DAOException;
+
+ /**
+ * Find {@link PatientList} matching a uuid
+ *
+ * @param uuid
+ * @return {@link PatientList} @should get a patient list by uuid
+ */
+ public DrugGroup getDrugGroupByUuid(String uuid);
+
+ /**
+ * Find {@link PatientList} matching a name
+ *
+ * @param name
+ * @return List of PatientLists @should get a patient list by name
+ */
+ public List<DrugGroup> getDrugGroupByName(String name);
+
+ /**
+ * Get all {@link PatientList}
+ *
+ * @return List of PatientLists @should get all patient lists
+ */
+ public List<DrugGroup> getAllDrugGroup(boolean includeRetired);
+
+ /**
+ * Update PatientList
+ *
+ * @return {@link PatientList} @should update a PatientList
+ */
+ DrugGroup updateDrugGroup(DrugGroup drugGroup) throws DAOException;
+}
View
87 api/src/main/java/org/raxa/module/raxacore/db/DrugInfoDAO.java
@@ -0,0 +1,87 @@
+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.EncounterType;
+import org.openmrs.api.db.DAOException;
+import org.raxa.module.raxacore.DrugInfo;
+
+/**
+ * Interface for accessing raxacore_drug_info
+ */
+public interface DrugInfoDAO {
+
+ /**
+ * Saves a DrugInfo
+ *
+ * @param DrugInfo to be saved
+ * @throws DAOException
+ * @should save a drug info
+ */
+ public DrugInfo saveDrugInfo(DrugInfo drugInfo) throws DAOException;
+
+ /**
+ * Purge a DrugInfo from database.
+ *
+ * @param DrugInfo object to be purged
+ */
+ public void deleteDrugInfo(DrugInfo drugInfo) throws DAOException;
+
+ /**
+ * Get drugInfo by internal identifier
+ *
+ * @param drugInfoId drugInfo id
+ * @return drugInfo with given internal identifier
+ * @throws DAOException
+ * @should get a drug info
+ */
+ public DrugInfo getDrugInfo(Integer drugInfoId) throws DAOException;
+
+ /**
+ * Find {@link DrugInfo} matching a uuid
+ *
+ * @param uuid
+ * @return {@link DrugInfo}
+ * @should get a drug info by uuid
+ */
+ public DrugInfo getDrugInfoByUuid(String uuid);
+
+ /**
+ * Find {@link DrugInfo} matching a name
+ *
+ * @param name
+ * @return List of DrugInfo
+ * @should get a drug info by name
+ */
+ public List<DrugInfo> getDrugInfoByName(String name);
+
+ /**
+ * Get all {@link DrugInfo}
+ *
+ * @return List of DrugInfo
+ * @should get all drug infos
+ */
+ public List<DrugInfo> getAllDrugInfo(boolean includeRetired);
+
+ /**
+ * Update DrugInfo
+ * @return {@link DrugInfo}
+ * @should update a DrugInfo
+ */
+ DrugInfo updateDrugInfo(DrugInfo drugInfo) throws DAOException;
+
+}
View
238 api/src/main/java/org/raxa/module/raxacore/db/hibernate/HibernateDrugGroupDAO.java
@@ -1,119 +1,119 @@
-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.EncounterType;
-import org.openmrs.api.db.DAOException;
-import org.raxa.module.raxacore.DrugGroup;
-import org.raxa.module.raxacore.db.DrugGroupDAO;
-
-public class HibernateDrugGroupDAO implements DrugGroupDAO {
-
- protected final Log log = LogFactory.getLog(getClass());
-
- /**
- * Hibernate session factory
- */
- private SessionFactory sessionFactory;
-
- /**
- * Set session factory
- *
- * @param sessionFactory
- */
- public void setSessionFactory(SessionFactory sessionFactory) {
- this.sessionFactory = sessionFactory;
- }
-
- /**
- * @see
- * org.raxa.module.db.DrugGroupDAO#saveDrugGroup(org.raxa.module.raxacore.DrugGroup)
- */
- @Override
- public DrugGroup saveDrugGroup(DrugGroup drugGroup) throws DAOException {
- sessionFactory.getCurrentSession().saveOrUpdate(drugGroup);
- return drugGroup;
- }
-
- /**
- * @see
- * org.raxa.module.db.DrugGroupDAO#deleteDrugGroup(org.raxa.module.raxacore.DrugGroup)
- */
- @Override
- public void deleteDrugGroup(DrugGroup drugGroup) throws DAOException {
- sessionFactory.getCurrentSession().delete(drugGroup);
- }
-
- /**
- * @see org.raxa.module.db.DrugGroupDAO#getDrugGroup(Integer)
- */
- @Override
- public DrugGroup getDrugGroup(Integer drugGroupId) throws DAOException {
- return (DrugGroup) sessionFactory.getCurrentSession().get(DrugGroup.class, drugGroupId);
- }
-
- /**
- * @see org.raxa.module.db.DrugGroupDAO#getDrugGroupByUuid(String)
- */
- @Override
- public DrugGroup getDrugGroupByUuid(String uuid) throws DAOException {
- Criteria criteria = sessionFactory.getCurrentSession().createCriteria(DrugGroup.class);
- criteria.add(Restrictions.eq("uuid", uuid));
- return (DrugGroup) criteria.uniqueResult();
- }
-
- /**
- * @see org.raxa.module.db.DrugGroupDAO#getDrugGroupByName(String)
- */
- @Override
- public List<DrugGroup> getDrugGroupByName(String name) throws DAOException {
- Criteria criteria = sessionFactory.getCurrentSession().createCriteria(DrugGroup.class);
- criteria.add(Restrictions.like("name", name));
- criteria.add(Restrictions.like("retired", false));
- List<DrugGroup> patients = new ArrayList<DrugGroup>();
- patients.addAll(criteria.list());
- return patients;
-
- }
-
- /**
- * @see org.raxa.module.db.DrugGroupDAO#getAllDrugGroup()
- */
- @Override
- public List<DrugGroup> getAllDrugGroup(boolean includeRetired) throws DAOException {
- Criteria criteria = sessionFactory.getCurrentSession().createCriteria(DrugGroup.class);
- if (includeRetired == false) {
- criteria.add(Restrictions.eq("retired", false));
- }
- return criteria.list();
- }
-
- /**
- * @see org.raxa.module.db.DrugGroupDAO#updateDrugGroup(Integer)
- */
- @Override
- public DrugGroup updateDrugGroup(DrugGroup drugGroup) throws DAOException {
- sessionFactory.getCurrentSession().update(drugGroup);
- return drugGroup;
- }
-}
+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.EncounterType;
+import org.openmrs.api.db.DAOException;
+import org.raxa.module.raxacore.DrugGroup;
+import org.raxa.module.raxacore.db.DrugGroupDAO;
+
+public class HibernateDrugGroupDAO implements DrugGroupDAO {
+
+ protected final Log log = LogFactory.getLog(getClass());
+
+ /**
+ * Hibernate session factory
+ */
+ private SessionFactory sessionFactory;
+
+ /**
+ * Set session factory
+ *
+ * @param sessionFactory
+ */
+ public void setSessionFactory(SessionFactory sessionFactory) {
+ this.sessionFactory = sessionFactory;
+ }
+
+ /**
+ * @see
+ * org.raxa.module.db.DrugGroupDAO#saveDrugGroup(org.raxa.module.raxacore.DrugGroup)
+ */
+ @Override
+ public DrugGroup saveDrugGroup(DrugGroup drugGroup) throws DAOException {
+ sessionFactory.getCurrentSession().saveOrUpdate(drugGroup);
+ return drugGroup;
+ }
+
+ /**
+ * @see
+ * org.raxa.module.db.DrugGroupDAO#deleteDrugGroup(org.raxa.module.raxacore.DrugGroup)
+ */
+ @Override
+ public void deleteDrugGroup(DrugGroup drugGroup) throws DAOException {
+ sessionFactory.getCurrentSession().delete(drugGroup);
+ }
+
+ /**
+ * @see org.raxa.module.db.DrugGroupDAO#getDrugGroup(Integer)
+ */
+ @Override
+ public DrugGroup getDrugGroup(Integer drugGroupId) throws DAOException {
+ return (DrugGroup) sessionFactory.getCurrentSession().get(DrugGroup.class, drugGroupId);
+ }
+
+ /**
+ * @see org.raxa.module.db.DrugGroupDAO#getDrugGroupByUuid(String)
+ */
+ @Override
+ public DrugGroup getDrugGroupByUuid(String uuid) throws DAOException {
+ Criteria criteria = sessionFactory.getCurrentSession().createCriteria(DrugGroup.class);
+ criteria.add(Restrictions.eq("uuid", uuid));
+ return (DrugGroup) criteria.uniqueResult();
+ }
+
+ /**
+ * @see org.raxa.module.db.DrugGroupDAO#getDrugGroupByName(String)
+ */
+ @Override
+ public List<DrugGroup> getDrugGroupByName(String name) throws DAOException {
+ Criteria criteria = sessionFactory.getCurrentSession().createCriteria(DrugGroup.class);
+ criteria.add(Restrictions.like("name", name));
+ criteria.add(Restrictions.like("retired", false));
+ List<DrugGroup> patients = new ArrayList<DrugGroup>();
+ patients.addAll(criteria.list());
+ return patients;
+
+ }
+
+ /**
+ * @see org.raxa.module.db.DrugGroupDAO#getAllDrugGroup()
+ */
+ @Override
+ public List<DrugGroup> getAllDrugGroup(boolean includeRetired) throws DAOException {
+ Criteria criteria = sessionFactory.getCurrentSession().createCriteria(DrugGroup.class);
+ if (includeRetired == false) {
+ criteria.add(Restrictions.eq("retired", false));
+ }
+ return criteria.list();
+ }
+
+ /**
+ * @see org.raxa.module.db.DrugGroupDAO#updateDrugGroup(Integer)
+ */
+ @Override
+ public DrugGroup updateDrugGroup(DrugGroup drugGroup) throws DAOException {
+ sessionFactory.getCurrentSession().update(drugGroup);
+ return drugGroup;
+ }
+}
View
118 api/src/main/java/org/raxa/module/raxacore/db/hibernate/HibernateDrugInfoDAO.java
@@ -0,0 +1,118 @@
+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.EncounterType;
+import org.openmrs.api.db.DAOException;
+import org.raxa.module.raxacore.DrugInfo;
+import org.raxa.module.raxacore.db.DrugInfoDAO;
+
+/**
+ * Accesses raxacore_drug_info from DrugInfo
+ */
+public class HibernateDrugInfoDAO implements DrugInfoDAO {
+
+ protected final Log log = LogFactory.getLog(getClass());
+
+ /**
+ * Hibernate session factory
+ */
+ private SessionFactory sessionFactory;
+
+ /**
+ * Set session factory
+ *
+ * @param sessionFactory
+ */
+ public void setSessionFactory(SessionFactory sessionFactory) {
+ this.sessionFactory = sessionFactory;
+ }
+
+ /**
+ * @see org.raxa.module.db.DrugInfoDAO#saveDrugInfo(org.raxa.module.raxacore.DrugInfo)
+ */
+ @Override
+ public DrugInfo saveDrugInfo(DrugInfo drugInfo) throws DAOException {
+ sessionFactory.getCurrentSession().saveOrUpdate(drugInfo);
+ return drugInfo;
+ }
+
+ /**
+ * @see org.raxa.module.db.DrugInfoDAO#deleteDrugInfo(org.raxa.module.raxacore.DrugInfo)
+ */
+ @Override
+ public void deleteDrugInfo(DrugInfo drugInfo) throws DAOException {
+ sessionFactory.getCurrentSession().delete(drugInfo);
+ }
+
+ /**
+ * @see org.raxa.module.db.DrugInfoDAO#getDrugInfo(Integer)
+ */
+ @Override
+ public DrugInfo getDrugInfo(Integer drugInfoId) throws DAOException {
+ return (DrugInfo) sessionFactory.getCurrentSession().get(DrugInfo.class, drugInfoId);
+ }
+
+ /**
+ * @see org.raxa.module.db.DrugInfoDAO#getDrugInfoByUuid(String)
+ */
+ @Override
+ public DrugInfo getDrugInfoByUuid(String uuid) throws DAOException {
+ Criteria criteria = sessionFactory.getCurrentSession().createCriteria(DrugInfo.class);
+ criteria.add(Restrictions.eq("uuid", uuid));
+ return (DrugInfo) criteria.uniqueResult();
+ }
+
+ /**
+ * @see org.raxa.module.db.DrugInfoDAO#getDrugInfoByName(String)
+ */
+ @Override
+ public List<DrugInfo> getDrugInfoByName(String name) throws DAOException {
+ Criteria criteria = sessionFactory.getCurrentSession().createCriteria(DrugInfo.class);
+ criteria.add(Restrictions.like("name", name));
+ criteria.add(Restrictions.like("retired", false));
+ List<DrugInfo> patients = new ArrayList<DrugInfo>();
+ patients.addAll(criteria.list());
+ return patients;
+
+ }
+
+ /**
+ * @see org.raxa.module.db.DrugInfoDAO#getAllDrugInfo()
+ */
+ @Override
+ public List<DrugInfo> getAllDrugInfo(boolean includeRetired) throws DAOException {
+ Criteria criteria = sessionFactory.getCurrentSession().createCriteria(DrugInfo.class);
+ if (includeRetired == false) {
+ criteria.add(Restrictions.eq("retired", false));
+ }
+ return criteria.list();
+ }
+
+ /**
+ * @see org.raxa.module.db.DrugInfoDAO#updateDrugInfo(Integer)
+ */
+ @Override
+ public DrugInfo updateDrugInfo(DrugInfo drugInfo) throws DAOException {
+ sessionFactory.getCurrentSession().update(drugInfo);
+ return drugInfo;
+ }
+}
View
280 api/src/main/java/org/raxa/module/raxacore/impl/DrugGroupServiceImpl.java
@@ -1,140 +1,140 @@
-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.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.DrugGroup;
-import org.raxa.module.raxacore.DrugGroupService;
-import org.raxa.module.raxacore.db.DrugGroupDAO;
-
-public class DrugGroupServiceImpl implements DrugGroupService {
-
- private DrugGroupDAO dao;
-
- private Log log = LogFactory.getLog(this.getClass());
-
- /**
- * @see org.raxa.module.raxacore.PatientListService#setPatientListDAO
- */
- @Override
- public void setDrugGroupDAO(DrugGroupDAO dao) {
- this.dao = dao;
- }
-
- /**
- * @see org.raxa.module.raxacore.PatientListService#savePatientList
- */
- @Override
- public DrugGroup saveDrugGroup(DrugGroup drugGroup) {
- return dao.saveDrugGroup(drugGroup);
- }
-
- /**
- * @see org.raxa.module.raxacore.PatientListService#getPatientList(Integer)
- */
- @Override
- public DrugGroup getDrugGroup(Integer id) {
- return dao.getDrugGroup(id);
- }
-
- /**
- * @see
- * org.raxa.module.raxacore.PatientListService#getPatientListByName(String)
- */
- @Override
- public List<DrugGroup> getDrugGroupByName(String name) {
- return dao.getDrugGroupByName(name);
- }
-
- /**
- * @see
- * org.raxa.module.raxacore.PatientListService#getPatientListByUuid(String)
- */
- @Override
- public DrugGroup getDrugGroupByUuid(String uuid) {
- return dao.getDrugGroupByUuid(uuid);
- }
-
- /**
- * @see org.raxa.module.raxacore.PatientListService#getAllPatientList
- */
- @Override
- public List<DrugGroup> getAllDrugGroup(boolean includeRetired) {
- return dao.getAllDrugGroup(includeRetired);
- }
-
- /**
- * Parses a string into a date
- *
- * @param str String to be parsed (must be iso format)
- * @return Date
- */
- private Date getDateFromString(String str) {
-
- String[] supportedFormats = { "yyyy-MM-dd'T'HH:mm:ss.SSSZ", "yyyy-MM-dd'T'HH:mm:ss.SSS", "yyyy-MM-dd'T'HH:mm:ssZ",
- "yyyy-MM-dd'T'HH:mm:ss", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd" };
- for (int i = 0; i < supportedFormats.length; i++) {
- try {
- Date date = new SimpleDateFormat(supportedFormats[i]).parse(str);
- return date;
- }
- catch (Exception ex) {
- //log.error(ex.getMessage() + " Error parsing string " + str + " into Date");
- }
- }
- log.error("Date string is malformed");
- return null;
- }
-
- /**
- * @see org.raxa.module.raxacore.PatientListService#updatePatientList
- */
- @Override
- public DrugGroup updateDrugGroup(DrugGroup drugGroup) {
- return dao.updateDrugGroup(drugGroup);
- }
-
- /**
- * @see org.raxa.module.raxacore.PatientListService#deletePatientList
- */
- @Override
- public void deleteDrugGroup(DrugGroup drugGroup) {
- dao.deleteDrugGroup(drugGroup);
- }
-
- @Override
- public void onStartup() {
- log.info("Starting patient list service");
- }
-
- @Override
- public void onShutdown() {
- log.info("Stopping patient list service");
- }
-}
+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.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.DrugGroup;
+import org.raxa.module.raxacore.DrugGroupService;
+import org.raxa.module.raxacore.db.DrugGroupDAO;
+
+public class DrugGroupServiceImpl implements DrugGroupService {
+
+ private DrugGroupDAO dao;
+
+ private Log log = LogFactory.getLog(this.getClass());
+
+ /**
+ * @see org.raxa.module.raxacore.PatientListService#setPatientListDAO
+ */
+ @Override
+ public void setDrugGroupDAO(DrugGroupDAO dao) {
+ this.dao = dao;
+ }
+
+ /**
+ * @see org.raxa.module.raxacore.PatientListService#savePatientList
+ */
+ @Override
+ public DrugGroup saveDrugGroup(DrugGroup drugGroup) {
+ return dao.saveDrugGroup(drugGroup);
+ }
+
+ /**
+ * @see org.raxa.module.raxacore.PatientListService#getPatientList(Integer)
+ */
+ @Override
+ public DrugGroup getDrugGroup(Integer id) {
+ return dao.getDrugGroup(id);
+ }
+
+ /**
+ * @see
+ * org.raxa.module.raxacore.PatientListService#getPatientListByName(String)
+ */
+ @Override
+ public List<DrugGroup> getDrugGroupByName(String name) {
+ return dao.getDrugGroupByName(name);
+ }
+
+ /**
+ * @see
+ * org.raxa.module.raxacore.PatientListService#getPatientListByUuid(String)
+ */
+ @Override
+ public DrugGroup getDrugGroupByUuid(String uuid) {
+ return dao.getDrugGroupByUuid(uuid);
+ }
+
+ /**
+ * @see org.raxa.module.raxacore.PatientListService#getAllPatientList
+ */
+ @Override
+ public List<DrugGroup> getAllDrugGroup(boolean includeRetired) {
+ return dao.getAllDrugGroup(includeRetired);
+ }
+
+ /**
+ * Parses a string into a date
+ *
+ * @param str String to be parsed (must be iso format)
+ * @return Date
+ */
+ private Date getDateFromString(String str) {
+
+ String[] supportedFormats = { "yyyy-MM-dd'T'HH:mm:ss.SSSZ", "yyyy-MM-dd'T'HH:mm:ss.SSS", "yyyy-MM-dd'T'HH:mm:ssZ",
+ "yyyy-MM-dd'T'HH:mm:ss", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd" };
+ for (int i = 0; i < supportedFormats.length; i++) {
+ try {
+ Date date = new SimpleDateFormat(supportedFormats[i]).parse(str);
+ return date;
+ }
+ catch (Exception ex) {
+ //log.error(ex.getMessage() + " Error parsing string " + str + " into Date");
+ }
+ }
+ log.error("Date string is malformed");
+ return null;
+ }
+
+ /**
+ * @see org.raxa.module.raxacore.PatientListService#updatePatientList
+ */
+ @Override
+ public DrugGroup updateDrugGroup(DrugGroup drugGroup) {
+ return dao.updateDrugGroup(drugGroup);
+ }
+
+ /**
+ * @see org.raxa.module.raxacore.PatientListService#deletePatientList
+ */
+ @Override
+ public void deleteDrugGroup(DrugGroup drugGroup) {
+ dao.deleteDrugGroup(drugGroup);
+ }
+
+ @Override
+ public void onStartup() {
+ log.info("Starting patient list service");
+ }
+
+ @Override
+ public void onShutdown() {
+ log.info("Stopping patient list service");
+ }
+}
View
132 api/src/main/java/org/raxa/module/raxacore/impl/DrugInfoServiceImpl.java
@@ -0,0 +1,132 @@
+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.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.Drug;
+import org.openmrs.api.context.Context;
+import org.raxa.module.raxacore.DrugInfo;
+import org.raxa.module.raxacore.DrugInfoService;
+import org.raxa.module.raxacore.db.DrugInfoDAO;
+
+public class DrugInfoServiceImpl implements DrugInfoService {
+
+ private DrugInfoDAO dao;
+
+ private Log log = LogFactory.getLog(this.getClass());
+
+ /**
+ * @see org.raxa.module.raxacore.DrugInfoService#setDrugInfoDAO
+ */
+ @Override
+ public void setDrugInfoDAO(DrugInfoDAO dao) {
+ this.dao = dao;
+ }
+
+ /**
+ * @see org.raxa.module.raxacore.DrugInfoService#saveDrugInfo
+ */
+ @Override
+ public DrugInfo saveDrugInfo(DrugInfo drugInfo) {
+ return dao.saveDrugInfo(drugInfo);
+ }
+
+ /**
+ * @see org.raxa.module.raxacore.DrugInfoService#getDrugInfo(Integer)
+ */
+ @Override
+ public DrugInfo getDrugInfo(Integer id) {
+ return dao.getDrugInfo(id);
+ }
+
+ /**
+ * @see
+ * org.raxa.module.raxacore.DrugInfoService#getDrugInfoByUuid(String)
+ */
+ @Override
+ public DrugInfo getDrugInfoByUuid(String uuid) {
+ return dao.getDrugInfoByUuid(uuid);
+ }
+
+ /**
+ * @see org.raxa.module.raxacore.DrugInfoService#getAllDrugInfo
+ */
+ @Override
+ public List<DrugInfo> getAllDrugInfo(boolean includeRetired) {
+ return dao.getAllDrugInfo(includeRetired);
+ }
+
+ /**
+ * Parses a string into a date
+ *
+ * @param str String to be parsed (must be iso format)
+ * @return Date
+ */
+ private Date getDateFromString(String str) {
+
+ String[] supportedFormats = { "yyyy-MM-dd'T'HH:mm:ss.SSSZ", "yyyy-MM-dd'T'HH:mm:ss.SSS", "yyyy-MM-dd'T'HH:mm:ssZ",
+ "yyyy-MM-dd'T'HH:mm:ss", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd" };
+ for (int i = 0; i < supportedFormats.length; i++) {
+ try {
+ Date date = new SimpleDateFormat(supportedFormats[i]).parse(str);
+ return date;
+ }
+ catch (Exception ex) {
+ //log.error(ex.getMessage() + " Error parsing string " + str + " into Date");
+ }
+ }
+ log.error("Date string is malformed");
+ return null;
+ }
+
+ /**
+ * @see org.raxa.module.raxacore.DrugInfoService#updateDrugInfo
+ */
+ @Override
+ public DrugInfo updateDrugInfo(DrugInfo drugInfo) {
+ return dao.updateDrugInfo(drugInfo);
+ }
+
+ /**
+ * @see org.raxa.module.raxacore.DrugInfoService#deleteDrugInfo
+ */
+ @Override
+ public void deleteDrugInfo(DrugInfo drugInfo) {
+ dao.deleteDrugInfo(drugInfo);
+ }
+
+ @Override
+ public void onStartup() {
+ log.info("Starting drug info service");
+ }
+
+ @Override
+ public void onShutdown() {
+ log.info("Stopping drug info service");
+ }
+}
View
27 api/src/main/resources/RaxacoreDrugInfo.hbm.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE hibernate-mapping PUBLIC
+ "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
+ "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+<hibernate-mapping package="org.raxa.module.raxacore">
+ <class name="DrugInfo" table="raxacore_drug_info">
+ <id name="id" column="drug_info_id">
+ <generator class="native"/>
+ </id>
+ <property name="drugId" type="java.lang.Integer" column="drug_id" insert="false" update="false"/>
+ <!-- relationship below should be one-to-one but we won't change OpenMRS Drug class so we use many-to-one -->
+ <many-to-one name="drug" class="org.openmrs.Drug" column="drug_id" not-null="true" unique="true" />
+ <property name="price" type="double" column="price" />
+ <property name="cost" type="double" column="cost" />
+ <property name="name" type="java.lang.String" column="name" length="255"/>
+ <property name="description" type="java.lang.String" column="description" length="2000"/>
+ <property name="uuid" type="java.lang.String" column="uuid" length="38" not-null="true" unique="true"/>
+ <many-to-one name="creator" class="org.openmrs.User" column="creator" not-null="true"/>
+ <property name="dateCreated" type="java.util.Date" column="date_created" not-null="true" length="19"/>
+ <property name="retired" type="java.lang.Boolean" column="retired" length="1" not-null="true"/>
+ <many-to-one name="retiredBy" class="org.openmrs.User" column="retired_by"/>
+ <property name="dateRetired" type="java.util.Date" column="date_retired"/>
+ <property name="retireReason" type="java.lang.String" column="retire_reason" length="255"/>
+ <many-to-one name="changedBy" class="org.openmrs.User" column="changed_by"/>
+ <property name="dateChanged" type="java.util.Date" column="date_changed" length="19"/>
+ </class>
+</hibernate-mapping>
View
61 api/src/main/resources/liquibase.xml
@@ -176,7 +176,7 @@
</createTable>
</changeSet>
- <changeSet id="2012-08-08_create_raxacore_drug_group" author="diegodayam">
+ <changeSet id="2012-08-08_create_raxacore_drug_group" author="diegodayan">
<preConditions onFail="MARK_RAN">
<not>
<tableExists tableName="raxacore_drug_group"/>
@@ -673,4 +673,63 @@
</addColumn>
</changeSet>
+ <changeSet id="2012-08-18_create_raxacore_drug_info" author="diegodayan">
+ <preConditions onFail="MARK_RAN">
+ <not>
+ <tableExists tableName="raxacore_drug_info"/>
+ </not>
+ </preConditions>
+ <comment>
+ Schema for raxacore_drug_info table
+ </comment>
+ <createTable tableName="raxacore_drug_info">
+ <column name="drug_info_id" type="int" autoIncrement="true">
+ <constraints primaryKey="true" nullable="false"/>
+ </column>
+ <column name="drug_id" type="int">
+ <constraints unique="true" nullable="false"/>
+ </column>
+ <column name="name" type="varchar(255)"/>
+ <column name="price" type="decimal(10,4)" defaultValueNumeric="0.0" />
+ <column name="cost" type="decimal(10,4)" defaultValueNumeric="0.0" />
+ <column name="description" type="varchar(2000)"/>
+ <column name="creator" type="int">
+ <constraints nullable="false"/>
+ </column>
+ <column name="date_created" type="DATETIME">
+ <constraints nullable="false"/>
+ </column>
+ <column defaultValueBoolean="false" name="voided" type="BOOLEAN">
+ <constraints nullable="false"/>
+ </column>
+ <column name="voided_by" type="int"/>
+ <column name="date_voided" type="DATETIME"/>
+ <column name="void_reason" type="varchar(255)"/>
+ <column name="changed_by" type="int"/>
+ <column name="date_changed" type="DATETIME"/>
+ <column defaultValueBoolean="false" name="retired" type="BOOLEAN">
+ <constraints nullable="false"/>
+ </column>
+ <column name="retired_by" type="int"/>
+ <column name="date_retired" type="DATETIME"/>
+ <column name="retire_reason" type="varchar(255)"/>
+ <column name="uuid" type="char(38)">
+ <constraints unique="true" nullable="false"/>
+ </column>
+ </createTable>
+ </changeSet>
+
+ <changeSet id="2012-08-20_add_constraints_to_raxacore_drug_info" author="diegodayan">
+ <preConditions onFail="MARK_RAN">
+ <tableExists tableName="raxacore_drug_info"/>
+ </preConditions>
+ <comment>
+ Adding constraints for auditing drug_info
+ </comment>
+ <addForeignKeyConstraint baseTableName="raxacore_drug_info"
+ baseColumnNames="drug_id"
+ constraintName="FK_raxacore_drug_info_drug_id_drug_drug_id"
+ referencedTableName="drug"
+ referencedColumnNames="drug_id"/>
+ </changeSet>
</databaseChangeLog>
View
33 api/src/main/resources/moduleApplicationContext.xml
@@ -123,6 +123,39 @@
</property>
</bean>
+ <bean id="org.raxa.module.raxacore.db.hibernate.HibernateDrugInfoDAO" class="org.raxa.module.raxacore.db.hibernate.HibernateDrugInfoDAO">
+ <property name="sessionFactory" ref="sessionFactory"/>
+ </bean>
+
+ <bean parent="serviceContext">
+ <property name="moduleService">
+ <list>
+ <value>org.raxa.module.raxacore.DrugInfoService</value>
+ <bean class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
+ <property name="transactionManager">
+ <ref bean="transactionManager"/>
+ </property>
+ <property name="target">
+ <bean class="org.raxa.module.raxacore.impl.DrugInfoServiceImpl">
+ <property name="DrugInfoDAO">
+ <bean class="org.raxa.module.raxacore.db.hibernate.HibernateDrugInfoDAO">
+ <property name="sessionFactory">
+ <ref bean="sessionFactory"/>
+ </property>
+ </bean>
+ </property>
+ </bean>
+ </property>
+ <property name="preInterceptors">
+ <ref bean="serviceInterceptors" />
+ </property>
+ <property name="transactionAttributeSource">
+ <bean class="org.springframework.transaction.annotation.AnnotationTransactionAttributeSource"/>
+ </property>
+ </bean>
+ </list>
+ </property>
+ </bean>
<bean id="org.raxa.module.raxacore.db.hibernate.HibernateDrugInventoryDAO" class="org.raxa.module.raxacore.db.hibernate.HibernateDrugInventoryDAO">
<property name="sessionFactory" ref="sessionFactory"/>
View
208 api/src/test/java/org/raxa/module/raxacore/db/hibernate/HibernateDrugGroupDAOTest.java
@@ -1,104 +1,104 @@
-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.DrugGroup;
-import org.raxa.module.raxacore.db.DrugGroupDAO;
-
-public class HibernateDrugGroupDAOTest 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 DrugGroupDAO dao = null;
-
- @Before
- public void setUp() throws Exception {
- executeDataSet(MODULE_TEST_DATA_XML);
- dao = (HibernateDrugGroupDAO) applicationContext
- .getBean("org.raxa.module.raxacore.db.hibernate.HibernateDrugGroupDAO");
- }
-
- @Test
- public void testSaveDrugGroup() {
- DrugGroup drugGroup = new DrugGroup();
- drugGroup.setName("TestDrugGroup3");
- drugGroup.setDescription("Third Test Drug Group");
- drugGroup.setCreator(Context.getUserContext().getAuthenticatedUser());
- drugGroup.setDateCreated(new java.util.Date());
- drugGroup.setUuid("68547121-1b70-465c-99ee-c9dfd95e7d30");
- drugGroup.setRetired(Boolean.FALSE);
- dao.saveDrugGroup(drugGroup);
- List<DrugGroup> result = dao.getDrugGroupByName("TestDrugGroup3");
- String name = result.get(0).getName();
- assertEquals(name, "TestDrugGroup3");
- }
-
- @Test
- public void testDeleteDrugGroup() {
- DrugGroup drugGroup = new DrugGroup();
- drugGroup.setId(2);
- drugGroup.setName("TestDrugGroup2");
- drugGroup.setDescription("Second Test Drug Group");
- drugGroup.setCreator(Context.getUserContext().getAuthenticatedUser());
- drugGroup.setDateCreated(new java.util.Date());
- drugGroup.setUuid("68547121-1b70-465e-99ee-c9dfd95e7d30");
- drugGroup.setRetired(Boolean.FALSE);
- dao.deleteDrugGroup(drugGroup);
- DrugGroup result = dao.getDrugGroup(2);
- assertEquals(null, result);
- }
-
- @Test
- public void testGetDrugGroup() {
- Integer drugGroupId = 1;
- DrugGroup result = dao.getDrugGroup(drugGroupId);
- String name = result.getName();
- assertEquals("TestDrugGroup1", name);
- }
-
- @Test
- public void testGetDrugGroupByUuid() {
- String uuid = "68547121-1b70-465e-99ee-c9dfd95e7d30";
- String result = dao.getDrugGroupByUuid(uuid).getName();
- assertEquals("TestDrugGroup2", result);
- }
-
- @Test
- public void testGetDrugGroupByName() {
- String name = "TestDrugGroup1";
- String result = dao.getDrugGroupByName(name).get(0).getName();
- assertEquals(name, result);
- }
-
- @Test
- public void testUpdateDrugGroup() {
- String nameSet = "NewDrugGroupName";
- String nameRetrieved;
- DrugGroup drugGroup = dao.getDrugGroup(1);
- drugGroup.setName(nameSet);
- dao.updateDrugGroup(drugGroup);
- nameRetrieved = dao.getDrugGroup(1).getName();
- assertEquals(nameSet, nameRetrieved);
- }
-}
+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.DrugGroup;
+import org.raxa.module.raxacore.db.DrugGroupDAO;
+
+public class HibernateDrugGroupDAOTest 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 DrugGroupDAO dao = null;
+
+ @Before
+ public void setUp() throws Exception {
+ executeDataSet(MODULE_TEST_DATA_XML);
+ dao = (HibernateDrugGroupDAO) applicationContext
+ .getBean("org.raxa.module.raxacore.db.hibernate.HibernateDrugGroupDAO");
+ }
+
+ @Test
+ public void testSaveDrugGroup() {
+ DrugGroup drugGroup = new DrugGroup();
+ drugGroup.setName("TestDrugGroup3");
+ drugGroup.setDescription("Third Test Drug Group");
+ drugGroup.setCreator(Context.getUserContext().getAuthenticatedUser());
+ drugGroup.setDateCreated(new java.util.Date());
+ drugGroup.setUuid("68547121-1b70-465c-99ee-c9dfd95e7d30");
+ drugGroup.setRetired(Boolean.FALSE);
+ dao.saveDrugGroup(drugGroup);
+ List<DrugGroup> result = dao.getDrugGroupByName("TestDrugGroup3");
+ String name = result.get(0).getName();
+ assertEquals(name, "TestDrugGroup3");
+ }
+
+ @Test
+ public void testDeleteDrugGroup() {
+ DrugGroup drugGroup = new DrugGroup();
+ drugGroup.setId(2);
+ drugGroup.setName("TestDrugGroup2");
+ drugGroup.setDescription("Second Test Drug Group");
+ drugGroup.setCreator(Context.getUserContext().getAuthenticatedUser());
+ drugGroup.setDateCreated(new java.util.Date());
+ drugGroup.setUuid("68547121-1b70-465e-99ee-c9dfd95e7d30");
+ drugGroup.setRetired(Boolean.FALSE);
+ dao.deleteDrugGroup(drugGroup);
+ DrugGroup result = dao.getDrugGroup(2);
+ assertEquals(null, result);
+ }
+
+ @Test
+ public void testGetDrugGroup() {
+ Integer drugGroupId = 1;
+ DrugGroup result = dao.getDrugGroup(drugGroupId);
+ String name = result.getName();
+ assertEquals("TestDrugGroup1", name);
+ }
+
+ @Test
+ public void testGetDrugGroupByUuid() {
+ String uuid = "68547121-1b70-465e-99ee-c9dfd95e7d30";
+ String result = dao.getDrugGroupByUuid(uuid).getName();
+ assertEquals("TestDrugGroup2", result);
+ }
+
+ @Test
+ public void testGetDrugGroupByName() {
+ String name = "TestDrugGroup1";
+ String result = dao.getDrugGroupByName(name).get(0).getName();
+ assertEquals(name, result);
+ }
+
+ @Test
+ public void testUpdateDrugGroup() {
+ String nameSet = "NewDrugGroupName";
+ String nameRetrieved;
+ DrugGroup drugGroup = dao.getDrugGroup(1);
+ drugGroup.setName(nameSet);
+ dao.updateDrugGroup(drugGroup);
+ nameRetrieved = dao.getDrugGroup(1).getName();
+ assertEquals(nameSet, nameRetrieved);
+ }
+}
View
148 api/src/test/java/org/raxa/module/raxacore/db/hibernate/HibernateDrugInfoDAOTest.java
@@ -0,0 +1,148 @@
+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.Drug;
+import org.openmrs.api.context.Context;
+import org.openmrs.test.BaseModuleContextSensitiveTest;
+import org.raxa.module.raxacore.DrugInfo;
+import org.raxa.module.raxacore.db.DrugInfoDAO;
+
+public class HibernateDrugInfoDAOTest 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 DrugInfoDAO dao = null;
+
+ @Before
+ public void setUp() throws Exception {
+ executeDataSet(MODULE_TEST_DATA_XML);
+ dao = (HibernateDrugInfoDAO) applicationContext
+ .getBean("org.raxa.module.raxacore.db.hibernate.HibernateDrugInfoDAO");
+ }
+
+ /**
+ * Test of saveDrugInfo method, of class HibernateDrugInfoDAO.
+ */
+ @Test
+ public void testSaveDrugInfo() {
+ DrugInfo drugInfo = new DrugInfo();
+ Drug drug = new Drug();
+ drug.setId(1);
+ drugInfo.setDrug(drug);
+ drugInfo.setDrugId(drug.getId());
+ drugInfo.setName("TestDrugInfo3");
+ drugInfo.setDescription("Third Test DrugInfo");
+ drugInfo.setCreator(Context.getUserContext().getAuthenticatedUser());
+ drugInfo.setDateCreated(new java.util.Date());
+ drugInfo.setUuid("68547121-1b70-465c-99ef-c9dfd95e7d30");
+ drugInfo.setRetired(Boolean.FALSE);
+ dao.saveDrugInfo(drugInfo);
+ DrugInfo result = dao.getDrugInfoByUuid("68547121-1b70-465c-99ef-c9dfd95e7d30");
+ String name = result.getName();
+ assertEquals(name, "TestDrugInfo3");
+ }
+
+ /**
+ * Test of deleteDrugInfo method, of class HibernateDrugInfoDAO.
+ */
+ @Test
+ public void testDeleteDrugInfo() {
+ DrugInfo drugInfo = new DrugInfo();
+ drugInfo.setId(2);
+ Drug drug = new Drug();
+ drug.setId(5);
+ drug.setDrugId(5);
+ drugInfo.setDrugId(5);
+ drugInfo.setDrug(drug);
+ drugInfo.setName("TestDrugInfo2");
+ drugInfo.setDescription("Second Test DrugInfo");
+ drugInfo.setCreator(Context.getUserContext().getAuthenticatedUser());
+ drugInfo.setDateCreated(new java.util.Date());
+ drugInfo.setUuid("68547121-1b70-465e-99ee-c9dfd95e7d30");
+ drugInfo.setRetired(Boolean.FALSE);
+ dao.deleteDrugInfo(drugInfo);
+ DrugInfo result = dao.getDrugInfo(2);
+ assertEquals(null, result);
+ }
+
+ /**
+ * Test of getDrugInfo method, of class HibernateDrugInfoDAO.
+ */
+ @Test
+ public void testGetDrugInfo() {
+ Integer drugInfoId = 1;
+ DrugInfo result = dao.getDrugInfo(drugInfoId);
+ String name = result.getName();
+ assertEquals("TestDrugInfo1", name);
+ }
+
+ /**
+ * Test of getDrugInfoByUuid method, of class HibernateDrugInfoDAO.
+ */
+ @Test
+ public void testGetDrugInfoByUuid() {
+ String uuid = "68547121-1b70-465e-99ee-c9dfd95e7d30";
+ String result = dao.getDrugInfoByUuid(uuid).getName();
+ assertEquals("TestDrugInfo2", result);
+ }
+
+ /**
+ * Test of getDrugInfoByName method, of class HibernateDrugInfoDAO.
+ */
+ @Test
+ public void testGetDrugInfoByName() {
+ String name = "TestDrugInfo1";
+ String result = dao.getDrugInfoByName(name).get(0).getName();
+ assertEquals(name, result);
+ }
+
+ /**
+ * Test of updateDrugInfo method, of class HibernateDrugInfoDAO.
+ */
+ @Test
+ public void testUpdateDrugInfo() {
+ DrugInfo drugInfo = dao.getDrugInfo(1);
+ drugInfo.setName("NewNameDrugInfo");
+ dao.updateDrugInfo(drugInfo);
+ String name = dao.getDrugInfo(1).getName();
+ assertEquals(name, "NewNameDrugInfo");
+ }
+
+ /**
+ * Test of getAllDrugInfo method, of class HibernateDrugInfoDAO.
+ */
+ @Test
+ public void testGetAllDrugInfo_shouldReturnUnretiredDrugInfo() {
+ List<DrugInfo> allDrugInfo = dao.getAllDrugInfo(false);
+ assertEquals(allDrugInfo.size(), 2);
+ }
+
+ /**
+ * Test of getAllDrugInfo method, of class HibernateDrugInfoDAO.
+ */
+ @Test
+ public void testGetAllDrugInfo_shouldReturnAllDrugInfoIncludingRetired() {
+ List<DrugInfo> allDrugInfo = dao.getAllDrugInfo(true);
+ assertEquals(allDrugInfo.size(), 3);
+ }
+}
View
444 api/src/test/java/org/raxa/module/raxacore/impl/DrugGroupServiceImplTest.java
@@ -1,222 +1,222 @@
-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.util.List;
-import static org.junit.Assert.*;
-import org.junit.Before;
-import org.junit.Test;
-import org.openmrs.User;
-import org.openmrs.api.APIAuthenticationException;
-import org.openmrs.api.context.Context;
-import org.openmrs.test.BaseModuleContextSensitiveTest;
-import org.raxa.module.raxacore.DrugGroup;
-import org.raxa.module.raxacore.DrugGroupService;
-
-/*
- * Testing the methods in DrugGroupServiceImpl
- */
-public class DrugGroupServiceImplTest 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 DrugGroupService s = null;
-
- @Before
- public void setUp() throws Exception {
- executeDataSet(MODULE_TEST_DATA_XML);
- s = Context.getService(DrugGroupService.class);
- //removing system developer role to test our privileges
- }
-
- @Test
- public void testSaveDrugGroupShouldUsePrivileges() throws Exception {
- Context.getUserContext().getAuthenticatedUser().removeRole(Context.getUserService().getRole("System Developer"));
- DrugGroup drugGroup = new DrugGroup();
- drugGroup.setName("TestDrugGroup3");
- drugGroup.setDescription("Third Test Drug Group");
- drugGroup.setCreator(Context.getUserContext().getAuthenticatedUser());
- drugGroup.setDateCreated(new java.util.Date());
- drugGroup.setUuid("68547121-1b70-465c-99ee-c9dfd95e7d30");
- drugGroup.setRetired(Boolean.FALSE);
- try {
- s.saveDrugGroup(drugGroup);
- // if we don't throw exception fail - no privileges required!
- fail("No privileges required for saveDrugGroup");
- }
- catch (APIAuthenticationException e) {
- Context.getUserContext().addProxyPrivilege("Add Drug Groups");
- Context.getUserContext().addProxyPrivilege("View Drug Groups");
- Context.getUserContext().addProxyPrivilege("View Users");
- s.saveDrugGroup(drugGroup);
- }
- }
-
- @Test
- public void testSaveDrugGroupShouldSaveDrugGroup() throws Exception {
- DrugGroup drugGroup = new DrugGroup();
- //NOTE: never set Id, will be generated automatically (when saving)
- drugGroup.setName("TestDrugGroup3");
- drugGroup.setDescription("Third Test Drug Group");
- drugGroup.setCreator(Context.getUserContext().getAuthenticatedUser());
- drugGroup.setDateCreated(new java.util.Date());
- drugGroup.setUuid("68547121-1b70-465c-99ee-c9dfd95e7d30");
- drugGroup.setRetired(Boolean.FALSE);
- s.saveDrugGroup(drugGroup);
- List<DrugGroup> result = s.getDrugGroupByName("TestDrugGroup3");
- String name = result.get(0).getName();
- assertEquals(name, "TestDrugGroup3");
- }
-
- @Test
- public void testGetDrugGroupShouldUsePrivileges() {
- Context.getUserContext().getAuthenticatedUser().removeRole(Context.getUserService().getRole("System Developer"));
- Context.getUserContext().removeProxyPrivilege("View Drug Groups");
- Integer drugGroupId = 1;
- DrugGroup result = null;
- try {
- result = s.getDrugGroup(drugGroupId);
- // if we don't throw exception fail - no privileges required!
- fail("No privileges required for getDrugGroup");
- }
- catch (APIAuthenticationException e) {
- Context.getUserContext().addProxyPrivilege("View Drug Groups");
- result = s.getDrugGroup(drugGroupId);
- }
- }
-
- @Test
- public void testGetDrugGroupShouldReturnDrugGroup() {
- Integer DrugGroupId = 1;
- DrugGroup result = s.getDrugGroup(DrugGroupId);
- String name = result.getName();
- assertEquals("TestDrugGroup1", name);
- }
-
- @Test
- public void testGetDrugGroupByNameShouldUsePrivileges() {
- Context.getUserContext().getAuthenticatedUser().removeRole(Context.getUserService().getRole("System Developer"));
- Context.getUserContext().removeProxyPrivilege("View Drug Groups");
- String name = "TestDrugGroup1";
- String result = null;
- try {
- result = s.getDrugGroupByName(name).get(0).getName();
- //if we don't throw exception fail - no privileges required!
- fail("No privileges required for getDrugGroupByName");
- }
- catch (APIAuthenticationException e) {
- Context.getUserContext().addProxyPrivilege("View Drug Groups");
- result = s.getDrugGroupByName(name).get(0).getName();
- }
- }
-
- @Test
- public void testGetDrugGroupByNameShouldReturnDrugGroup() {
- String name = "TestDrugGroup1";
- String result = s.getDrugGroupByName(name).get(0).getName();
- assertEquals(name, result);
- }
-
- @Test
- public void testGetDrugGroupByUuidShouldUsePrivileges() {
- Context.getUserContext().getAuthenticatedUser().removeRole(Context.getUserService().getRole("System Developer"));
- Context.getUserContext().removeProxyPrivilege("View Drug Groups");
- String uuid = "68547121-1b70-465e-99ee-c9dfd95e7d30";
- String result = null;
- try {
- result = s.getDrugGroupByUuid(uuid).getName();
- // if we don't throw exception fail - no privileges required!
- fail("No privileges required for getDrugGroupByUuid");
- }
- catch (APIAuthenticationException e) {
- Context.getUserContext().addProxyPrivilege("View Drug Groups");
- result = s.getDrugGroupByUuid(uuid).getName();
- }
- }
-
- @Test
- public void testGetDrugGroupByUuidShouldReturnDrugGroup() {
- String uuid = "68547121-1b70-465e-99ee-c9dfd95e7d30";
- String result = s.getDrugGroupByUuid(uuid).getName();
- assertEquals("TestDrugGroup2", result);
- }
-
- @Test
- public void testUpdateDrugGroupShouldUsePrivileges() {
- Context.getUserContext().getAuthenticatedUser().removeRole(Context.getUserService().getRole("System Developer"));
- Context.getUserContext().addProxyPrivilege("View Drug Groups");
- DrugGroup drugGroup = s.getDrugGroup(1);
- drugGroup.setName("NewNameDrugGroup