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
new file mode 100644
index 0000000000..aeffe6ca50
--- /dev/null
+++ b/api/src/main/java/org/raxa/module/raxacore/Billing.java
@@ -0,0 +1,124 @@
+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;
+
+/**
+ * Billing stores the attributes of a bill
+ */
+public class Billing extends BaseOpenmrsMetadata implements Serializable {
+
+ private Integer billId;
+
+ private String status;
+
+ private Integer providerId;
+
+ private Integer patientId;
+
+ private Integer totalAmount;
+
+ private Integer balance;
+
+ 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 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;
+ }
+
+ 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..360cf83f62
--- /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;
+
+/**
+ * BillingItemAdjustments stores the data of billingitems in the bill like discounts , reason of discount .
+ */
+
+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..725e065ba9
--- /dev/null
+++ b/api/src/main/java/org/raxa/module/raxacore/BillingItemAdjustmentService.java
@@ -0,0 +1,88 @@
+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;
+
+ /**
+ * 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
new file mode 100644
index 0000000000..b4a433e0f1
--- /dev/null
+++ b/api/src/main/java/org/raxa/module/raxacore/BillingItemService.java
@@ -0,0 +1,51 @@
+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; //saves a billingItem
+
+ BillingItem getBillingItem(int billItemId) throws DAOException; //get billingitem by id
+
+ void deleteBillingItem(BillingItem item) throws DAOException; //delete billing item
+
+ BillingItem getBillingItemByUuid(String uuid); // get billing item by uuid
+
+ List getAllBillingItems() throws DAOException; // get all billing items
+
+ List getAllBillingItemsByBill(Integer billid); //get all billing items in bill by billid
+
+ BillingItem updateBillingItem(BillingItem item); //update billing item
+
+ List getAllBillingItemsByProvider(Integer providerId); //get billing item by providerId
+
+ 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
new file mode 100644
index 0000000000..e4d637053f
--- /dev/null
+++ b/api/src/main/java/org/raxa/module/raxacore/BillingService.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 BillingService extends OpenmrsService {
+
+ Billing saveBill(Billing bill) throws DAOException; //save a bill
+
+ void deleteBill(Billing bill) throws DAOException; //delete a bill
+
+ Billing getBillByPatientUuid(String uuid); // get all bills of a patient given its uuuid
+
+ List getAllBills() throws DAOException; //get all bills
+
+ List getAllBillsByStatus(String status); //get all bills by status
+
+ 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 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
new file mode 100644
index 0000000000..a1af8308b0
--- /dev/null
+++ b/api/src/main/java/org/raxa/module/raxacore/db/BillingDAO.java
@@ -0,0 +1,47 @@
+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.Encounter;
+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 Billing getBill(int billId);
+
+ 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/BillingItemAdjustmentDAO.java b/api/src/main/java/org/raxa/module/raxacore/db/BillingItemAdjustmentDAO.java
new file mode 100644
index 0000000000..5fcb103bfa
--- /dev/null
+++ b/api/src/main/java/org/raxa/module/raxacore/db/BillingItemAdjustmentDAO.java
@@ -0,0 +1,41 @@
+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;
+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);
+
+ BillingItemAdjustment getBillingItemAdjustment(int billItemAdjustmentId);
+
+ 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..148a6d30a5
--- /dev/null
+++ b/api/src/main/java/org/raxa/module/raxacore/db/BillingItemDAO.java
@@ -0,0 +1,47 @@
+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);
+
+ BillingItem getBillingItem(int billItemId);
+
+ 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..b6431713ed
--- /dev/null
+++ b/api/src/main/java/org/raxa/module/raxacore/db/hibernate/HibernateBillingDAO.java
@@ -0,0 +1,127 @@
+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.Encounter;
+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 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) {
+
+ Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Billing.class);
+ criteria.add(Restrictions.eq("providerId", providerId));
+ List bills = new ArrayList();
+ bills.addAll(criteria.list());
+ 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;
+ }
+
+ @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/db/hibernate/HibernateBillingItemAdjustmentDAO.java b/api/src/main/java/org/raxa/module/raxacore/db/hibernate/HibernateBillingItemAdjustmentDAO.java
new file mode 100644
index 0000000000..ecb3cc19bb
--- /dev/null
+++ b/api/src/main/java/org/raxa/module/raxacore/db/hibernate/HibernateBillingItemAdjustmentDAO.java
@@ -0,0 +1,96 @@
+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 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);
+ 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..bd0750ff3c
--- /dev/null
+++ b/api/src/main/java/org/raxa/module/raxacore/db/hibernate/HibernateBillingItemDAO.java
@@ -0,0 +1,133 @@
+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 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);
+ 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/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/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..d17b4afdfd
--- /dev/null
+++ b/api/src/main/java/org/raxa/module/raxacore/impl/BillingItemAdjustmentServiceImpl.java
@@ -0,0 +1,82 @@
+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 BillingItemAdjustment getBillingItemAdjustment(int billItemAdjustmentId) {
+ return dao.getBillingItemAdjustment(billItemAdjustmentId);
+ }
+
+ 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..0a52d97b7c
--- /dev/null
+++ b/api/src/main/java/org/raxa/module/raxacore/impl/BillingItemServiceImpl.java
@@ -0,0 +1,96 @@
+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 BillingItem getBillingItem(int billItemId)
+
+ {
+ return dao.getBillingItem(billItemId);
+ }
+
+ 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..604f7d4d06
--- /dev/null
+++ b/api/src/main/java/org/raxa/module/raxacore/impl/BillingServiceImpl.java
@@ -0,0 +1,96 @@
+package org.raxa.module.raxacore.impl;
+
+/**
+ * Copyright 2012, Raxa
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.openmrs.Encounter;
+import org.openmrs.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 Billing getBill(int billId) {
+ return dao.getBill(billId);
+ }
+
+ 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);
+ }
+
+ 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/api/src/main/resources/RaxacoreBilling.hbm.xml b/api/src/main/resources/RaxacoreBilling.hbm.xml
new file mode 100644
index 0000000000..a1877eb293
--- /dev/null
+++ b/api/src/main/resources/RaxacoreBilling.hbm.xml
@@ -0,0 +1,36 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/api/src/main/resources/RaxacoreBillingItem.hbm.xml b/api/src/main/resources/RaxacoreBillingItem.hbm.xml
new file mode 100644
index 0000000000..eec3cf4ec5
--- /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..b24aedfc7c
--- /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 a1a288bfca..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,5 +515,529 @@
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
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Alter Schema for raxacore_billing_item
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ 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/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/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/api/src/test/resources/TestingApplicationContext.xml b/api/src/test/resources/TestingApplicationContext .xml
similarity index 65%
rename from api/src/test/resources/TestingApplicationContext.xml
rename to api/src/test/resources/TestingApplicationContext .xml
index f513c8c2d9..210341ce8d 100644
--- a/api/src/test/resources/TestingApplicationContext.xml
+++ b/api/src/test/resources/TestingApplicationContext .xml
@@ -32,7 +32,12 @@
-
+
+
+
+
+
+
@@ -133,7 +138,64 @@
-
+
+
+
+ org.raxa.module.raxacore.BillingService
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ org.raxa.module.raxacore.BillingItemService
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
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/BillingController.java b/omod/src/main/java/org/raxa/module/raxacore/web/v1_0/controller/BillingController.java
new file mode 100644
index 0000000000..d6e663f25e
--- /dev/null
+++ b/omod/src/main/java/org/raxa/module/raxacore/web/v1_0/controller/BillingController.java
@@ -0,0 +1,282 @@
+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.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;
+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;
+
+ EncounterService serve;
+
+ Gson gson = new GsonBuilder().serializeNulls().create();
+
+ private static final String[] REF = { "uuid", "patientId", "status", "providerId", "name", "description", "billId",
+ "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
+ * @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));
+ }
+
+ /**
+ *
+ * @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
+ * @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..12482567ce
--- /dev/null
+++ b/omod/src/main/java/org/raxa/module/raxacore/web/v1_0/controller/BillingItemController.java
@@ -0,0 +1,193 @@
+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));
+ }
+
+}
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..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
@@ -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;
@@ -31,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;
@@ -42,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 {
@@ -69,9 +73,14 @@ 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.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());
+ drugInventory.setRetired(false);
if (post.get("originalQuantity") != null) {
drugInventory.setOriginalQuantity(Integer.parseInt(post.get("originalQuantity").toString()));
}
@@ -93,14 +102,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..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
@@ -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;
@@ -15,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;
@@ -26,6 +29,7 @@
*/
@Controller
+@Transactional
@RequestMapping(value = "/rest/v1/raxacore/drugpurchaseorder")
public class DrugPurchaseOrderController extends BaseRestController {
@@ -65,32 +69,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);
+
}
//
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