From 4202f189ac44bc1a20067ac3759c01398a4211f0 Mon Sep 17 00:00:00 2001 From: Abhis Date: Fri, 17 Aug 2012 19:49:02 +0530 Subject: [PATCH 1/6] GET working , POST not going to db --- .../hibernate/HibernateDrugInventoryDAO.java | 2 +- .../HibernateDrugPurchaseOrderDAO.java | 3 +- api/src/main/resources/liquibase.xml | 8 ++--- .../HibernateDrugInventoryDAOTest.java | 16 ++++----- .../controller/DrugInventoryController.java | 31 ++++++++++++----- .../DrugPurchaseOrderController.java | 34 +++++++++++++------ 6 files changed, 60 insertions(+), 34 deletions(-) diff --git a/api/src/main/java/org/raxa/module/raxacore/db/hibernate/HibernateDrugInventoryDAO.java b/api/src/main/java/org/raxa/module/raxacore/db/hibernate/HibernateDrugInventoryDAO.java index 63e4dee3fa..1166fcd08d 100644 --- a/api/src/main/java/org/raxa/module/raxacore/db/hibernate/HibernateDrugInventoryDAO.java +++ b/api/src/main/java/org/raxa/module/raxacore/db/hibernate/HibernateDrugInventoryDAO.java @@ -52,7 +52,7 @@ public DrugInventory getDrugInventoryByUuid(String uuid) { Criteria criteria = sessionFactory.getCurrentSession().createCriteria(DrugInventory.class); criteria.add(Restrictions.eq("uuid", uuid)); - System.out.println("///////"+criteria.uniqueResult()); + System.out.println("///////" + criteria.uniqueResult()); return (DrugInventory) criteria.uniqueResult(); } diff --git a/api/src/main/java/org/raxa/module/raxacore/db/hibernate/HibernateDrugPurchaseOrderDAO.java b/api/src/main/java/org/raxa/module/raxacore/db/hibernate/HibernateDrugPurchaseOrderDAO.java index de9486ad07..1429637a49 100644 --- a/api/src/main/java/org/raxa/module/raxacore/db/hibernate/HibernateDrugPurchaseOrderDAO.java +++ b/api/src/main/java/org/raxa/module/raxacore/db/hibernate/HibernateDrugPurchaseOrderDAO.java @@ -39,7 +39,8 @@ public void setSessionFactory(SessionFactory sessionFactory) { public DrugPurchaseOrder saveDrugPurchaseOrder(DrugPurchaseOrder drugPurchaseOrder) { - sessionFactory.getCurrentSession().saveOrUpdate(drugPurchaseOrder); + //sessionFactory.getCurrentSession().saveOrUpdate(drugPurchaseOrder); //did not work + sessionFactory.getCurrentSession().merge(drugPurchaseOrder); return drugPurchaseOrder; } diff --git a/api/src/main/resources/liquibase.xml b/api/src/main/resources/liquibase.xml index a1a288bfca..feb9183320 100644 --- a/api/src/main/resources/liquibase.xml +++ b/api/src/main/resources/liquibase.xml @@ -134,7 +134,7 @@ @@ -252,7 +252,7 @@ @@ -301,7 +301,7 @@ @@ -454,7 +454,7 @@ diff --git a/api/src/test/java/org/raxa/module/raxacore/db/hibernate/HibernateDrugInventoryDAOTest.java b/api/src/test/java/org/raxa/module/raxacore/db/hibernate/HibernateDrugInventoryDAOTest.java index 568a2a05b7..df338060e7 100644 --- a/api/src/test/java/org/raxa/module/raxacore/db/hibernate/HibernateDrugInventoryDAOTest.java +++ b/api/src/test/java/org/raxa/module/raxacore/db/hibernate/HibernateDrugInventoryDAOTest.java @@ -53,7 +53,6 @@ public void testSaveDrugInventory() { DrugInventory dInventory = new DrugInventory(); //NOTE: never set Id, will be generated automatically (when saving) - dInventory.setName("TestList6"); dInventory.setDescription("Third Test List"); dInventory.setCreator(Context.getUserContext().getAuthenticatedUser()); @@ -81,7 +80,7 @@ public void testSaveDrugInventory() { @Test public void testDeleteDrugInventory() { - DrugInventory dInventory=new DrugInventory(); + DrugInventory dInventory = new DrugInventory(); dInventory.setName("TestList6"); dInventory.setDescription("Third Test List"); dInventory.setCreator(Context.getUserContext().getAuthenticatedUser()); @@ -99,17 +98,17 @@ public void testDeleteDrugInventory() { dInventory.setLocationId(1); dInventory.setDrugPurchaseOrderId(14); dInventory.setOriginalQuantity(20); - + dao.deleteDrugInventory(dInventory); - DrugInventory result=dao.getDrugInventoryByUuid("68547121-1b70-465c-99ee-c9dfd95e7d34"); - assertEquals(result,null); + DrugInventory result = dao.getDrugInventoryByUuid("68547121-1b70-465c-99ee-c9dfd95e7d34"); + assertEquals(result, null); } @Test public void testGetDrugInventoryByUuid() { - DrugInventory result=dao.getDrugInventoryByUuid("68547121-1b70-465c-99ee-c9dfd95e7d36"); + DrugInventory result = dao.getDrugInventoryByUuid("68547121-1b70-465c-99ee-c9dfd95e7d36"); String name = result.getName(); assertEquals(name, "TestList6"); @@ -131,12 +130,11 @@ public void testGetAllDrugInventoriesByStatus() { @Test public void testUpdateDrugInventory() { - DrugInventory dInventory=dao.getDrugInventoryByUuid("68547121-1b70-465c-99ee-c9dfd95e7d36"); + DrugInventory dInventory = dao.getDrugInventoryByUuid("68547121-1b70-465c-99ee-c9dfd95e7d36"); dInventory.setName("new test list"); dao.updateDrugInventory(dInventory); - String name=dao.getDrugInventoryByUuid("68547121-1b70-465c-99ee-c9dfd95e7d36").getName(); + String name = dao.getDrugInventoryByUuid("68547121-1b70-465c-99ee-c9dfd95e7d36").getName(); assertEquals(name, "new test list"); - } diff --git a/omod/src/main/java/org/raxa/module/raxacore/web/v1_0/controller/DrugInventoryController.java b/omod/src/main/java/org/raxa/module/raxacore/web/v1_0/controller/DrugInventoryController.java index 1d563a1508..969a1b1e2e 100644 --- a/omod/src/main/java/org/raxa/module/raxacore/web/v1_0/controller/DrugInventoryController.java +++ b/omod/src/main/java/org/raxa/module/raxacore/web/v1_0/controller/DrugInventoryController.java @@ -21,6 +21,8 @@ import java.util.Date; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; + +import org.openmrs.User; import org.openmrs.api.context.Context; import org.openmrs.module.webservices.rest.SimpleObject; import org.openmrs.module.webservices.rest.web.RestUtil; @@ -69,9 +71,11 @@ public Object saveDrugInventory(@RequestBody SimpleObject post, HttpServletReque //drugInventory.setName(post.get("name").toString()); //drugInventory.setDescription(post.get("description").toString()); drugInventory.setUuid(post.get("uuid").toString()); - drugInventory.setDrugId(Integer.parseInt(post.get("DrugId").toString())); + drugInventory.setDrugId(Integer.parseInt(post.get("drugId").toString())); drugInventory.setQuantity(Integer.parseInt(post.get("quantity").toString())); drugInventory.setDateCreated(new Date()); + drugInventory.setCreator(new User()); + drugInventory.setRetired(false); if (post.get("originalQuantity") != null) { drugInventory.setOriginalQuantity(Integer.parseInt(post.get("originalQuantity").toString())); } @@ -93,14 +97,25 @@ public Object saveDrugInventory(@RequestBody SimpleObject post, HttpServletReque if (post.get("locationId") != null) { drugInventory.setLocationId(Integer.parseInt(post.get("locationId").toString())); } - if (post.get("drugPurchaseOrderId") != null) {} - - DrugInventory created = service.saveDrugInventory(drugInventory); - SimpleObject obj = new SimpleObject(); - obj.add("uuid", created.getUuid()); - obj.add("drugId", created.getDrugId()); - obj.add("quantity", created.getQuantity()); + if (post.get("drugPurchaseOrderId") != null) { + drugInventory.setDrugPurchaseOrderId(Integer.parseInt(post.get("drugPurchaseOrderId").toString())); + } + DrugInventory created; + SimpleObject obj = obj = new SimpleObject(); + ; + try { + created = service.saveDrugInventory(drugInventory); + + obj.add("uuid", created.getUuid()); + obj.add("drugId", created.getDrugId()); + obj.add("quantity", created.getQuantity()); + } + catch (Exception e) { + System.out.println("helllloooooo errroorr ocuuured"); + e.printStackTrace(); + } return RestUtil.created(response, obj); + } @RequestMapping(value = "/{uuid}", method = RequestMethod.GET) diff --git a/omod/src/main/java/org/raxa/module/raxacore/web/v1_0/controller/DrugPurchaseOrderController.java b/omod/src/main/java/org/raxa/module/raxacore/web/v1_0/controller/DrugPurchaseOrderController.java index d502640480..6a869e54dc 100644 --- a/omod/src/main/java/org/raxa/module/raxacore/web/v1_0/controller/DrugPurchaseOrderController.java +++ b/omod/src/main/java/org/raxa/module/raxacore/web/v1_0/controller/DrugPurchaseOrderController.java @@ -6,6 +6,8 @@ import java.util.Date; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; + +import org.openmrs.Provider; import org.openmrs.api.context.Context; import org.openmrs.module.webservices.rest.SimpleObject; import org.openmrs.module.webservices.rest.web.RestUtil; @@ -65,32 +67,42 @@ private String getResourceVersion() { @RequestMapping(method = RequestMethod.POST) @WSDoc("Save New DrugPurchaseOrder") @ResponseBody - public Object saveDrugPurchaseOrder(@RequestBody SimpleObject post, HttpServletRequest request, + public Object creatnewDrugPurchaseOrder(@RequestBody SimpleObject post, HttpServletRequest request, HttpServletResponse response) throws ResponseException { + initDrugPurchaseOrderController(); + DrugPurchaseOrder drugOrder = new DrugPurchaseOrder(); - drugOrder.setUuid(post.get("uuid").toString()); drugOrder.setName(post.get("name").toString()); + drugOrder.setProvider(Context.getProviderService().getProvider(Integer.parseInt(post.get("providerId").toString()))); + //drugOrder.setProviderId(new Integer(1)); + drugOrder.setProviderId(Integer.parseInt(post.get("providerId").toString())); drugOrder.setDateCreated(new Date()); - if (post.get("drugPurchaseOrderDate") != null) { - drugOrder.setDrugPurchaseOrderDate(new Date(post.get("drugPurchaseOrderDate").toString())); - } + drugOrder.setCreator(Context.getUserContext().getAuthenticatedUser()); - if (post.get("received") != null) { - drugOrder.setReceived((Boolean) post.get("received")); - } + drugOrder.setReceived(false); + + // + drugOrder.setRetired(false); if (post.get("locationId") != null) { drugOrder.setLocationId(Integer.parseInt(post.get("locationId").toString())); } - DrugPurchaseOrder created = service.saveDrugPurchaseOrder(drugOrder); + DrugPurchaseOrder created = null; SimpleObject obj = new SimpleObject(); + + created = service.saveDrugPurchaseOrder(drugOrder); + + System.out.println("uuid is" + drugOrder.getUuid()); + obj.add("uuid", created.getUuid()); obj.add("name", created.getName()); - obj.add("providerId", created.getDateCreated()); - return RestUtil.noContent(response); + obj.add("providerId", created.getProviderId()); + + return RestUtil.created(response, obj); + } // From 7747fd8c5f92488e71e765c8b0eeabe67d21fc49 Mon Sep 17 00:00:00 2001 From: Abhis Date: Fri, 17 Aug 2012 19:56:10 +0530 Subject: [PATCH 2/6] GET working post not going to db --- .../raxacore/web/v1_0/controller/DrugInventoryController.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/omod/src/main/java/org/raxa/module/raxacore/web/v1_0/controller/DrugInventoryController.java b/omod/src/main/java/org/raxa/module/raxacore/web/v1_0/controller/DrugInventoryController.java index 969a1b1e2e..2d92e7088d 100644 --- a/omod/src/main/java/org/raxa/module/raxacore/web/v1_0/controller/DrugInventoryController.java +++ b/omod/src/main/java/org/raxa/module/raxacore/web/v1_0/controller/DrugInventoryController.java @@ -72,6 +72,9 @@ public Object saveDrugInventory(@RequestBody SimpleObject post, HttpServletReque //drugInventory.setDescription(post.get("description").toString()); drugInventory.setUuid(post.get("uuid").toString()); drugInventory.setDrugId(Integer.parseInt(post.get("drugId").toString())); + + drugInventory.setDrug(Context.getConceptService().getDrug(Integer.parseInt(post.get("drugId").toString()))); + drugInventory.setQuantity(Integer.parseInt(post.get("quantity").toString())); drugInventory.setDateCreated(new Date()); drugInventory.setCreator(new User()); From 126b0046f898fe6023f90cad378837ffb0971609 Mon Sep 17 00:00:00 2001 From: Abhis Date: Tue, 4 Sep 2012 17:00:00 +0530 Subject: [PATCH 3/6] Backend complete and working --- .../org/raxa/module/raxacore/Billing.java | 104 ++++ .../org/raxa/module/raxacore/BillingItem.java | 174 ++++++ .../raxacore/BillingItemAdjustment.java | 97 ++++ .../BillingItemAdjustmentService.java | 40 ++ .../module/raxacore/BillingItemService.java | 49 ++ .../raxa/module/raxacore/BillingService.java | 42 ++ .../raxa/module/raxacore/db/BillingDAO.java | 38 ++ .../raxacore/db/BillingItemAdjustmentDAO.java | 38 ++ .../module/raxacore/db/BillingItemDAO.java | 45 ++ .../db/hibernate/HibernateBillingDAO.java | 98 ++++ .../HibernateBillingItemAdjustmentDAO.java | 88 ++++ .../db/hibernate/HibernateBillingItemDAO.java | 123 +++++ .../BillingItemAdjustmentServiceImpl.java | 78 +++ .../raxacore/impl/BillingItemServiceImpl.java | 90 ++++ .../raxacore/impl/BillingServiceImpl.java | 80 +++ .../main/resources/RaxacoreBilling.hbm.xml | 33 ++ .../resources/RaxacoreBillingItem.hbm.xml | 42 ++ .../RaxacoreBillingItemAdjustment.hbm.xml | 31 ++ api/src/main/resources/liquibase.xml | 497 ++++++++++++++++++ .../resources/moduleApplicationContext.xml | 135 ++++- omod/src/main/resources/config.xml | 8 +- 21 files changed, 1911 insertions(+), 19 deletions(-) create mode 100644 api/src/main/java/org/raxa/module/raxacore/Billing.java create mode 100644 api/src/main/java/org/raxa/module/raxacore/BillingItem.java create mode 100644 api/src/main/java/org/raxa/module/raxacore/BillingItemAdjustment.java create mode 100644 api/src/main/java/org/raxa/module/raxacore/BillingItemAdjustmentService.java create mode 100644 api/src/main/java/org/raxa/module/raxacore/BillingItemService.java create mode 100644 api/src/main/java/org/raxa/module/raxacore/BillingService.java create mode 100644 api/src/main/java/org/raxa/module/raxacore/db/BillingDAO.java create mode 100644 api/src/main/java/org/raxa/module/raxacore/db/BillingItemAdjustmentDAO.java create mode 100644 api/src/main/java/org/raxa/module/raxacore/db/BillingItemDAO.java create mode 100644 api/src/main/java/org/raxa/module/raxacore/db/hibernate/HibernateBillingDAO.java create mode 100644 api/src/main/java/org/raxa/module/raxacore/db/hibernate/HibernateBillingItemAdjustmentDAO.java create mode 100644 api/src/main/java/org/raxa/module/raxacore/db/hibernate/HibernateBillingItemDAO.java create mode 100644 api/src/main/java/org/raxa/module/raxacore/impl/BillingItemAdjustmentServiceImpl.java create mode 100644 api/src/main/java/org/raxa/module/raxacore/impl/BillingItemServiceImpl.java create mode 100644 api/src/main/java/org/raxa/module/raxacore/impl/BillingServiceImpl.java create mode 100644 api/src/main/resources/RaxacoreBilling.hbm.xml create mode 100644 api/src/main/resources/RaxacoreBillingItem.hbm.xml create mode 100644 api/src/main/resources/RaxacoreBillingItemAdjustment.hbm.xml diff --git a/api/src/main/java/org/raxa/module/raxacore/Billing.java b/api/src/main/java/org/raxa/module/raxacore/Billing.java new file mode 100644 index 0000000000..4802209ab1 --- /dev/null +++ b/api/src/main/java/org/raxa/module/raxacore/Billing.java @@ -0,0 +1,104 @@ +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.Provider; +import org.openmrs.Patient; + +/** + * PatientList stores the data needed to lists patients for registration, screener, etc. + */ +public class Billing extends BaseOpenmrsMetadata implements Serializable { + + private Integer billId; + + private String status; + + private Integer providerId; + + private Integer patientId; + + private Provider provider; + + private Patient patient; + + public Billing() { + + } + + public Integer getBillId() { + return billId; + } + + public void setBillId(Integer billId) { + this.billId = billId; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + public Integer getProviderId() { + return providerId; + } + + public void setProviderId(Integer providerId) { + this.providerId = providerId; + } + + public Integer getPatientId() { + return patientId; + } + + public void setPatientId(Integer patientId) { + this.patientId = patientId; + } + + public Provider getProvider() { + return provider; + } + + public void setProvider(Provider provider) { + this.provider = provider; + } + + public Patient getPatient() { + return patient; + } + + public void setPatient(Patient patient) { + this.patient = patient; + } + + @Override + public Integer getId() { + // TODO Auto-generated method stub + return null; + } + + @Override + public void setId(Integer arg0) { + // TODO Auto-generated method stub + + } + +} diff --git a/api/src/main/java/org/raxa/module/raxacore/BillingItem.java b/api/src/main/java/org/raxa/module/raxacore/BillingItem.java new file mode 100644 index 0000000000..cf7425958a --- /dev/null +++ b/api/src/main/java/org/raxa/module/raxacore/BillingItem.java @@ -0,0 +1,174 @@ +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.Concept; +import org.openmrs.Encounter; +import org.openmrs.Order; +import org.openmrs.Provider; + +/** + * BillingItem stores the data of items in the bill. + */ +public class BillingItem extends BaseOpenmrsMetadata implements Serializable { + + private Integer billItemId; + + private Integer billId; + + private Integer providerId; + + private Integer conceptId; + + private Integer encounterId; + + private Integer orderId; + + private Integer quantity; + + private Integer value; + + private Provider provider; + + private Concept concept; + + private Encounter encounter; + + private Order order; + + private Billing bill; + + public BillingItem() { + + } + + public Integer getbillItemId() { + return billItemId; + } + + public void setbillItemId(Integer billItemId) { + this.billItemId = billItemId; + } + + public Integer getBillId() { + return billId; + } + + public void setBillId(Integer billId) { + this.billId = billId; + } + + public Integer getConceptId() { + return conceptId; + } + + public void setConceptId(Integer conceptId) { + this.conceptId = conceptId; + } + + public Integer getEncounterId() { + return encounterId; + } + + public void setEncounterId(Integer encounterId) { + this.encounterId = encounterId; + } + + public Integer getOrderId() { + return orderId; + } + + public void setOrderId(Integer orderId) { + this.orderId = orderId; + } + + public Integer getValue() { + return value; + } + + public void setValue(Integer value) { + this.value = value; + } + + public Integer getQuantity() { + return quantity; + } + + public void setQuantity(Integer quantity) { + this.quantity = quantity; + } + + public Integer getProviderId() { + return providerId; + } + + public void setProviderId(Integer providerId) { + this.providerId = providerId; + } + + public Provider getProvider() { + return provider; + } + + public void setProvider(Provider provider) { + this.provider = provider; + } + + public Concept getConcept() { + return concept; + } + + public void setConcept(Concept concept) { + this.concept = concept; + } + + public Encounter getEncounter() { + return encounter; + } + + public void setEncounter(Encounter encounter) { + this.encounter = encounter; + } + + public Order getOrder() { + return order; + } + + public void setOrder(Order order) { + this.order = order; + } + + public Billing getBill() { + return bill; + } + + public void setBill(Billing bill) { + this.bill = bill; + } + + @Override + public Integer getId() { + return getbillItemId(); + } + + @Override + public void setId(Integer arg0) { + setbillItemId(arg0); + } + +} diff --git a/api/src/main/java/org/raxa/module/raxacore/BillingItemAdjustment.java b/api/src/main/java/org/raxa/module/raxacore/BillingItemAdjustment.java new file mode 100644 index 0000000000..5f2fa54aae --- /dev/null +++ b/api/src/main/java/org/raxa/module/raxacore/BillingItemAdjustment.java @@ -0,0 +1,97 @@ +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.Concept; +import org.openmrs.Encounter; +import org.openmrs.Order; +import org.openmrs.Provider; + +/** + * BillingItem stores the data of items in the bill. + */ + +public class BillingItemAdjustment extends BaseOpenmrsMetadata implements Serializable { + + private Integer billItemAdjustmentId; + + private Integer billItemId; + + private String reason; + + private Integer value; + + private BillingItem billItem; + + public BillingItemAdjustment() { + + } + + public Integer getBillItemAdjustmentId() { + return billItemAdjustmentId; + } + + public void setBillItemAdjustmentId(Integer billItemAdjustmentId) { + this.billItemAdjustmentId = billItemAdjustmentId; + } + + public Integer getBillItemId() { + return billItemId; + } + + public void setBillItemId(Integer billItemId) { + this.billItemId = billItemId; + } + + public String getReason() { + return reason; + } + + public void setReason(String reason) { + this.reason = reason; + } + + public Integer getValue() { + return value; + } + + public void setValue(Integer value) { + this.value = value; + } + + public BillingItem getBillItem() { + return billItem; + } + + public void setBillItem(BillingItem billitem) { + this.billItem = billitem; + } + + @Override + public Integer getId() { + return getBillItemAdjustmentId(); + + } + + @Override + public void setId(Integer arg0) { + setBillItemAdjustmentId(arg0); + + } + +} diff --git a/api/src/main/java/org/raxa/module/raxacore/BillingItemAdjustmentService.java b/api/src/main/java/org/raxa/module/raxacore/BillingItemAdjustmentService.java new file mode 100644 index 0000000000..3a8a7be73d --- /dev/null +++ b/api/src/main/java/org/raxa/module/raxacore/BillingItemAdjustmentService.java @@ -0,0 +1,40 @@ +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.api.db.DAOException; +import org.openmrs.util.PrivilegeConstants; +import org.raxa.module.raxacore.db.DrugInventoryDAO; +import org.springframework.transaction.annotation.Transactional; + +public interface BillingItemAdjustmentService extends OpenmrsService { + + BillingItemAdjustment saveBillingItemAdjustment(BillingItemAdjustment adjustment) throws DAOException; + + void deleteBillingItemAdjustment(BillingItemAdjustment adjustment) throws DAOException; + + BillingItemAdjustment getBillingItemAdjustmentByUuid(String uuid); + + List getAllBillingItemAdjustments() throws DAOException; + + BillingItemAdjustment updateBillingItemAdjustment(BillingItemAdjustment adjustment); + + List getAllBillingItemAdjustmentsByBillingItem(Integer billingitemid); +} diff --git a/api/src/main/java/org/raxa/module/raxacore/BillingItemService.java b/api/src/main/java/org/raxa/module/raxacore/BillingItemService.java new file mode 100644 index 0000000000..4189a3d913 --- /dev/null +++ b/api/src/main/java/org/raxa/module/raxacore/BillingItemService.java @@ -0,0 +1,49 @@ +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.api.db.DAOException; +import org.openmrs.util.PrivilegeConstants; +import org.raxa.module.raxacore.db.DrugInventoryDAO; +import org.springframework.transaction.annotation.Transactional; + +public interface BillingItemService extends OpenmrsService { + + BillingItem saveBillingItem(BillingItem item) throws DAOException; + + void deleteBillingItem(BillingItem item) throws DAOException; + + BillingItem getBillingItemByUuid(String uuid); + + List getAllBillingItems() throws DAOException; + + List getAllBillingItemsByBill(Integer billid); + + BillingItem updateBillingItem(BillingItem item); + + List getAllBillingItemsByProvider(Integer providerId); + + List getAllBillingItemsByEncounter(Integer encounterId); + + List getAllBillingItemsByConcept(Integer conceptId); + + List getAllBillingItemsByOrder(Integer orderId); + +} diff --git a/api/src/main/java/org/raxa/module/raxacore/BillingService.java b/api/src/main/java/org/raxa/module/raxacore/BillingService.java new file mode 100644 index 0000000000..ef5387776a --- /dev/null +++ b/api/src/main/java/org/raxa/module/raxacore/BillingService.java @@ -0,0 +1,42 @@ +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.api.db.DAOException; +import org.openmrs.util.PrivilegeConstants; +import org.raxa.module.raxacore.db.DrugInventoryDAO; +import org.springframework.transaction.annotation.Transactional; + +public interface BillingService extends OpenmrsService { + + Billing saveBill(Billing bill) throws DAOException; + + void deleteBill(Billing bill) throws DAOException; + + Billing getBillByPatientUuid(String uuid); + + List getAllBills() throws DAOException; + + List getAllBillsByStatus(String status); + + Billing updateBill(Billing bill); + + List getAllBillsByProvider(Integer providerId); +} diff --git a/api/src/main/java/org/raxa/module/raxacore/db/BillingDAO.java b/api/src/main/java/org/raxa/module/raxacore/db/BillingDAO.java new file mode 100644 index 0000000000..994f6b2815 --- /dev/null +++ b/api/src/main/java/org/raxa/module/raxacore/db/BillingDAO.java @@ -0,0 +1,38 @@ +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.Billing; + +public interface BillingDAO { + + public Billing saveBill(Billing bill) throws DAOException; + + public void deleteBill(Billing bill) throws DAOException; + + public Billing getBillByPatientUuid(String uuid); + + public List getAllBills() throws DAOException; + + public List getAllBillsByStatus(String status); + + public Billing updateBill(Billing bill); + + public List getAllBillsByProvider(Integer providerId); +} diff --git a/api/src/main/java/org/raxa/module/raxacore/db/BillingItemAdjustmentDAO.java b/api/src/main/java/org/raxa/module/raxacore/db/BillingItemAdjustmentDAO.java new file mode 100644 index 0000000000..abeccf32da --- /dev/null +++ b/api/src/main/java/org/raxa/module/raxacore/db/BillingItemAdjustmentDAO.java @@ -0,0 +1,38 @@ +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.BillingItemAdjustment; + +public interface BillingItemAdjustmentDAO { + + BillingItemAdjustment saveBillingItemAdjustment(BillingItemAdjustment adjustment) throws DAOException; + + void deleteBillingItemAdjustment(BillingItemAdjustment adjustment) throws DAOException; + + BillingItemAdjustment getBillingItemAdjustmentByUuid(String uuid); + + List getAllBillingItemAdjustments() throws DAOException; + + List getAllBillingItemAdjustmentsByReason(String reason); + + BillingItemAdjustment updateBillingItemAdjustment(BillingItemAdjustment adjustment); + + List getAllBillingItemAdjustmentsByBillingItem(Integer billingitemid); +} diff --git a/api/src/main/java/org/raxa/module/raxacore/db/BillingItemDAO.java b/api/src/main/java/org/raxa/module/raxacore/db/BillingItemDAO.java new file mode 100644 index 0000000000..9b1a3b6069 --- /dev/null +++ b/api/src/main/java/org/raxa/module/raxacore/db/BillingItemDAO.java @@ -0,0 +1,45 @@ +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.BillingItem; + +public interface BillingItemDAO { + + BillingItem saveBillingItem(BillingItem item) throws DAOException; + + void deleteBillingItem(BillingItem item) throws DAOException; + + BillingItem getBillingItemByUuid(String uuid); + + List getAllBillingItems() throws DAOException; + + List getAllBillingItemsByBill(Integer billid); + + BillingItem updateBillingItem(BillingItem item); + + List getAllBillingItemsByProvider(Integer providerId); + + List getAllBillingItemsByEncounter(Integer encounterId); + + List getAllBillingItemsByConcept(Integer conceptId); + + List getAllBillingItemsByOrder(Integer orderId); + +} diff --git a/api/src/main/java/org/raxa/module/raxacore/db/hibernate/HibernateBillingDAO.java b/api/src/main/java/org/raxa/module/raxacore/db/hibernate/HibernateBillingDAO.java new file mode 100644 index 0000000000..94197e3626 --- /dev/null +++ b/api/src/main/java/org/raxa/module/raxacore/db/hibernate/HibernateBillingDAO.java @@ -0,0 +1,98 @@ +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.Billing; + +import org.raxa.module.raxacore.db.BillingDAO; +import org.springframework.transaction.annotation.Transactional; + +public class HibernateBillingDAO implements BillingDAO { + + protected final Log log = LogFactory.getLog(getClass()); + + private SessionFactory sessionFactory; + + public void setSessionFactory(SessionFactory sessionFactory) { + this.sessionFactory = sessionFactory; + } + + @Transactional + public Billing saveBill(Billing bill) throws DAOException { + + sessionFactory.getCurrentSession().saveOrUpdate(bill); + return bill; + } + + @Transactional + public void deleteBill(Billing bill) throws DAOException { + + sessionFactory.getCurrentSession().delete(bill); + } + + @Transactional + public Billing getBillByPatientUuid(String uuid) { + + Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Billing.class); + criteria.add(Restrictions.eq("uuid", uuid)); + + return (Billing) criteria.uniqueResult(); + } + + @Transactional + public List getAllBills() throws DAOException { + + Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Billing.class); + return criteria.list(); + + } + + @Transactional + public List getAllBillsByStatus(String status) { + + Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Billing.class); + criteria.add(Restrictions.eq("status", status)); + List bills = new ArrayList(); + bills.addAll(criteria.list()); + return bills; + + } + + @Transactional + public Billing updateBill(Billing bill) { + + sessionFactory.getCurrentSession().update(bill); + return bill; + } + + @Transactional + public List getAllBillsByProvider(Integer providerId) { + + Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Billing.class); + criteria.add(Restrictions.eq("providerId", providerId)); + List bills = new ArrayList(); + bills.addAll(criteria.list()); + return bills; + } + +} diff --git a/api/src/main/java/org/raxa/module/raxacore/db/hibernate/HibernateBillingItemAdjustmentDAO.java b/api/src/main/java/org/raxa/module/raxacore/db/hibernate/HibernateBillingItemAdjustmentDAO.java new file mode 100644 index 0000000000..6f9187b87f --- /dev/null +++ b/api/src/main/java/org/raxa/module/raxacore/db/hibernate/HibernateBillingItemAdjustmentDAO.java @@ -0,0 +1,88 @@ +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.BillingItemAdjustment; + +import org.raxa.module.raxacore.db.BillingItemAdjustmentDAO; +import org.springframework.transaction.annotation.Transactional; + +public class HibernateBillingItemAdjustmentDAO implements BillingItemAdjustmentDAO { + + protected final Log log = LogFactory.getLog(getClass()); + + private SessionFactory sessionFactory; + + public void setSessionFactory(SessionFactory sessionFactory) { + this.sessionFactory = sessionFactory; + } + + @Transactional + public BillingItemAdjustment saveBillingItemAdjustment(BillingItemAdjustment adjustment) { + sessionFactory.getCurrentSession().saveOrUpdate(adjustment); + return adjustment; + } + + @Transactional + public void deleteBillingItemAdjustment(BillingItemAdjustment adjustment) { + sessionFactory.getCurrentSession().delete(adjustment); + } + + @Transactional + public BillingItemAdjustment getBillingItemAdjustmentByUuid(String uuid) { + Criteria criteria = sessionFactory.getCurrentSession().createCriteria(BillingItemAdjustment.class); + criteria.add(Restrictions.eq("uuid", uuid)); + + return (BillingItemAdjustment) criteria.uniqueResult(); + } + + @Transactional + public List getAllBillingItemAdjustments() { + Criteria criteria = sessionFactory.getCurrentSession().createCriteria(BillingItemAdjustment.class); + return criteria.list(); + } + + @Transactional + public List getAllBillingItemAdjustmentsByReason(String reason) { + Criteria criteria = sessionFactory.getCurrentSession().createCriteria(BillingItemAdjustment.class); + criteria.add(Restrictions.eq("reason", reason)); + List bills = new ArrayList(); + bills.addAll(criteria.list()); + return bills; + } + + @Transactional + public BillingItemAdjustment updateBillingItemAdjustment(BillingItemAdjustment adjustment) { + sessionFactory.getCurrentSession().update(adjustment); + return adjustment; + } + + @Transactional + public List getAllBillingItemAdjustmentsByBillingItem(Integer billingitemid) { + Criteria criteria = sessionFactory.getCurrentSession().createCriteria(BillingItemAdjustment.class); + criteria.add(Restrictions.eq("billItemId", billingitemid)); + List bills = new ArrayList(); + bills.addAll(criteria.list()); + return bills; + } +} diff --git a/api/src/main/java/org/raxa/module/raxacore/db/hibernate/HibernateBillingItemDAO.java b/api/src/main/java/org/raxa/module/raxacore/db/hibernate/HibernateBillingItemDAO.java new file mode 100644 index 0000000000..8fa59ac556 --- /dev/null +++ b/api/src/main/java/org/raxa/module/raxacore/db/hibernate/HibernateBillingItemDAO.java @@ -0,0 +1,123 @@ +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.Billing; +import org.raxa.module.raxacore.BillingItem; + +import org.raxa.module.raxacore.db.BillingDAO; +import org.raxa.module.raxacore.db.BillingItemDAO; +import org.springframework.transaction.annotation.Transactional; + +public class HibernateBillingItemDAO implements BillingItemDAO { + + protected final Log log = LogFactory.getLog(getClass()); + + private SessionFactory sessionFactory; + + public void setSessionFactory(SessionFactory sessionFactory) { + this.sessionFactory = sessionFactory; + } + + @Transactional + public BillingItem saveBillingItem(BillingItem item) { + sessionFactory.getCurrentSession().saveOrUpdate(item); + return item; + + } + + @Transactional + public void deleteBillingItem(BillingItem item) { + sessionFactory.getCurrentSession().delete(item); + } + + @Transactional + public BillingItem getBillingItemByUuid(String uuid) + + { + Criteria criteria = sessionFactory.getCurrentSession().createCriteria(BillingItem.class); + criteria.add(Restrictions.eq("uuid", uuid)); + + return (BillingItem) criteria.uniqueResult(); + } + + @Transactional + public List getAllBillingItems() { + Criteria criteria = sessionFactory.getCurrentSession().createCriteria(BillingItem.class); + return criteria.list(); + } + + @Transactional + public List getAllBillingItemsByBill(Integer billid) { + Criteria criteria = sessionFactory.getCurrentSession().createCriteria(BillingItem.class); + criteria.add(Restrictions.eq("billId", billid)); + List bills = new ArrayList(); + bills.addAll(criteria.list()); + return bills; + } + + @Transactional + public BillingItem updateBillingItem(BillingItem item) { + sessionFactory.getCurrentSession().update(item); + return item; + } + + @Transactional + public List getAllBillingItemsByProvider(Integer providerId) { + + Criteria criteria = sessionFactory.getCurrentSession().createCriteria(BillingItem.class); + criteria.add(Restrictions.eq("providerId", providerId)); + List bills = new ArrayList(); + bills.addAll(criteria.list()); + return bills; + + } + + @Transactional + public List getAllBillingItemsByEncounter(Integer encounterId) { + Criteria criteria = sessionFactory.getCurrentSession().createCriteria(BillingItem.class); + criteria.add(Restrictions.eq("encounterId", encounterId)); + List bills = new ArrayList(); + bills.addAll(criteria.list()); + return bills; + } + + @Transactional + public List getAllBillingItemsByConcept(Integer conceptId) { + Criteria criteria = sessionFactory.getCurrentSession().createCriteria(BillingItem.class); + criteria.add(Restrictions.eq("conceptId", conceptId)); + List bills = new ArrayList(); + bills.addAll(criteria.list()); + return bills; + } + + @Transactional + public List getAllBillingItemsByOrder(Integer orderId) { + Criteria criteria = sessionFactory.getCurrentSession().createCriteria(BillingItem.class); + criteria.add(Restrictions.eq("orderId", orderId)); + List bills = new ArrayList(); + bills.addAll(criteria.list()); + return bills; + } + +} diff --git a/api/src/main/java/org/raxa/module/raxacore/impl/BillingItemAdjustmentServiceImpl.java b/api/src/main/java/org/raxa/module/raxacore/impl/BillingItemAdjustmentServiceImpl.java new file mode 100644 index 0000000000..2268ff5056 --- /dev/null +++ b/api/src/main/java/org/raxa/module/raxacore/impl/BillingItemAdjustmentServiceImpl.java @@ -0,0 +1,78 @@ +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.BillingItemAdjustment; +import org.raxa.module.raxacore.BillingItemAdjustmentService; +import org.raxa.module.raxacore.db.BillingItemAdjustmentDAO; + +public class BillingItemAdjustmentServiceImpl implements BillingItemAdjustmentService { + + private BillingItemAdjustmentDAO dao; + + private Log log = LogFactory.getLog(this.getClass()); + + public void setBillingItemAdjustmentDAO(BillingItemAdjustmentDAO dao) { + this.dao = dao; + + } + + public void onShutdown() { + + log.info("Starting drug purchase order service"); + } + + public void onStartup() { + + log.info("Starting drug purchase order service"); + } + + public BillingItemAdjustment saveBillingItemAdjustment(BillingItemAdjustment adjustment) { + return dao.saveBillingItemAdjustment(adjustment); + } + + public void deleteBillingItemAdjustment(BillingItemAdjustment adjustment) { + dao.deleteBillingItemAdjustment(adjustment); + } + + public BillingItemAdjustment getBillingItemAdjustmentByUuid(String uuid) { + return dao.getBillingItemAdjustmentByUuid(uuid); + } + + public List getAllBillingItemAdjustments() { + return dao.getAllBillingItemAdjustments(); + } + + public List getAllBillingItemAdjustmentsByReason(String reason) { + return dao.getAllBillingItemAdjustmentsByReason(reason); + } + + public BillingItemAdjustment updateBillingItemAdjustment(BillingItemAdjustment adjustment) { + return dao.updateBillingItemAdjustment(adjustment); + } + + public List getAllBillingItemAdjustmentsByBillingItem(Integer billingitemid) { + return dao.getAllBillingItemAdjustmentsByBillingItem(billingitemid); + } +} diff --git a/api/src/main/java/org/raxa/module/raxacore/impl/BillingItemServiceImpl.java b/api/src/main/java/org/raxa/module/raxacore/impl/BillingItemServiceImpl.java new file mode 100644 index 0000000000..d4af9fd9df --- /dev/null +++ b/api/src/main/java/org/raxa/module/raxacore/impl/BillingItemServiceImpl.java @@ -0,0 +1,90 @@ +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 org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.raxa.module.raxacore.Billing; +import org.raxa.module.raxacore.BillingItem; +import org.raxa.module.raxacore.BillingItemService; +import org.raxa.module.raxacore.BillingService; +import org.raxa.module.raxacore.db.BillingItemDAO; + +public class BillingItemServiceImpl implements BillingItemService { + + private BillingItemDAO dao; + + private Log log = LogFactory.getLog(this.getClass()); + + public void setBillingItemDAO(BillingItemDAO dao) { + this.dao = dao; + + } + + public void onShutdown() { + + log.info("Starting drug purchase order service"); + } + + public void onStartup() { + + log.info("Starting drug purchase order service"); + } + + public BillingItem saveBillingItem(BillingItem item) { + return dao.saveBillingItem(item); + } + + public void deleteBillingItem(BillingItem item) { + dao.deleteBillingItem(item); + } + + public BillingItem getBillingItemByUuid(String uuid) + + { + return dao.getBillingItemByUuid(uuid); + } + + public List getAllBillingItems() { + return dao.getAllBillingItems(); + } + + public List getAllBillingItemsByBill(Integer billid) { + return dao.getAllBillingItemsByBill(billid); + } + + public BillingItem updateBillingItem(BillingItem item) { + return dao.updateBillingItem(item); + } + + public List getAllBillingItemsByProvider(Integer providerId) { + return dao.getAllBillingItemsByProvider(providerId); + } + + public List getAllBillingItemsByEncounter(Integer encounterId) { + return dao.getAllBillingItemsByEncounter(encounterId); + } + + public List getAllBillingItemsByConcept(Integer conceptId) { + return dao.getAllBillingItemsByConcept(conceptId); + } + + public List getAllBillingItemsByOrder(Integer orderId) { + return dao.getAllBillingItemsByOrder(orderId); + } + +} diff --git a/api/src/main/java/org/raxa/module/raxacore/impl/BillingServiceImpl.java b/api/src/main/java/org/raxa/module/raxacore/impl/BillingServiceImpl.java new file mode 100644 index 0000000000..3860c06ab5 --- /dev/null +++ b/api/src/main/java/org/raxa/module/raxacore/impl/BillingServiceImpl.java @@ -0,0 +1,80 @@ +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.Patient; +import org.openmrs.api.context.Context; +import org.raxa.module.raxacore.Billing; +import org.raxa.module.raxacore.BillingService; +import org.raxa.module.raxacore.db.BillingDAO; + +public class BillingServiceImpl implements BillingService { + + private BillingDAO dao; + + private Log log = LogFactory.getLog(this.getClass()); + + public void setBillingDAO(BillingDAO dao) { + this.dao = dao; + + } + + public void onShutdown() { + + log.info("Starting drug purchase order service"); + } + + public void onStartup() { + + log.info("Starting drug purchase order service"); + } + + public Billing saveBill(Billing bill) { + return dao.saveBill(bill); + } + + public void deleteBill(Billing bill) { + dao.deleteBill(bill); + } + + public Billing getBillByPatientUuid(String uuid) { + return dao.getBillByPatientUuid(uuid); + } + + public List getAllBills() { + return dao.getAllBills(); + } + + public List getAllBillsByStatus(String status) { + return dao.getAllBillsByStatus(status); + } + + public Billing updateBill(Billing bill) { + return dao.updateBill(bill); + } + + public List getAllBillsByProvider(Integer providerId) { + return dao.getAllBillsByProvider(providerId); + } +} diff --git a/api/src/main/resources/RaxacoreBilling.hbm.xml b/api/src/main/resources/RaxacoreBilling.hbm.xml new file mode 100644 index 0000000000..627f94d748 --- /dev/null +++ b/api/src/main/resources/RaxacoreBilling.hbm.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/api/src/main/resources/RaxacoreBillingItem.hbm.xml b/api/src/main/resources/RaxacoreBillingItem.hbm.xml new file mode 100644 index 0000000000..60b1471e83 --- /dev/null +++ b/api/src/main/resources/RaxacoreBillingItem.hbm.xml @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/api/src/main/resources/RaxacoreBillingItemAdjustment.hbm.xml b/api/src/main/resources/RaxacoreBillingItemAdjustment.hbm.xml new file mode 100644 index 0000000000..f646247fa9 --- /dev/null +++ b/api/src/main/resources/RaxacoreBillingItemAdjustment.hbm.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/api/src/main/resources/liquibase.xml b/api/src/main/resources/liquibase.xml index feb9183320..c5de3f3428 100644 --- a/api/src/main/resources/liquibase.xml +++ b/api/src/main/resources/liquibase.xml @@ -515,5 +515,502 @@ referencedColumnNames="user_id" referencedTableName="users" /> + + + + + + + + + + + + Schema for raxacore_billing table + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Adding constraints for raxacore_billing + + + + + + + + + + + + + + + + + + + + + + + Schema for raxacore_billing_item table + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Adding constraints for raxacore_billing_item + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Schema for raxacore_billing_item_adjustment + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Adding constraints for raxacore_billing_item_adjustment + + + + + + + + + + + + \ No newline at end of file diff --git a/api/src/main/resources/moduleApplicationContext.xml b/api/src/main/resources/moduleApplicationContext.xml index 8060435634..87ac0f8f99 100644 --- a/api/src/main/resources/moduleApplicationContext.xml +++ b/api/src/main/resources/moduleApplicationContext.xml @@ -25,18 +25,57 @@ - - - - - + - + + + + + + + + + + + + + + + + org.raxa.module.raxacore.DrugPurchaseOrderService + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -72,18 +111,19 @@ - + + - org.raxa.module.raxacore.DrugPurchaseOrderService + org.raxa.module.raxacore.DrugInventoryService - - - + + + @@ -102,18 +142,19 @@ - + + - org.raxa.module.raxacore.DrugInventoryService + org.raxa.module.raxacore.BillingService - - - + + + @@ -131,5 +172,65 @@ - + + + + + org.raxa.module.raxacore.BillingItemService + + + + + + + + + + + + + + + + + + + + + + + + + + + + + org.raxa.module.raxacore.BillingItemAdjustmentService + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/omod/src/main/resources/config.xml b/omod/src/main/resources/config.xml index 7e5b19a5b1..00d9751828 100644 --- a/omod/src/main/resources/config.xml +++ b/omod/src/main/resources/config.xml @@ -57,8 +57,12 @@ - RaxacorePatientList.hbm.xml - RaxacoreDrugPurchaseOrder.hbm.xml + RaxacoreDrugPurchaseOrder.hbm.xml + RaxacorePatientList.hbm.xml RaxacoreDrugInventory.hbm.xml + RaxacoreBilling.hbm.xml + RaxacoreBillingItem.hbm.xml + + RaxacoreBillingItemAdjustment.hbm.xml From 4a33459260ebfad272be7b1fe1763602cccf20b3 Mon Sep 17 00:00:00 2001 From: Abhis Date: Sat, 15 Dec 2012 17:27:19 +0530 Subject: [PATCH 4/6] Billing updated --- api/.classpath | 1 + api/pom.xml | 4 +- .../org/raxa/module/raxacore/Billing.java | 22 ++- .../raxacore/BillingItemAdjustment.java | 2 +- .../BillingItemAdjustmentService.java | 50 +++++- .../module/raxacore/BillingItemService.java | 23 +-- .../raxa/module/raxacore/BillingService.java | 19 ++- .../raxa/module/raxacore/db/BillingDAO.java | 4 + .../raxacore/db/BillingItemAdjustmentDAO.java | 3 + .../module/raxacore/db/BillingItemDAO.java | 2 + .../db/hibernate/HibernateBillingDAO.java | 22 ++- .../HibernateBillingItemAdjustmentDAO.java | 8 + .../db/hibernate/HibernateBillingItemDAO.java | 10 ++ .../BillingItemAdjustmentServiceImpl.java | 4 + .../raxacore/impl/BillingItemServiceImpl.java | 6 + .../raxacore/impl/BillingServiceImpl.java | 8 + .../main/resources/RaxacoreBilling.hbm.xml | 9 +- .../resources/RaxacoreBillingItem.hbm.xml | 20 +-- .../RaxacoreBillingItemAdjustment.hbm.xml | 4 +- api/src/main/resources/liquibase.xml | 49 ++++-- .../resources/TestingApplicationContext.xml | 142 ------------------ .../raxacore/include/moduleTestData.xml | 9 ++ api/src/test/resources/test-hibernate.cfg.xml | 5 +- .../controller/DrugInventoryController.java | 2 + .../DrugPurchaseOrderController.java | 2 + 25 files changed, 236 insertions(+), 194 deletions(-) delete mode 100644 api/src/test/resources/TestingApplicationContext.xml diff --git a/api/.classpath b/api/.classpath index dd55e60ced..8065d5e204 100644 --- a/api/.classpath +++ b/api/.classpath @@ -6,5 +6,6 @@ + diff --git a/api/pom.xml b/api/pom.xml index b816efd5e3..c732196654 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -11,8 +11,9 @@ jar RaxaEMR Core API API project for RaxaEMR Core Module - + + org.openmrs.api openmrs-api @@ -71,6 +72,7 @@ + diff --git a/api/src/main/java/org/raxa/module/raxacore/Billing.java b/api/src/main/java/org/raxa/module/raxacore/Billing.java index 4802209ab1..aeffe6ca50 100644 --- a/api/src/main/java/org/raxa/module/raxacore/Billing.java +++ b/api/src/main/java/org/raxa/module/raxacore/Billing.java @@ -21,7 +21,7 @@ import org.openmrs.Patient; /** - * PatientList stores the data needed to lists patients for registration, screener, etc. + * Billing stores the attributes of a bill */ public class Billing extends BaseOpenmrsMetadata implements Serializable { @@ -33,6 +33,10 @@ public class Billing extends BaseOpenmrsMetadata implements Serializable { private Integer patientId; + private Integer totalAmount; + + private Integer balance; + private Provider provider; private Patient patient; @@ -57,6 +61,22 @@ public void setStatus(String status) { this.status = status; } + public Integer getTotalAmount() { + return totalAmount; + } + + public void setTotalAmount(Integer totalAmount) { + this.totalAmount = totalAmount; + } + + public Integer getBalance() { + return balance; + } + + public void setBalance(Integer balance) { + this.balance = balance; + } + public Integer getProviderId() { return providerId; } diff --git a/api/src/main/java/org/raxa/module/raxacore/BillingItemAdjustment.java b/api/src/main/java/org/raxa/module/raxacore/BillingItemAdjustment.java index 5f2fa54aae..360cf83f62 100644 --- a/api/src/main/java/org/raxa/module/raxacore/BillingItemAdjustment.java +++ b/api/src/main/java/org/raxa/module/raxacore/BillingItemAdjustment.java @@ -23,7 +23,7 @@ import org.openmrs.Provider; /** - * BillingItem stores the data of items in the bill. + * BillingItemAdjustments stores the data of billingitems in the bill like discounts , reason of discount . */ public class BillingItemAdjustment extends BaseOpenmrsMetadata implements Serializable { diff --git a/api/src/main/java/org/raxa/module/raxacore/BillingItemAdjustmentService.java b/api/src/main/java/org/raxa/module/raxacore/BillingItemAdjustmentService.java index 3a8a7be73d..bdba0d5bfe 100644 --- a/api/src/main/java/org/raxa/module/raxacore/BillingItemAdjustmentService.java +++ b/api/src/main/java/org/raxa/module/raxacore/BillingItemAdjustmentService.java @@ -25,16 +25,60 @@ import org.springframework.transaction.annotation.Transactional; public interface BillingItemAdjustmentService extends OpenmrsService { - + BillingItemAdjustment saveBillingItemAdjustment(BillingItemAdjustment adjustment) throws DAOException; - + /** + * saves a billing adjustment + * @param adjustment + * @return + * @throws DAOException + */ void deleteBillingItemAdjustment(BillingItemAdjustment adjustment) throws DAOException; - + /** + * delete a billing adjustment + * @param adjustment + * @return + * @throws DAOException + */ BillingItemAdjustment getBillingItemAdjustmentByUuid(String uuid); + /** + * get a billing adjustment by uuid + * @param adjustment + * @return + * @throws DAOException + */ + BillingItemAdjustment getBillingItemAdjustment(int billItemAdjustmentId); + + /** + * get a billing adjustment by its id + * @param adjustment + * @return + * @throws DAOException + */ List getAllBillingItemAdjustments() throws DAOException; + /** + * gets all billing adjustment + * @param adjustment + * @return + * @throws DAOException + */ + BillingItemAdjustment updateBillingItemAdjustment(BillingItemAdjustment adjustment); + /** + *update billing adjustment given id + * @param adjustment + * @return + * @throws DAOException + */ List getAllBillingItemAdjustmentsByBillingItem(Integer billingitemid); + + /** + * gets all billing adjustments for billing item + * @param adjustment + * @return + * @throws DAOException + */ } diff --git a/api/src/main/java/org/raxa/module/raxacore/BillingItemService.java b/api/src/main/java/org/raxa/module/raxacore/BillingItemService.java index 4189a3d913..bf93c22431 100644 --- a/api/src/main/java/org/raxa/module/raxacore/BillingItemService.java +++ b/api/src/main/java/org/raxa/module/raxacore/BillingItemService.java @@ -26,24 +26,27 @@ public interface BillingItemService extends OpenmrsService { - BillingItem saveBillingItem(BillingItem item) throws DAOException; - void deleteBillingItem(BillingItem item) throws DAOException; + BillingItem saveBillingItem(BillingItem item) throws DAOException; //saves a billingItem - BillingItem getBillingItemByUuid(String uuid); + BillingItem getBillingItem(int billItemId) throws DAOException; //get billingitem by id - List getAllBillingItems() throws DAOException; + void deleteBillingItem(BillingItem item) throws DAOException; //delete billing item - List getAllBillingItemsByBill(Integer billid); + BillingItem getBillingItemByUuid(String uuid); // get billing item by uuid - BillingItem updateBillingItem(BillingItem item); + List getAllBillingItems() throws DAOException; // get all billing items - List getAllBillingItemsByProvider(Integer providerId); + List getAllBillingItemsByBill(Integer billid); //get all billing items in bill by billid - List getAllBillingItemsByEncounter(Integer encounterId); + BillingItem updateBillingItem(BillingItem item); //update billing item - List getAllBillingItemsByConcept(Integer conceptId); + List getAllBillingItemsByProvider(Integer providerId); //get billing item by providerId - List getAllBillingItemsByOrder(Integer orderId); + List getAllBillingItemsByEncounter(Integer encounterId); //get billing items by encounterId + + List getAllBillingItemsByConcept(Integer conceptId); // get billingItems by concept + + List getAllBillingItemsByOrder(Integer orderId); //get billingItems by orderId } diff --git a/api/src/main/java/org/raxa/module/raxacore/BillingService.java b/api/src/main/java/org/raxa/module/raxacore/BillingService.java index ef5387776a..14503413c6 100644 --- a/api/src/main/java/org/raxa/module/raxacore/BillingService.java +++ b/api/src/main/java/org/raxa/module/raxacore/BillingService.java @@ -26,17 +26,22 @@ public interface BillingService extends OpenmrsService { - Billing saveBill(Billing bill) throws DAOException; + Billing saveBill(Billing bill) throws DAOException; //save a bill - void deleteBill(Billing bill) throws DAOException; + void deleteBill(Billing bill) throws DAOException; //delete a bill - Billing getBillByPatientUuid(String uuid); + Billing getBillByPatientUuid(String uuid); // get all bills of a patient given its uuuid - List getAllBills() throws DAOException; + List getAllBills() throws DAOException; //get all bills - List getAllBillsByStatus(String status); + List getAllBillsByStatus(String status); //get all bills by status - Billing updateBill(Billing bill); + Billing updateBill(Billing bill); // update a bill + + Billing getBill(int billId); // get a bill given its id + + List getAllBillsByProvider(Integer providerId); // get all bills for Provider given providerId + + List getAllBillsByPatient(Integer patientId); //get all bills for patient given patientId - List getAllBillsByProvider(Integer providerId); } diff --git a/api/src/main/java/org/raxa/module/raxacore/db/BillingDAO.java b/api/src/main/java/org/raxa/module/raxacore/db/BillingDAO.java index 994f6b2815..2f5bb6f59a 100644 --- a/api/src/main/java/org/raxa/module/raxacore/db/BillingDAO.java +++ b/api/src/main/java/org/raxa/module/raxacore/db/BillingDAO.java @@ -34,5 +34,9 @@ public interface BillingDAO { public Billing updateBill(Billing bill); + public Billing getBill(int billId); + public List getAllBillsByProvider(Integer providerId); + + public List getAllBillsByPatient(Integer patientId); } diff --git a/api/src/main/java/org/raxa/module/raxacore/db/BillingItemAdjustmentDAO.java b/api/src/main/java/org/raxa/module/raxacore/db/BillingItemAdjustmentDAO.java index abeccf32da..5fcb103bfa 100644 --- a/api/src/main/java/org/raxa/module/raxacore/db/BillingItemAdjustmentDAO.java +++ b/api/src/main/java/org/raxa/module/raxacore/db/BillingItemAdjustmentDAO.java @@ -18,6 +18,7 @@ import java.util.List; import org.openmrs.api.db.DAOException; +import org.raxa.module.raxacore.BillingItem; import org.raxa.module.raxacore.BillingItemAdjustment; public interface BillingItemAdjustmentDAO { @@ -28,6 +29,8 @@ public interface BillingItemAdjustmentDAO { BillingItemAdjustment getBillingItemAdjustmentByUuid(String uuid); + BillingItemAdjustment getBillingItemAdjustment(int billItemAdjustmentId); + List getAllBillingItemAdjustments() throws DAOException; List getAllBillingItemAdjustmentsByReason(String reason); diff --git a/api/src/main/java/org/raxa/module/raxacore/db/BillingItemDAO.java b/api/src/main/java/org/raxa/module/raxacore/db/BillingItemDAO.java index 9b1a3b6069..148a6d30a5 100644 --- a/api/src/main/java/org/raxa/module/raxacore/db/BillingItemDAO.java +++ b/api/src/main/java/org/raxa/module/raxacore/db/BillingItemDAO.java @@ -28,6 +28,8 @@ public interface BillingItemDAO { BillingItem getBillingItemByUuid(String uuid); + BillingItem getBillingItem(int billItemId); + List getAllBillingItems() throws DAOException; List getAllBillingItemsByBill(Integer billid); diff --git a/api/src/main/java/org/raxa/module/raxacore/db/hibernate/HibernateBillingDAO.java b/api/src/main/java/org/raxa/module/raxacore/db/hibernate/HibernateBillingDAO.java index 94197e3626..47b8be5d7a 100644 --- a/api/src/main/java/org/raxa/module/raxacore/db/hibernate/HibernateBillingDAO.java +++ b/api/src/main/java/org/raxa/module/raxacore/db/hibernate/HibernateBillingDAO.java @@ -15,15 +15,14 @@ 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.Billing; - import org.raxa.module.raxacore.db.BillingDAO; import org.springframework.transaction.annotation.Transactional; @@ -85,6 +84,16 @@ public Billing updateBill(Billing bill) { return bill; } + @Transactional + public Billing getBill(int billId) throws DAOException { + + Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Billing.class); + criteria.add(Restrictions.eq("billId", billId)); + + return (Billing) criteria.uniqueResult(); + + } + @Transactional public List getAllBillsByProvider(Integer providerId) { @@ -95,4 +104,13 @@ public List getAllBillsByProvider(Integer providerId) { return bills; } + @Transactional + public List getAllBillsByPatient(Integer patientId) { + + Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Billing.class); + criteria.add(Restrictions.eq("patientId", patientId)); + List bills = new ArrayList(); + bills.addAll(criteria.list()); + return bills; + } } diff --git a/api/src/main/java/org/raxa/module/raxacore/db/hibernate/HibernateBillingItemAdjustmentDAO.java b/api/src/main/java/org/raxa/module/raxacore/db/hibernate/HibernateBillingItemAdjustmentDAO.java index 6f9187b87f..ecb3cc19bb 100644 --- a/api/src/main/java/org/raxa/module/raxacore/db/hibernate/HibernateBillingItemAdjustmentDAO.java +++ b/api/src/main/java/org/raxa/module/raxacore/db/hibernate/HibernateBillingItemAdjustmentDAO.java @@ -56,6 +56,14 @@ public BillingItemAdjustment getBillingItemAdjustmentByUuid(String uuid) { return (BillingItemAdjustment) criteria.uniqueResult(); } + @Transactional + public BillingItemAdjustment getBillingItemAdjustment(int billItemAdjustmentId) { + Criteria criteria = sessionFactory.getCurrentSession().createCriteria(BillingItemAdjustment.class); + criteria.add(Restrictions.eq("billItemAdjustmentId", billItemAdjustmentId)); + + return (BillingItemAdjustment) criteria.uniqueResult(); + } + @Transactional public List getAllBillingItemAdjustments() { Criteria criteria = sessionFactory.getCurrentSession().createCriteria(BillingItemAdjustment.class); diff --git a/api/src/main/java/org/raxa/module/raxacore/db/hibernate/HibernateBillingItemDAO.java b/api/src/main/java/org/raxa/module/raxacore/db/hibernate/HibernateBillingItemDAO.java index 8fa59ac556..bd0750ff3c 100644 --- a/api/src/main/java/org/raxa/module/raxacore/db/hibernate/HibernateBillingItemDAO.java +++ b/api/src/main/java/org/raxa/module/raxacore/db/hibernate/HibernateBillingItemDAO.java @@ -61,6 +61,16 @@ public BillingItem getBillingItemByUuid(String uuid) return (BillingItem) criteria.uniqueResult(); } + @Transactional + public BillingItem getBillingItem(int billItemId) + + { + Criteria criteria = sessionFactory.getCurrentSession().createCriteria(BillingItem.class); + criteria.add(Restrictions.eq("billItemId", billItemId)); + + return (BillingItem) criteria.uniqueResult(); + } + @Transactional public List getAllBillingItems() { Criteria criteria = sessionFactory.getCurrentSession().createCriteria(BillingItem.class); diff --git a/api/src/main/java/org/raxa/module/raxacore/impl/BillingItemAdjustmentServiceImpl.java b/api/src/main/java/org/raxa/module/raxacore/impl/BillingItemAdjustmentServiceImpl.java index 2268ff5056..d17b4afdfd 100644 --- a/api/src/main/java/org/raxa/module/raxacore/impl/BillingItemAdjustmentServiceImpl.java +++ b/api/src/main/java/org/raxa/module/raxacore/impl/BillingItemAdjustmentServiceImpl.java @@ -60,6 +60,10 @@ public BillingItemAdjustment getBillingItemAdjustmentByUuid(String uuid) { return dao.getBillingItemAdjustmentByUuid(uuid); } + public BillingItemAdjustment getBillingItemAdjustment(int billItemAdjustmentId) { + return dao.getBillingItemAdjustment(billItemAdjustmentId); + } + public List getAllBillingItemAdjustments() { return dao.getAllBillingItemAdjustments(); } diff --git a/api/src/main/java/org/raxa/module/raxacore/impl/BillingItemServiceImpl.java b/api/src/main/java/org/raxa/module/raxacore/impl/BillingItemServiceImpl.java index d4af9fd9df..0a52d97b7c 100644 --- a/api/src/main/java/org/raxa/module/raxacore/impl/BillingItemServiceImpl.java +++ b/api/src/main/java/org/raxa/module/raxacore/impl/BillingItemServiceImpl.java @@ -59,6 +59,12 @@ public BillingItem getBillingItemByUuid(String uuid) return dao.getBillingItemByUuid(uuid); } + public BillingItem getBillingItem(int billItemId) + + { + return dao.getBillingItem(billItemId); + } + public List getAllBillingItems() { return dao.getAllBillingItems(); } diff --git a/api/src/main/java/org/raxa/module/raxacore/impl/BillingServiceImpl.java b/api/src/main/java/org/raxa/module/raxacore/impl/BillingServiceImpl.java index 3860c06ab5..cfdcf5f29f 100644 --- a/api/src/main/java/org/raxa/module/raxacore/impl/BillingServiceImpl.java +++ b/api/src/main/java/org/raxa/module/raxacore/impl/BillingServiceImpl.java @@ -62,6 +62,10 @@ public Billing getBillByPatientUuid(String uuid) { return dao.getBillByPatientUuid(uuid); } + public Billing getBill(int billId) { + return dao.getBill(billId); + } + public List getAllBills() { return dao.getAllBills(); } @@ -77,4 +81,8 @@ public Billing updateBill(Billing bill) { public List getAllBillsByProvider(Integer providerId) { return dao.getAllBillsByProvider(providerId); } + + public List getAllBillsByPatient(Integer patientId) { + return dao.getAllBillsByPatient(patientId); + } } diff --git a/api/src/main/resources/RaxacoreBilling.hbm.xml b/api/src/main/resources/RaxacoreBilling.hbm.xml index 627f94d748..a1877eb293 100644 --- a/api/src/main/resources/RaxacoreBilling.hbm.xml +++ b/api/src/main/resources/RaxacoreBilling.hbm.xml @@ -21,12 +21,15 @@ - - + + - + + diff --git a/api/src/main/resources/RaxacoreBillingItem.hbm.xml b/api/src/main/resources/RaxacoreBillingItem.hbm.xml index 60b1471e83..eec3cf4ec5 100644 --- a/api/src/main/resources/RaxacoreBillingItem.hbm.xml +++ b/api/src/main/resources/RaxacoreBillingItem.hbm.xml @@ -24,19 +24,19 @@ - - + + - - + + - - + + - - + + - - + + diff --git a/api/src/main/resources/RaxacoreBillingItemAdjustment.hbm.xml b/api/src/main/resources/RaxacoreBillingItemAdjustment.hbm.xml index f646247fa9..b24aedfc7c 100644 --- a/api/src/main/resources/RaxacoreBillingItemAdjustment.hbm.xml +++ b/api/src/main/resources/RaxacoreBillingItemAdjustment.hbm.xml @@ -25,7 +25,7 @@ - - + + diff --git a/api/src/main/resources/liquibase.xml b/api/src/main/resources/liquibase.xml index c5de3f3428..5dd8740756 100644 --- a/api/src/main/resources/liquibase.xml +++ b/api/src/main/resources/liquibase.xml @@ -134,7 +134,7 @@ @@ -252,7 +252,7 @@ @@ -301,7 +301,7 @@ @@ -454,7 +454,7 @@ @@ -515,8 +515,10 @@ referencedColumnNames="user_id" referencedTableName="users" /> + + @@ -621,7 +623,7 @@ @@ -668,7 +670,7 @@ @@ -714,7 +716,6 @@ - @@ -799,7 +800,7 @@ @@ -868,7 +869,7 @@ @@ -915,6 +916,8 @@ + + @@ -1013,4 +1016,28 @@ + + + Alter Schema for raxacore_billing_item + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/api/src/test/resources/TestingApplicationContext.xml b/api/src/test/resources/TestingApplicationContext.xml deleted file mode 100644 index f513c8c2d9..0000000000 --- a/api/src/test/resources/TestingApplicationContext.xml +++ /dev/null @@ -1,142 +0,0 @@ - - - - - - - classpath:hibernate.cfg.xml - classpath:test-hibernate.cfg.xml - - - - - - - - - - - - - - - - - - - - - - - - org.raxa.module.raxacore.PatientListService - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - org.raxa.module.raxacore.DrugPurchaseOrderService - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - org.raxa.module.raxacore.DrugInventoryService - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file 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 0e6d5818d6..ba85e7630c 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 @@ -6,6 +6,10 @@ + + + + @@ -15,4 +19,9 @@ + + + + + \ 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 7337dac671..224c2056fe 100644 --- a/api/src/test/resources/test-hibernate.cfg.xml +++ b/api/src/test/resources/test-hibernate.cfg.xml @@ -8,7 +8,10 @@ - + + + + diff --git a/omod/src/main/java/org/raxa/module/raxacore/web/v1_0/controller/DrugInventoryController.java b/omod/src/main/java/org/raxa/module/raxacore/web/v1_0/controller/DrugInventoryController.java index 2d92e7088d..1e1c4a1736 100644 --- a/omod/src/main/java/org/raxa/module/raxacore/web/v1_0/controller/DrugInventoryController.java +++ b/omod/src/main/java/org/raxa/module/raxacore/web/v1_0/controller/DrugInventoryController.java @@ -33,6 +33,7 @@ import org.raxa.module.raxacore.DrugInventoryService; import org.raxa.module.raxacore.PatientList; import org.springframework.stereotype.Controller; +import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; @@ -44,6 +45,7 @@ * Controller for REST web service access to the PatientList resource. */ @Controller +@Transactional @RequestMapping(value = "/rest/v1/raxacore/druginventory") public class DrugInventoryController extends BaseRestController { diff --git a/omod/src/main/java/org/raxa/module/raxacore/web/v1_0/controller/DrugPurchaseOrderController.java b/omod/src/main/java/org/raxa/module/raxacore/web/v1_0/controller/DrugPurchaseOrderController.java index 6a869e54dc..368f9c9548 100644 --- a/omod/src/main/java/org/raxa/module/raxacore/web/v1_0/controller/DrugPurchaseOrderController.java +++ b/omod/src/main/java/org/raxa/module/raxacore/web/v1_0/controller/DrugPurchaseOrderController.java @@ -17,6 +17,7 @@ import org.raxa.module.raxacore.DrugPurchaseOrder; import org.raxa.module.raxacore.DrugPurchaseOrderService; import org.springframework.stereotype.Controller; +import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; @@ -28,6 +29,7 @@ */ @Controller +@Transactional @RequestMapping(value = "/rest/v1/raxacore/drugpurchaseorder") public class DrugPurchaseOrderController extends BaseRestController { From 0575b547fe6635095e14672e1023b12222d3e2e0 Mon Sep 17 00:00:00 2001 From: Abhis Date: Sat, 15 Dec 2012 17:51:43 +0530 Subject: [PATCH 5/6] Billing Updated --- .../HbernateBillingItemAdjustmentDAOTest.java | 131 ++++++++++ .../db/hibernate/HibernateBillingDAOTest.java | 154 ++++++++++++ .../HibernateBillingItemDAOTest.java | 182 ++++++++++++++ .../resources/TestingApplicationContext .xml | 204 ++++++++++++++++ .../v1_0/controller/BillingController.java | 226 ++++++++++++++++++ .../BillingItemAdjustmentController.java | 108 +++++++++ .../controller/BillingItemController.java | 192 +++++++++++++++ 7 files changed, 1197 insertions(+) create mode 100644 api/src/test/java/org/raxa/module/raxacore/db/hibernate/HbernateBillingItemAdjustmentDAOTest.java create mode 100644 api/src/test/java/org/raxa/module/raxacore/db/hibernate/HibernateBillingDAOTest.java create mode 100644 api/src/test/java/org/raxa/module/raxacore/db/hibernate/HibernateBillingItemDAOTest.java create mode 100644 api/src/test/resources/TestingApplicationContext .xml create mode 100644 omod/src/main/java/org/raxa/module/raxacore/web/v1_0/controller/BillingController.java create mode 100644 omod/src/main/java/org/raxa/module/raxacore/web/v1_0/controller/BillingItemAdjustmentController.java create mode 100644 omod/src/main/java/org/raxa/module/raxacore/web/v1_0/controller/BillingItemController.java diff --git a/api/src/test/java/org/raxa/module/raxacore/db/hibernate/HbernateBillingItemAdjustmentDAOTest.java b/api/src/test/java/org/raxa/module/raxacore/db/hibernate/HbernateBillingItemAdjustmentDAOTest.java new file mode 100644 index 0000000000..9b112c0dde --- /dev/null +++ b/api/src/test/java/org/raxa/module/raxacore/db/hibernate/HbernateBillingItemAdjustmentDAOTest.java @@ -0,0 +1,131 @@ +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.Date; +import java.util.List; +import static org.junit.Assert.*; + +import org.junit.Before; +import org.junit.Test; +import org.openmrs.Concept; +import org.openmrs.Encounter; +import org.openmrs.Order; +import org.openmrs.Patient; +import org.openmrs.Provider; +import org.openmrs.api.context.Context; +import org.openmrs.test.BaseModuleContextSensitiveTest; +import org.raxa.module.raxacore.BillingItem; +import org.raxa.module.raxacore.BillingItemAdjustment; +import org.raxa.module.raxacore.db.BillingItemAdjustmentDAO; + +public class HbernateBillingItemAdjustmentDAOTest 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 BillingItemAdjustmentDAO dao = null; + + @Before + public void setUp() throws Exception { + executeDataSet(MODULE_TEST_DATA_XML); + dao = (BillingItemAdjustmentDAO) applicationContext + .getBean("org.raxa.module.raxacore.db.hibernate.HibernateBillingItemAdjustmentDAO"); + } + + @Test + public void testSaveBillingItemAdjustment() { + BillingItemAdjustment billItemAdj = new BillingItemAdjustment(); + billItemAdj.setName("TestList9"); + billItemAdj.setDescription("testing"); + billItemAdj.setCreator(Context.getUserContext().getAuthenticatedUser()); + billItemAdj.setDateCreated(new java.util.Date()); + billItemAdj.setUuid("abc"); + billItemAdj.setDateCreated(new java.util.Date()); + billItemAdj.setRetired(Boolean.FALSE); + billItemAdj.setReason("xyz"); + billItemAdj.setValue(10); + billItemAdj.setBillItemId(8); + dao.saveBillingItemAdjustment(billItemAdj); + BillingItemAdjustment result = dao.getBillingItemAdjustmentByUuid("abc"); + String uuid = result.getUuid(); + assertEquals(uuid, "abc"); + } + + @Test + public void testDeleteBillingItemAdjustment() { + BillingItemAdjustment billItemAdj = new BillingItemAdjustment(); + billItemAdj.setName("TestList9"); + billItemAdj.setDescription("testing"); + billItemAdj.setCreator(Context.getUserContext().getAuthenticatedUser()); + billItemAdj.setDateCreated(new java.util.Date()); + billItemAdj.setUuid("abc"); + billItemAdj.setDateCreated(new java.util.Date()); + billItemAdj.setRetired(Boolean.FALSE); + billItemAdj.setReason("xyz"); + billItemAdj.setValue(10); + billItemAdj.setBillItemId(8); + dao.deleteBillingItemAdjustment(billItemAdj); + BillingItemAdjustment result = dao.getBillingItemAdjustmentByUuid("abc"); + //String uuid = result.getUuid(); + + assertEquals(result, null); + } + + @Test + public void testBillingItemAdjustmentByUuid() { + BillingItemAdjustment result = dao.getBillingItemAdjustmentByUuid("68547121-1b70-465c-99ee-c9dfd95e7d38"); + String name = result.getName(); + assertEquals(name, "TestList9"); + + } + + @Test + public void testGetAllBillingItemAdjustments() { + + List allBillingItemsAdj = dao.getAllBillingItemAdjustments(); + assertEquals(allBillingItemsAdj.size(), 1); + + } + + @Test + public void testGetAllBillingItemAdjustmentsByBillingItem() { + + List allBillingItemsAdj = dao.getAllBillingItemAdjustmentsByBillingItem(8); + assertEquals(allBillingItemsAdj.size(), 1); + + } + + @Test + public void testUpdateBillingItemAdjustment() { + BillingItemAdjustment billItemAdj = dao.getBillingItemAdjustmentByUuid("68547121-1b70-465c-99ee-c9dfd95e7d38"); + billItemAdj.setName("new test list"); + dao.updateBillingItemAdjustment(billItemAdj); + String name = dao.getBillingItemAdjustmentByUuid("68547121-1b70-465c-99ee-c9dfd95e7d38").getName(); + assertEquals(name, "new test list"); + + } + + @Test + public void testGetAllBillingItemAdjustmentsByReason() { + + List allBillingItemsAdj = dao.getAllBillingItemAdjustmentsByReason("RSBY"); + assertEquals(allBillingItemsAdj.size(), 1); + + } + +} diff --git a/api/src/test/java/org/raxa/module/raxacore/db/hibernate/HibernateBillingDAOTest.java b/api/src/test/java/org/raxa/module/raxacore/db/hibernate/HibernateBillingDAOTest.java new file mode 100644 index 0000000000..fad0f375ad --- /dev/null +++ b/api/src/test/java/org/raxa/module/raxacore/db/hibernate/HibernateBillingDAOTest.java @@ -0,0 +1,154 @@ +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.Date; +import java.util.List; +import static org.junit.Assert.*; + +import org.junit.Before; +import org.junit.Test; +import org.openmrs.Drug; +import org.openmrs.EncounterType; +import org.openmrs.Location; +import org.openmrs.Provider; +import org.openmrs.Patient; +import org.openmrs.api.context.Context; +import org.openmrs.test.BaseModuleContextSensitiveTest; +import org.raxa.module.raxacore.Billing; +import org.raxa.module.raxacore.DrugInventory; + +import org.raxa.module.raxacore.db.BillingDAO; + +public class HibernateBillingDAOTest 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 BillingDAO dao = null; + + @Before + public void setUp() throws Exception { + executeDataSet(MODULE_TEST_DATA_XML); + dao = (BillingDAO) applicationContext.getBean("org.raxa.module.raxacore.db.hibernate.HibernateBillingDAO"); + } + + @Test + public void testSaveBill() { + Billing bill = new Billing(); + //NOTE: never set Id, will be generated automatically (when saving) + Patient pat = new Patient(2); + Provider pro = new Provider(1); + bill.setName("TestList7"); + bill.setDescription("testing"); + bill.setCreator(Context.getUserContext().getAuthenticatedUser()); + bill.setDateCreated(new java.util.Date()); + bill.setUuid("68547121-1b70-465c-99ee-c9dfd95e7d34"); + bill.setDateCreated(new java.util.Date()); + bill.setRetired(Boolean.FALSE); + //bill.setBatch("batch 1"); + //bill.setQuantity(10); + bill.setStatus("paid"); + //bill.setDrugId(2); + //bill.setExpiryDate(new Date(2012 - 1 - 1)); + //bill.setValue(20); + bill.setProviderId(1); + bill.setPatientId(2); + //bill.setDrugPurchaseOrderId(14); + //bill.setOriginalQuantity(20); + bill.setPatient(pat); + bill.setProvider(pro); + + dao.saveBill(bill); + Billing result = dao.getBillByPatientUuid("68547121-1b70-465c-99ee-c9dfd95e7d34"); + //DrugInventory result=dao.get + String uuid = result.getUuid(); + assertEquals(uuid, "68547121-1b70-465c-99ee-c9dfd95e7d34"); + } + + @Test + public void testDeleteBill() { + Billing bill = new Billing(); + //NOTE: never set Id, will be generated automatically (when saving) + Patient pat = new Patient(2); + Provider pro = new Provider(1); + bill.setName("TestList7"); + bill.setDescription("testing"); + bill.setCreator(Context.getUserContext().getAuthenticatedUser()); + bill.setDateCreated(new java.util.Date()); + bill.setUuid("68547121-1b70-465c-99ee-c9dfd95e7d34"); + bill.setDateCreated(new java.util.Date()); + bill.setRetired(Boolean.FALSE); + //bill.setBatch("batch 1"); + //bill.setQuantity(10); + bill.setStatus("paid"); + //bill.setDrugId(2); + //bill.setExpiryDate(new Date(2012 - 1 - 1)); + //bill.setValue(20); + bill.setProviderId(1); + bill.setPatientId(2); + //bill.setDrugPurchaseOrderId(14); + //bill.setOriginalQuantity(20); + bill.setPatient(pat); + bill.setProvider(pro); + + dao.deleteBill(bill); + Billing result = dao.getBillByPatientUuid("68547121-1b70-465c-99ee-c9dfd95e7d34"); + + assertEquals(result, null); + } + + @Test + public void testGetBillsByUuid() { + Billing result = dao.getBillByPatientUuid("68547121-1b70-465c-99ee-c9dfd95e7d36"); + String name = result.getName(); + assertEquals(name, "TestList7"); + + } + + @Test + public void testGetAllBills() { + + List allBills = dao.getAllBills(); + assertEquals(allBills.size(), 1); + + } + + @Test + public void testGetAllBillsByStatus() { + List allBills = dao.getAllBillsByStatus("paid"); + assertEquals(allBills.size(), 1); + } + + @Test + public void testUpdateBill() { + Billing bill = dao.getBillByPatientUuid("68547121-1b70-465c-99ee-c9dfd95e7d36"); + bill.setName("new test list"); + dao.updateBill(bill); + String name = dao.getBillByPatientUuid("68547121-1b70-465c-99ee-c9dfd95e7d36").getName(); + assertEquals(name, "new test list"); + + } + + @Test + public void testGetBillsByProvider() { + List allBills = dao.getAllBillsByProvider(1); + assertEquals(allBills.size(), 1); + + } + +} diff --git a/api/src/test/java/org/raxa/module/raxacore/db/hibernate/HibernateBillingItemDAOTest.java b/api/src/test/java/org/raxa/module/raxacore/db/hibernate/HibernateBillingItemDAOTest.java new file mode 100644 index 0000000000..7c3e08b55a --- /dev/null +++ b/api/src/test/java/org/raxa/module/raxacore/db/hibernate/HibernateBillingItemDAOTest.java @@ -0,0 +1,182 @@ +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.Date; +import java.util.List; +import static org.junit.Assert.*; + +import org.junit.Before; +import org.junit.Test; +import org.openmrs.Drug; +import org.openmrs.EncounterType; +import org.openmrs.Encounter; +import org.openmrs.Concept; +import org.openmrs.Order; +import org.openmrs.Patient; +import org.openmrs.Provider; +import org.openmrs.api.context.Context; +import org.openmrs.test.BaseModuleContextSensitiveTest; +import org.raxa.module.raxacore.Billing; +import org.raxa.module.raxacore.BillingItem; +import org.raxa.module.raxacore.db.BillingItemDAO; + +public class HibernateBillingItemDAOTest 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 BillingItemDAO dao = null; + + @Before + public void setUp() throws Exception { + executeDataSet(MODULE_TEST_DATA_XML); + dao = (BillingItemDAO) applicationContext.getBean("org.raxa.module.raxacore.db.hibernate.HibernateBillingItemDAO"); + } + + @Test + public void testSaveBillItem() { + BillingItem billItem = new BillingItem(); + //NOTE: never set Id, will be generated automatically (when saving) + Patient pat = new Patient(2); + Encounter enc = new Encounter(10); + Concept con = new Concept(1); + Order ord = new Order(1); + Provider pro = new Provider(1); + + billItem.setName("TestList8"); + billItem.setDescription("testing"); + billItem.setCreator(Context.getUserContext().getAuthenticatedUser()); + billItem.setDateCreated(new java.util.Date()); + billItem.setUuid("abc"); + billItem.setDateCreated(new java.util.Date()); + billItem.setRetired(Boolean.FALSE); + //bill.setBatch("batch 1"); + billItem.setQuantity(10); + billItem.setValue(10); + billItem.setProviderId(1); + billItem.setConceptId(1); + billItem.setEncounterId(10); + billItem.setOrderId(1); + billItem.setBillId(7); + billItem.setProvider(pro); + billItem.setConcept(con); + billItem.setEncounter(enc); + billItem.setOrder(ord); + + dao.saveBillingItem(billItem); + BillingItem result = dao.getBillingItemByUuid("abc"); + String uuid = result.getUuid(); + assertEquals(uuid, "abc"); + } + + @Test + public void testDeleteBill() { + BillingItem billItem = new BillingItem(); + //NOTE: never set Id, will be generated automatically (when saving) + Patient pat = new Patient(2); + Encounter enc = new Encounter(10); + Concept con = new Concept(1); + Order ord = new Order(1); + Provider pro = new Provider(1); + + billItem.setName("TestList8"); + billItem.setDescription("testing"); + billItem.setCreator(Context.getUserContext().getAuthenticatedUser()); + billItem.setDateCreated(new java.util.Date()); + billItem.setUuid("abc"); + billItem.setDateCreated(new java.util.Date()); + billItem.setRetired(Boolean.FALSE); + //bill.setBatch("batch 1"); + billItem.setQuantity(10); + billItem.setValue(10); + billItem.setProviderId(1); + billItem.setConceptId(1); + billItem.setEncounterId(10); + billItem.setOrderId(1); + billItem.setBillId(7); + billItem.setProvider(pro); + billItem.setConcept(con); + billItem.setEncounter(enc); + billItem.setOrder(ord); + + dao.deleteBillingItem(billItem); + BillingItem result = dao.getBillingItemByUuid("abc"); + + assertEquals(result, null); + } + + @Test + public void testGetBillingItemByUuid() { + BillingItem result = dao.getBillingItemByUuid("68547121-1b70-465c-99ee-c9dfd95e7d37"); + String name = result.getName(); + assertEquals(name, "TestList8"); + + } + + @Test + public void testGetAllBillingItems() { + + List allBillingItems = dao.getAllBillingItems(); + assertEquals(allBillingItems.size(), 1); + + } + + @Test + public void testGetAllBillingItemsByBill() { + List allBillingItems = dao.getAllBillingItemsByBill(7); + assertEquals(allBillingItems.size(), 1); + } + + @Test + public void testUpdateBillingItem() { + BillingItem billItem = dao.getBillingItemByUuid("68547121-1b70-465c-99ee-c9dfd95e7d37"); + billItem.setName("new test list"); + dao.updateBillingItem(billItem); + String name = dao.getBillingItemByUuid("68547121-1b70-465c-99ee-c9dfd95e7d37").getName(); + assertEquals(name, "new test list"); + + } + + @Test + public void testGetAllBillingItemsByProvider() { + List allBillingItems = dao.getAllBillingItemsByProvider(1); + assertEquals(allBillingItems.size(), 1); + + } + + @Test + public void testGetAllBillingItemsByEncounter() { + List allBillingItems = dao.getAllBillingItemsByEncounter(10); + assertEquals(allBillingItems.size(), 1); + + } + + @Test + public void testGetAllBillingItemsByConcept() { + List allBillingItems = dao.getAllBillingItemsByConcept(1); + assertEquals(allBillingItems.size(), 1); + + } + + @Test + public void testGetAllBillingItemsByOrder() { + List allBillingItems = dao.getAllBillingItemsByOrder(1); + assertEquals(allBillingItems.size(), 1); + + } +} diff --git a/api/src/test/resources/TestingApplicationContext .xml b/api/src/test/resources/TestingApplicationContext .xml new file mode 100644 index 0000000000..210341ce8d --- /dev/null +++ b/api/src/test/resources/TestingApplicationContext .xml @@ -0,0 +1,204 @@ + + + + + + + classpath:hibernate.cfg.xml + classpath:test-hibernate.cfg.xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + org.raxa.module.raxacore.PatientListService + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + org.raxa.module.raxacore.DrugPurchaseOrderService + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + org.raxa.module.raxacore.DrugInventoryService + + + + + + + + + + + + + + + + + + + + + + + + + + + + + org.raxa.module.raxacore.BillingService + + + + + + + + + + + + + + + + + + + + + + + + + + + + + org.raxa.module.raxacore.BillingItemService + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/omod/src/main/java/org/raxa/module/raxacore/web/v1_0/controller/BillingController.java b/omod/src/main/java/org/raxa/module/raxacore/web/v1_0/controller/BillingController.java new file mode 100644 index 0000000000..ddad21c32e --- /dev/null +++ b/omod/src/main/java/org/raxa/module/raxacore/web/v1_0/controller/BillingController.java @@ -0,0 +1,226 @@ +package org.raxa.module.raxacore.web.v1_0.controller; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.LinkedHashMap; +import java.util.List; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import org.openmrs.Provider; +import org.openmrs.api.context.Context; +import org.openmrs.module.webservices.rest.SimpleObject; +import org.openmrs.module.webservices.rest.web.RestUtil; +import org.openmrs.module.webservices.rest.web.annotation.WSDoc; +import org.openmrs.module.webservices.rest.web.response.ResponseException; +import org.openmrs.module.webservices.rest.web.v1_0.controller.BaseRestController; +import org.raxa.module.raxacore.Billing; +import org.raxa.module.raxacore.BillingItem; +import org.raxa.module.raxacore.BillingItemAdjustment; +import org.raxa.module.raxacore.BillingItemAdjustmentService; +import org.raxa.module.raxacore.BillingItemService; +import org.raxa.module.raxacore.BillingService; +import org.raxa.module.raxacore.PatientList; +import org.springframework.stereotype.Controller; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; + +/** + * Controller for REST web service access to the Billing resource. + */ + +@Controller +@Transactional +@RequestMapping(value = "/rest/v1/raxacore/billing") +public class BillingController extends BaseRestController { + + BillingService service; + + Gson gson = new GsonBuilder().serializeNulls().create(); + + private static final String[] REF = { "uuid", "patientId", "status", "providerId", "name", "description", "billId", + "dateCreated", "balance", "totalAmount" }; + + public void initBillingController() { + service = Context.getService(BillingService.class); + } + + private String getResourceVersion() { + return "1.0"; + } + /** + * + * @param post + * @param request + * @param response + * @return + * @throws ResponseException + * Saves a bill along with all billing items and ajustments + */ + @RequestMapping(method = RequestMethod.POST) + @WSDoc("Save Bill") + @ResponseBody + public Object saveBill(@RequestBody SimpleObject post, HttpServletRequest request, HttpServletResponse response) + throws ResponseException { + initBillingController(); + Billing bill = new Billing(); + + bill.setPatientId(Integer.parseInt(post.get("patientId").toString())); + bill.setProviderId(Integer.parseInt(post.get("providerId").toString())); + bill.setStatus(post.get("status").toString()); + + bill.setBalance(Integer.parseInt(post.get("balance").toString())); + + bill.setTotalAmount(Integer.parseInt(post.get("totalAmount").toString())); + + if (post.get("name") != null) { + bill.setName(post.get("name").toString()); + } + + if (post.get("description") != null) { + bill.setDescription(post.get("description").toString()); + } + + bill.setProvider(Context.getProviderService().getProvider(Integer.parseInt(post.get("providerId").toString()))); + + bill.setPatient(Context.getPatientService().getPatient(Integer.parseInt(post.get("patientId").toString()))); + + Billing created; + SimpleObject obj = new SimpleObject(); + + try { + created = service.saveBill(bill); + + obj.add("uuid", created.getUuid()); + obj.add("patientId", created.getPatientId()); + obj.add("providerId", created.getProviderId()); + obj.add("status", created.getStatus()); + } + catch (Exception e) { + System.out.println(" error"); + e.printStackTrace(); + } + saveOrUpdateBillItem(post, bill); + return RestUtil.created(response, obj); + + } + + /** + * + * @param uuid + * @param request + * @return + * @throws ResponseException + gets Billing Item by uuid + */ + @RequestMapping(value = "/{uuid}", method = RequestMethod.GET) + @WSDoc("Gets bill by the uuid path") + @ResponseBody() + public String getBillByUuid(@PathVariable("uuid") String uuid, HttpServletRequest request) throws ResponseException { + initBillingController(); + Billing bill = service.getBillByPatientUuid(uuid); + SimpleObject obj = new SimpleObject(); + obj.add("uuid", bill.getUuid()); + obj.add("patientId", bill.getPatientId()); + obj.add("providerId", bill.getProviderId()); + obj.add("status", bill.getStatus()); + return gson.toJson(obj); + } + + + /** + * + * @param query + * @param request + * @return + * @throws ResponseException + gets all bills by patientID + */ + @RequestMapping(method = RequestMethod.GET, params = "q") + @WSDoc("Gets All bills by patientId") + @ResponseBody() + public String getPatientListsByName(@RequestParam("q") Integer query, HttpServletRequest request) + throws ResponseException { + initBillingController(); + + List getAllBillsByPatient = service.getAllBillsByPatient(query); + ArrayList results = new ArrayList(); + for (Billing patientList : getAllBillsByPatient) { + SimpleObject obj = new SimpleObject(); + obj.add("uuid", patientList.getUuid()); + obj.add("billId", patientList.getBillId()); + obj.add("status", patientList.getStatus()); + + obj.add("providerId", patientList.getProviderId()); + obj.add("dateCreated", patientList.getDateCreated()); + obj.add("balance", patientList.getBalance()); + obj.add("totalAmount", patientList.getTotalAmount()); + + results.add(obj); + } + return gson.toJson(new SimpleObject().add("results", results)); + } + + /** + * Saves billing Items in bill + * @param post + * @param bill + * @throws ResponseException + */ + private void saveOrUpdateBillItem(SimpleObject post, Billing bill) throws ResponseException { + + if (post.get("billItems") != null) { + List billItemObjects = (List) post.get("billItems"); + for (int i = 0; i < billItemObjects.size(); i++) + + { + + BillingItem billItem = new BillingItem(); + + //setBillItemFields(billItem, billItemObjects.get(i)); + billItem.setBillId(bill.getBillId()); + if (billItemObjects.get(i).get("quantity") != null) { + billItem.setQuantity(Integer.parseInt(billItemObjects.get(i).get("quantity").toString())); + } + + if (billItemObjects.get(i).get("value") != null) { + billItem.setValue(Integer.parseInt(billItemObjects.get(i).get("value").toString())); + } + + if (billItemObjects.get(i).get("name") != null) { + billItem.setName(billItemObjects.get(i).get("name").toString()); + } + + if (billItemObjects.get(i).get("description") != null) { + billItem.setDescription(billItemObjects.get(i).get("description").toString()); + } + + Context.getService(BillingItemService.class).saveBillingItem(billItem); + + BillingItemAdjustment adjust = new BillingItemAdjustment(); + adjust.setBillItemId(billItem.getbillItemId()); + + if (billItemObjects.get(i).get("discount") != null) { + adjust.setValue(Integer.parseInt(billItemObjects.get(i).get("discount").toString())); + } + + if (billItemObjects.get(i).get("discountReason") != null) { + adjust.setReason(billItemObjects.get(i).get("discountReason").toString()); + } + Context.getService(BillingItemAdjustmentService.class).saveBillingItemAdjustment(adjust); + + } + + } + + } + +} diff --git a/omod/src/main/java/org/raxa/module/raxacore/web/v1_0/controller/BillingItemAdjustmentController.java b/omod/src/main/java/org/raxa/module/raxacore/web/v1_0/controller/BillingItemAdjustmentController.java new file mode 100644 index 0000000000..c5fd778542 --- /dev/null +++ b/omod/src/main/java/org/raxa/module/raxacore/web/v1_0/controller/BillingItemAdjustmentController.java @@ -0,0 +1,108 @@ +package org.raxa.module.raxacore.web.v1_0.controller; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import java.text.SimpleDateFormat; +import java.util.Date; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import org.openmrs.Provider; +import org.openmrs.api.context.Context; +import org.openmrs.module.webservices.rest.SimpleObject; +import org.openmrs.module.webservices.rest.web.RestUtil; +import org.openmrs.module.webservices.rest.web.annotation.WSDoc; +import org.openmrs.module.webservices.rest.web.response.ResponseException; +import org.openmrs.module.webservices.rest.web.v1_0.controller.BaseRestController; +import org.raxa.module.raxacore.BillingItemAdjustment; +import org.raxa.module.raxacore.BillingItemAdjustmentService; +import org.springframework.stereotype.Controller; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.ResponseBody; + +/** + * Controller for REST web service access to the BillingItem resource. + */ + +@Controller +@RequestMapping(value = "/rest/v1/raxacore/billingitemadjustment") +public class BillingItemAdjustmentController extends BaseRestController { + + BillingItemAdjustmentService service; + + Gson gson = new GsonBuilder().serializeNulls().create(); + + private static final String[] REF = { "uuid", "billId", "value", "reason" }; + + public void initBillingItemAdjustmentController() { + service = Context.getService(BillingItemAdjustmentService.class); + } + + private String getResourceVersion() { + return "1.0"; + } + + @Transactional + @RequestMapping(method = RequestMethod.POST) + @WSDoc("Save BillItemAdjustment") + @ResponseBody + public Object saveBillItem(@RequestBody SimpleObject post, HttpServletRequest request, HttpServletResponse response) + throws ResponseException { + initBillingItemAdjustmentController(); + BillingItemAdjustment billItem = new BillingItemAdjustment(); + + if (post.get("reason") != null) { + billItem.setReason((post.get("reason").toString())); + } + + if (post.get("billId") != null) { + billItem.setBillItemId(Integer.parseInt(post.get("billId").toString())); + } + + if (post.get("value") != null) { + billItem.setValue(Integer.parseInt(post.get("value").toString())); + } + + if (post.get("name") != null) { + billItem.setName(post.get("name").toString()); + } + + if (post.get("description") != null) { + billItem.setDescription(post.get("description").toString()); + } + + BillingItemAdjustment created; + SimpleObject obj = obj = new SimpleObject(); + ; + try { + created = service.saveBillingItemAdjustment(billItem); + + obj.add("uuid", created.getUuid()); + obj.add("billId", created.getBillItem()); + + } + catch (Exception e) { + System.out.println("helllloooooo errroorr ocuuured"); + e.printStackTrace(); + } + return RestUtil.created(response, obj); + + } + + @RequestMapping(value = "/{uuid}", method = RequestMethod.GET) + @WSDoc("Gets bill by the uuid path") + @ResponseBody() + public String getBillItemAdjustmentByUuid(@PathVariable("uuid") String uuid, HttpServletRequest request) + throws ResponseException { + initBillingItemAdjustmentController(); + BillingItemAdjustment billItem = service.getBillingItemAdjustmentByUuid(uuid); + SimpleObject obj = new SimpleObject(); + obj.add("uuid", billItem.getUuid()); + obj.add("billId", billItem.getBillItemId()); + + return gson.toJson(obj); + } +} diff --git a/omod/src/main/java/org/raxa/module/raxacore/web/v1_0/controller/BillingItemController.java b/omod/src/main/java/org/raxa/module/raxacore/web/v1_0/controller/BillingItemController.java new file mode 100644 index 0000000000..396b5799e5 --- /dev/null +++ b/omod/src/main/java/org/raxa/module/raxacore/web/v1_0/controller/BillingItemController.java @@ -0,0 +1,192 @@ +package org.raxa.module.raxacore.web.v1_0.controller; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import org.openmrs.Provider; +import org.openmrs.api.context.Context; +import org.openmrs.module.webservices.rest.SimpleObject; +import org.openmrs.module.webservices.rest.web.RestUtil; +import org.openmrs.module.webservices.rest.web.annotation.WSDoc; +import org.openmrs.module.webservices.rest.web.response.ResponseException; +import org.openmrs.module.webservices.rest.web.v1_0.controller.BaseRestController; +import org.raxa.module.raxacore.Billing; +import org.raxa.module.raxacore.BillingItem; +import org.raxa.module.raxacore.BillingItemAdjustment; +import org.raxa.module.raxacore.BillingItemAdjustmentService; +import org.raxa.module.raxacore.BillingItemService; +import org.raxa.module.raxacore.BillingService; +import org.raxa.module.raxacore.impl.BillingServiceImpl; +import org.springframework.stereotype.Controller; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; + +/** + * Controller for REST web service access to the BillingItem resource. + */ + +@Controller +@Transactional +@RequestMapping(value = "/rest/v1/raxacore/billingitem") +public class BillingItemController extends BaseRestController { + + BillingItemService service; + + Gson gson = new GsonBuilder().serializeNulls().create(); + + private static final String[] REF = { "uuid", "billId", "conceptId", "providerId", "encounterId", "orderId" }; + + public void initBillingItemController() { + service = Context.getService(BillingItemService.class); + } + + private String getResourceVersion() { + return "1.0"; + } + + @RequestMapping(method = RequestMethod.POST) + @WSDoc("Save BillItem") + @ResponseBody + public Object saveBillItem(@RequestBody SimpleObject post, HttpServletRequest request, HttpServletResponse response) + throws ResponseException { + initBillingItemController(); + BillingItem billItem = new BillingItem(); + //drugInventory.setName(post.get("name").toString()); + //drugInventory.setDescription(post.get("description").toString()); + //drugInventory.setUuid(post.get("uuid").toString()); + + if (post.get("billId") != null) { + billItem.setBillId(Integer.parseInt(post.get("billId").toString())); + } + if (post.get("conceptId") != null) { + + billItem.setConceptId(Integer.parseInt(post.get("conceptId").toString())); + billItem.setConcept(Context.getConceptService().getConcept(Integer.parseInt(post.get("conceptId").toString()))); + + } + if (post.get("encounterId") != null) { + billItem.setEncounterId(Integer.parseInt(post.get("encounterId").toString())); + billItem.setEncounter(Context.getEncounterService().getEncounter( + Integer.parseInt(post.get("encounterId").toString()))); + + } + if (post.get("providerId") != null) { + billItem.setProviderId(Integer.parseInt(post.get("providerId").toString())); + billItem.setProvider(Context.getProviderService().getProvider( + Integer.parseInt(post.get("providerId").toString()))); + + } + + if (post.get("orderId") != null) { + billItem.setOrderId(Integer.parseInt(post.get("orderId").toString())); + billItem.setOrder(Context.getOrderService().getOrder(Integer.parseInt(post.get("orderId").toString()))); + + } + + if (post.get("quantity") != null) { + billItem.setQuantity(Integer.parseInt(post.get("quantity").toString())); + } + + if (post.get("value") != null) { + billItem.setValue(Integer.parseInt(post.get("value").toString())); + } + + if (post.get("name") != null) { + billItem.setName(post.get("name").toString()); + } + + if (post.get("description") != null) { + billItem.setDescription(post.get("description").toString()); + } + + BillingItem created; + SimpleObject obj = obj = new SimpleObject(); + ; + try { + created = service.saveBillingItem(billItem); + + obj.add("uuid", created.getUuid()); + obj.add("billId", created.getBillId()); + obj.add("providerId", created.getProviderId()); + obj.add("orderId", created.getOrderId()); + obj.add("encounterId", created.getEncounterId()); + obj.add("conceptId", created.getConceptId()); + } + catch (Exception e) { + System.out.println("helllloooooo errroorr ocuuured"); + e.printStackTrace(); + } + return RestUtil.created(response, obj); + + } + + @RequestMapping(value = "/{uuid}", method = RequestMethod.GET) + @WSDoc("Gets bill by the uuid path") + @ResponseBody() + public String getBillItemByUuid(@PathVariable("uuid") String uuid, HttpServletRequest request) throws ResponseException { + initBillingItemController(); + BillingItem billItem = service.getBillingItemByUuid(uuid); + SimpleObject obj = new SimpleObject(); + obj.add("uuid", billItem.getUuid()); + obj.add("billId", billItem.getBillId()); + obj.add("conceptId", billItem.getConceptId()); + obj.add("orderId", billItem.getOrderId()); + obj.add("encounterId", billItem.getEncounterId()); + obj.add("providerId", billItem.getProviderId()); + + return gson.toJson(obj); + } + /** + *Gets all billingItems and its adjustments given Bill Id + * @param query + * @param request + * @return + * @throws ResponseException + */ + @RequestMapping(method = RequestMethod.GET, params = "q") + @WSDoc("Gets All Biiling Items by Bill Id") + @ResponseBody() + public String getPatientListsByName(@RequestParam("q") Integer query, HttpServletRequest request) + throws ResponseException { + initBillingItemController(); + + List getAllBillingItemsByBill = service.getAllBillingItemsByBill(query); + ArrayList results = new ArrayList(); + for (BillingItem patientList : getAllBillingItemsByBill) { + SimpleObject obj = new SimpleObject(); + + List adjust = Context.getService(BillingItemAdjustmentService.class) + .getAllBillingItemAdjustmentsByBillingItem(patientList.getbillItemId()); + + for (BillingItemAdjustment adj : adjust) { + obj.add("Olddiscount", adj.getValue()); + obj.add("OlddiscountReason", adj.getReason()); + } + + obj.add("Olduuid", patientList.getUuid()); + obj.add("OldbillItemId", patientList.getbillItemId()); + obj.add("Oldquantity", patientList.getQuantity()); + obj.add("Oldname", patientList.getName()); + obj.add("Olddescription", patientList.getDescription()); + obj.add("OldproviderId", patientList.getProviderId()); + + obj.add("Oldvalue", patientList.getValue()); + obj.add("OlddateCreated", patientList.getDateCreated()); + + results.add(obj); + } + return gson.toJson(new SimpleObject().add("results", results)); + } + +} From 6969436658a9b5bc6f26a020398e25d55d8be359 Mon Sep 17 00:00:00 2001 From: Abhis Date: Thu, 20 Dec 2012 13:10:40 +0530 Subject: [PATCH 6/6] Billing Updated --- .../BillingItemAdjustmentService.java | 6 +- .../module/raxacore/BillingItemService.java | 5 +- .../raxa/module/raxacore/BillingService.java | 6 +- .../raxa/module/raxacore/db/BillingDAO.java | 5 ++ .../db/hibernate/HibernateBillingDAO.java | 11 ++++ .../raxacore/impl/BillingServiceImpl.java | 8 +++ .../v1_0/controller/BillingController.java | 60 ++++++++++++++++++- .../controller/BillingItemController.java | 1 + 8 files changed, 94 insertions(+), 8 deletions(-) diff --git a/api/src/main/java/org/raxa/module/raxacore/BillingItemAdjustmentService.java b/api/src/main/java/org/raxa/module/raxacore/BillingItemAdjustmentService.java index bdba0d5bfe..725e065ba9 100644 --- a/api/src/main/java/org/raxa/module/raxacore/BillingItemAdjustmentService.java +++ b/api/src/main/java/org/raxa/module/raxacore/BillingItemAdjustmentService.java @@ -25,8 +25,9 @@ import org.springframework.transaction.annotation.Transactional; public interface BillingItemAdjustmentService extends OpenmrsService { - + BillingItemAdjustment saveBillingItemAdjustment(BillingItemAdjustment adjustment) throws DAOException; + /** * saves a billing adjustment * @param adjustment @@ -34,6 +35,7 @@ public interface BillingItemAdjustmentService extends OpenmrsService { * @throws DAOException */ void deleteBillingItemAdjustment(BillingItemAdjustment adjustment) throws DAOException; + /** * delete a billing adjustment * @param adjustment @@ -41,6 +43,7 @@ public interface BillingItemAdjustmentService extends OpenmrsService { * @throws DAOException */ BillingItemAdjustment getBillingItemAdjustmentByUuid(String uuid); + /** * get a billing adjustment by uuid * @param adjustment @@ -66,6 +69,7 @@ public interface BillingItemAdjustmentService extends OpenmrsService { */ BillingItemAdjustment updateBillingItemAdjustment(BillingItemAdjustment adjustment); + /** *update billing adjustment given id * @param adjustment diff --git a/api/src/main/java/org/raxa/module/raxacore/BillingItemService.java b/api/src/main/java/org/raxa/module/raxacore/BillingItemService.java index bf93c22431..b4a433e0f1 100644 --- a/api/src/main/java/org/raxa/module/raxacore/BillingItemService.java +++ b/api/src/main/java/org/raxa/module/raxacore/BillingItemService.java @@ -26,14 +26,13 @@ public interface BillingItemService extends OpenmrsService { - BillingItem saveBillingItem(BillingItem item) throws DAOException; //saves a billingItem BillingItem getBillingItem(int billItemId) throws DAOException; //get billingitem by id - void deleteBillingItem(BillingItem item) throws DAOException; //delete billing item + void deleteBillingItem(BillingItem item) throws DAOException; //delete billing item - BillingItem getBillingItemByUuid(String uuid); // get billing item by uuid + BillingItem getBillingItemByUuid(String uuid); // get billing item by uuid List getAllBillingItems() throws DAOException; // get all billing items diff --git a/api/src/main/java/org/raxa/module/raxacore/BillingService.java b/api/src/main/java/org/raxa/module/raxacore/BillingService.java index 14503413c6..e4d637053f 100644 --- a/api/src/main/java/org/raxa/module/raxacore/BillingService.java +++ b/api/src/main/java/org/raxa/module/raxacore/BillingService.java @@ -38,10 +38,12 @@ public interface BillingService extends OpenmrsService { Billing updateBill(Billing bill); // update a bill - Billing getBill(int billId); // get a bill given its id + Billing getBill(int billId); // get a bill given its id - List getAllBillsByProvider(Integer providerId); // get all bills for Provider given providerId + List getAllBillsByProvider(Integer providerId); // get all bills for Provider given providerId List getAllBillsByPatient(Integer patientId); //get all bills for patient given patientId + List getEncountersByPatientId(Integer patientId); + } diff --git a/api/src/main/java/org/raxa/module/raxacore/db/BillingDAO.java b/api/src/main/java/org/raxa/module/raxacore/db/BillingDAO.java index 2f5bb6f59a..a1af8308b0 100644 --- a/api/src/main/java/org/raxa/module/raxacore/db/BillingDAO.java +++ b/api/src/main/java/org/raxa/module/raxacore/db/BillingDAO.java @@ -17,6 +17,8 @@ */ import java.util.List; + +import org.openmrs.Encounter; import org.openmrs.api.db.DAOException; import org.raxa.module.raxacore.Billing; @@ -39,4 +41,7 @@ public interface BillingDAO { public List getAllBillsByProvider(Integer providerId); public List getAllBillsByPatient(Integer patientId); + + public List getEncountersByPatientId(Integer patientId); + } diff --git a/api/src/main/java/org/raxa/module/raxacore/db/hibernate/HibernateBillingDAO.java b/api/src/main/java/org/raxa/module/raxacore/db/hibernate/HibernateBillingDAO.java index 47b8be5d7a..b6431713ed 100644 --- a/api/src/main/java/org/raxa/module/raxacore/db/hibernate/HibernateBillingDAO.java +++ b/api/src/main/java/org/raxa/module/raxacore/db/hibernate/HibernateBillingDAO.java @@ -21,6 +21,7 @@ import org.hibernate.Criteria; import org.hibernate.SessionFactory; import org.hibernate.criterion.Restrictions; +import org.openmrs.Encounter; import org.openmrs.api.db.DAOException; import org.raxa.module.raxacore.Billing; import org.raxa.module.raxacore.db.BillingDAO; @@ -113,4 +114,14 @@ public List getAllBillsByPatient(Integer patientId) { bills.addAll(criteria.list()); return bills; } + + @Transactional + public List getEncountersByPatientId(Integer patientId) { + Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Encounter.class); + criteria.add(Restrictions.eq("patientId", patientId)); + List bills = new ArrayList(); + bills.addAll(criteria.list()); + return bills; + } + } diff --git a/api/src/main/java/org/raxa/module/raxacore/impl/BillingServiceImpl.java b/api/src/main/java/org/raxa/module/raxacore/impl/BillingServiceImpl.java index cfdcf5f29f..604f7d4d06 100644 --- a/api/src/main/java/org/raxa/module/raxacore/impl/BillingServiceImpl.java +++ b/api/src/main/java/org/raxa/module/raxacore/impl/BillingServiceImpl.java @@ -23,6 +23,7 @@ import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.openmrs.Encounter; import org.openmrs.Patient; import org.openmrs.api.context.Context; import org.raxa.module.raxacore.Billing; @@ -85,4 +86,11 @@ public List getAllBillsByProvider(Integer providerId) { public List getAllBillsByPatient(Integer patientId) { return dao.getAllBillsByPatient(patientId); } + + @Override + public List getEncountersByPatientId(Integer patientId) { + // TODO Auto-generated method stub + return dao.getEncountersByPatientId(patientId); + + } } diff --git a/omod/src/main/java/org/raxa/module/raxacore/web/v1_0/controller/BillingController.java b/omod/src/main/java/org/raxa/module/raxacore/web/v1_0/controller/BillingController.java index ddad21c32e..d6e663f25e 100644 --- a/omod/src/main/java/org/raxa/module/raxacore/web/v1_0/controller/BillingController.java +++ b/omod/src/main/java/org/raxa/module/raxacore/web/v1_0/controller/BillingController.java @@ -10,7 +10,10 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; + +import org.openmrs.Encounter; import org.openmrs.Provider; +import org.openmrs.api.EncounterService; import org.openmrs.api.context.Context; import org.openmrs.module.webservices.rest.SimpleObject; import org.openmrs.module.webservices.rest.web.RestUtil; @@ -44,18 +47,23 @@ public class BillingController extends BaseRestController { BillingService service; + EncounterService serve; + Gson gson = new GsonBuilder().serializeNulls().create(); private static final String[] REF = { "uuid", "patientId", "status", "providerId", "name", "description", "billId", - "dateCreated", "balance", "totalAmount" }; + "dateCreated", "balance", "totalAmount", "encounterId", "category", "item_name", "quantity", "price", + "doscountReason" }; public void initBillingController() { service = Context.getService(BillingService.class); + serve = Context.getEncounterService(); } private String getResourceVersion() { return "1.0"; } + /** * * @param post @@ -135,7 +143,6 @@ public String getBillByUuid(@PathVariable("uuid") String uuid, HttpServletReques return gson.toJson(obj); } - /** * * @param query @@ -169,6 +176,55 @@ public String getPatientListsByName(@RequestParam("q") Integer query, HttpServle return gson.toJson(new SimpleObject().add("results", results)); } + /** + * + * @param query + * @param request + * @return + * @throws ResponseException + gets all encounters by patientID + */ + @RequestMapping(method = RequestMethod.GET, params = "v") + @WSDoc("Gets All Encounters by patientId") + @ResponseBody() + public String getEncountersByPatientId(@RequestParam("v") Integer query, HttpServletRequest request) + throws ResponseException { + initBillingController(); + + List all = serve.getEncountersByPatientId(query); + ArrayList results = new ArrayList(); + for (Encounter patientList : all) { + SimpleObject obj = new SimpleObject(); + // obj.add("uuid", patientList.getUuid()); + obj.add("item_name", "EncounterId:" + patientList.getEncounterId().toString()); + // obj.add("providerId", patientList.getProvidersByRoles()); + obj.add("discountReason", patientList.getDateCreated()); + + if (patientList.getEncounterType().getEncounterTypeId().toString().compareTo("1") == 0) { + obj.add("category", "ADULTINITIAL"); + } + if (patientList.getEncounterType().getEncounterTypeId().toString().compareTo("2") == 0) { + obj.add("category", "ADULTRETURN"); + } + + else if (patientList.getEncounterType().getEncounterTypeId().toString().compareTo("5") == 0) { + obj.add("category", "OUTPATIENT"); + } else if (patientList.getEncounterType().getEncounterTypeId().toString().compareTo("6") == 0) { + obj.add("category", "REGISTRATION"); + } else if (patientList.getEncounterType().getEncounterTypeId().toString().compareTo("7") == 0) { + obj.add("category", "PRESCRIPTION"); + } + + obj.add("quantity", "1"); + obj.add("price", "500"); + + results.add(obj); + + } + + return gson.toJson(new SimpleObject().add("results", results)); + } + /** * Saves billing Items in bill * @param post diff --git a/omod/src/main/java/org/raxa/module/raxacore/web/v1_0/controller/BillingItemController.java b/omod/src/main/java/org/raxa/module/raxacore/web/v1_0/controller/BillingItemController.java index 396b5799e5..12482567ce 100644 --- a/omod/src/main/java/org/raxa/module/raxacore/web/v1_0/controller/BillingItemController.java +++ b/omod/src/main/java/org/raxa/module/raxacore/web/v1_0/controller/BillingItemController.java @@ -147,6 +147,7 @@ public String getBillItemByUuid(@PathVariable("uuid") String uuid, HttpServletRe return gson.toJson(obj); } + /** *Gets all billingItems and its adjustments given Bill Id * @param query