diff --git a/omods/core/api/src/main/java/org/openmrs/module/icare/billing/BillingServiceImpl.java b/omods/core/api/src/main/java/org/openmrs/module/icare/billing/BillingServiceImpl.java index 2c8f6416d..b41fb8759 100644 --- a/omods/core/api/src/main/java/org/openmrs/module/icare/billing/BillingServiceImpl.java +++ b/omods/core/api/src/main/java/org/openmrs/module/icare/billing/BillingServiceImpl.java @@ -34,6 +34,7 @@ import javax.naming.ConfigurationException; import java.io.IOException; +import java.text.SimpleDateFormat; import java.time.LocalDateTime; import java.time.ZoneId; import java.time.format.DateTimeFormatter; @@ -774,7 +775,10 @@ public Map processGepgCallbackResponse(Map callb Map status = (Map) callbackData.get("Status"); Map feedbackData = (Map) callbackData.get("FeedbackData"); - + GlobalProperty globalProperty = new GlobalProperty(); + globalProperty.setProperty("gepg.callbackResponseData.icareConnect"); + globalProperty.setPropertyValue(callbackData.toString()); + administrationService.saveGlobalProperty(globalProperty); if (feedbackData.containsKey("gepgPmtSpInfo")) { Map gepgPmtSpInfo = (Map) feedbackData.get("gepgPmtSpInfo"); Map pymtTrxInf = (Map) gepgPmtSpInfo.get("PymtTrxInf"); @@ -782,7 +786,7 @@ public Map processGepgCallbackResponse(Map callb Payment payment = this.paymentDAO.getPaymentByRequestId(Integer.parseInt(requestId)); if (payment != null) { - payment.setReferenceNumber((String) pymtTrxInf.get("PspReceiptNumber")); + payment.setReferenceNumber((String) pymtTrxInf.get("PayCtrNum")); payment.setBillAmount(Double.parseDouble((String) pymtTrxInf.get("BillAmt"))); payment.setPaidAmount(Double.parseDouble((String) pymtTrxInf.get("PaidAmt"))); LocalDateTime localDateTime = LocalDateTime.parse((String) pymtTrxInf.get("TrxDtTm")); @@ -825,6 +829,7 @@ public Map processGepgCallbackResponse(Map callb Map billTrxInf = (Map) gepgBillSubResp.get("BillTrxInf"); String billIdString = (String) billTrxInf.get("BillId"); + String payCntrNum = (String) billTrxInf.get("PayCntrNum"); String requestId = status.containsKey("RequestId") ? (String) status.get("RequestId") : null; @@ -897,6 +902,10 @@ public Map processGepgCallbackResponse(Map callb response.put("SystemAuth", systemAuth); response.put("AckData", ackData); + } else { + String requestId = status.containsKey("RequestId") ? (String) status.get("RequestId") : null; + return buildErrorResponse(response, systemAuth, ackData, requestId, + "Encounter an Error on response"); } } else { @@ -945,7 +954,7 @@ public List getAllPaymentsWithStatus() throws Exception { return paymentDAO.findByPaymentTypeId(paymentTypeId); } - public String fetchControlNumber(String requestId) throws Exception { + public String fetchControlNumber(Integer requestId) throws Exception { String controlNumber = null; long startTime = System.currentTimeMillis(); long timeout = 32000; @@ -971,133 +980,391 @@ public String fetchControlNumber(String requestId) throws Exception { } // create payload for GePG Control Number Generation + // @Override + // public Map createGePGPayload(Patient patient, + // List invoiceItems, + // Number totalBillAmount, + // Date billExpirlyDate, String personPhoneAttributeTypeUuid, String + // personEmailAttributeTypeUuid, + // String currency, + // String gepgAuthSignature, String GFSCodeConceptSourceMappingUuid, String + // spCode, String sytemCode, + // String serviceCode, String SpSysId, String subSpCode, String + // clientPrivateKey, String pkcs12Path, + // String pkcs12Password, String enginepublicKey, String billId) throws + // Exception { + // AdministrationService administrationService = + // Context.getAdministrationService(); + // // Validate inputs + // if (patient == null) { + // throw new IllegalArgumentException("Patient cannot be null"); + // } + // if (invoiceItems == null || invoiceItems.isEmpty()) { + // throw new IllegalArgumentException("Invoice items cannot be null or empty"); + // } + // if (currency == null) { + // throw new IllegalArgumentException("Currency cannot be null"); + // } + // if (gepgAuthSignature == null) { + // gepgAuthSignature = ""; + // } + // if (GFSCodeConceptSourceMappingUuid == null) { + // throw new IllegalArgumentException("GFS Code Concept Source Mapping UUID + // cannot be null"); + // } + // if (spCode == null || sytemCode == null || serviceCode == null || SpSysId == + // null || subSpCode == null) { + // String missingParams = ""; + // if (spCode == null) + // missingParams += "spCode "; + // if (sytemCode == null) + // missingParams += "systemCode "; + // if (serviceCode == null) + // missingParams += "serviceCode "; + // if (SpSysId == null) + // missingParams += "SpSysId "; + // if (subSpCode == null) + // missingParams += "subSpCode "; + // throw new IllegalArgumentException("Missing system parameters: " + + // missingParams.trim()); + // } + + // // Retrieve patient attributes + // String patientNames = patient.getGivenName() + " " + patient.getFamilyName(); + // String patientUuid = patient.getId().toString(); + // String patientPhoneNumber = ""; + // String email = ""; + // for (PersonAttribute attribute : patient.getAttributes()) { + // if (personPhoneAttributeTypeUuid != null + // && + // attribute.getAttributeType().getUuid().equals(personPhoneAttributeTypeUuid)) + // { + // patientPhoneNumber = attribute.getValue(); + // } else if (personEmailAttributeTypeUuid != null + // && + // attribute.getAttributeType().getUuid().equals(personEmailAttributeTypeUuid)) + // { + // email = attribute.getValue(); + // } + // } + + // // BillItems generation + + // BillItems billItems = new BillItems(); + + // for (InvoiceItem invoiceItem : invoiceItems) { + // Drug drug = invoiceItem.getItem().getDrug(); + // Concept concept = invoiceItem.getItem().getConcept(); + + // if (drug == null && concept == null) { + // throw new IllegalStateException("Concept can not be null for InvoiceItem" + + // drug + concept); + // } else if (concept != null) { + // for (ConceptMap conceptMap : concept.getConceptMappings()) { + // if (conceptMap.getConceptReferenceTerm().getConceptSource().getUuid() + // .equals(GFSCodeConceptSourceMappingUuid)) { + // String GFSCode = conceptMap.getConceptReferenceTerm().getCode(); + // billItems.getBillItem().add( + // new BillItem(invoiceItem.getItem().getId().toString(), "N", + // invoiceItem.getPrice().toString(), + // invoiceItem.getPrice().toString(), "0.0", GFSCode)); + // } else { + // throw new IllegalStateException( + // "Please verify GFS CODE concept mapping if configured in a correct way"); + // } + // } + // } else if (drug != null) { + // Concept drugConcept = drug.getConcept(); + // GlobalProperty globalProperty = new GlobalProperty(); + // for (ConceptMap conceptMap : drugConcept.getConceptMappings()) { + // if (conceptMap.getConceptReferenceTerm().getConceptSource().getUuid() + // .equals(GFSCodeConceptSourceMappingUuid)) { + // globalProperty.setProperty("iCare.gepg.DrugConcept.icareConnect"); + // globalProperty.setPropertyValue("if condition meet"); + // administrationService.saveGlobalProperty(globalProperty); + // String GFSCode = conceptMap.getConceptReferenceTerm().getCode(); + // billItems.getBillItem().add( + // new BillItem(invoiceItem.getItem().getId().toString(), "N", + // invoiceItem.getPrice().toString(), + // invoiceItem.getPrice().toString(), "0.0", GFSCode)); + // } else { + // throw new IllegalStateException( + // "Please verify GFS CODE concept mapping if configured in a correct way"); + // } + // } + // } + + // } + + // // Create and populate BillHdr + // BillHdr billHdr = new BillHdr(); + // billHdr.setSpCode(spCode); + // billHdr.setRtrRespFlg("true"); + + // // Create and populate BillTrxInf + // BillTrxInf billTrxInf = new BillTrxInf(); + // billTrxInf.setBillId(billId); + // billTrxInf.setSubSpCode(subSpCode); + // billTrxInf.setSpSysId(SpSysId); + // billTrxInf.setBillAmt(totalBillAmount.toString()); + // billTrxInf.setMiscAmt("0"); + // LocalDateTime now = LocalDateTime.now(); + // DateTimeFormatter formatter = + // DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss"); + // String formattedNow = now.format(formatter); + // billTrxInf.setBillGenDt(formattedNow); + + // LocalDateTime expirationTime = now.plusHours(24); + // String formattedExpirationTime = expirationTime.format(formatter); + // billTrxInf.setBillExprDt(formattedExpirationTime); + // billTrxInf.setPyrId("40"); + // billTrxInf.setPyrName(patientNames.toUpperCase()); + // billTrxInf.setBillDesc("Hospital Bill Payments"); + // billTrxInf.setBillGenBy("UDSM Hospital"); + // billTrxInf.setBillApprBy(patientNames.toUpperCase()); + // billTrxInf.setPyrCellNum(patientPhoneNumber); + // billTrxInf.setPyrEmail(email); + // billTrxInf.setCcy(currency); + // billTrxInf.setBillEqvAmt(totalBillAmount.toString()); + // billTrxInf.setRemFlag("false"); + // billTrxInf.setBillPayOpt("2"); + // billTrxInf.setBillItems(billItems); + // // Create and populate RequestData + // // Save PaymentData before Reference Number (Control Number) + // RequestData requestData = new RequestData(); + // try { + // Integer billUuid = Integer.parseInt(billId); + // Invoice invoice = invoiceDAO.findById(billUuid); + // if (invoice == null) { + // throw new Exception("Invoice of this Bill id " + billId + " is not valid"); + + // } + + // String paymentTypeConceptUuid = administrationService + // .getGlobalProperty(ICareConfig.DEFAULT_PAYMENT_TYPE_VIA_CONTROL_NUMBER); + // if (paymentTypeConceptUuid == null) { + // throw new Exception("No default payment type based on control number"); + // } + + // Concept paymentType = + // Context.getConceptService().getConceptByUuid(paymentTypeConceptUuid); + // if (paymentType == null) { + // throw new Exception("Payment type concept not found for UUID: " + + // paymentTypeConceptUuid); + // } + + // Payment payment = new Payment(); + // payment.setPaymentType(paymentType); + // payment.setReferenceNumber(null); + // payment.setInvoice(invoice); + // payment.setReceivedBy("SYSTEM"); + // payment.setStatus(PaymentStatus.REQUESTED); + // payment.setCreator(Context.getAuthenticatedUser()); + // payment.setDateCreated(new Date()); + // this.paymentDAO.save(payment); + // Integer paymentId = payment.getId(); + // requestData.setRequestId(paymentId.toString()); + // } catch (Exception e) { + // throw new Exception("Failed to Save Payments Data: " + e.getMessage()); + // } + + // requestData.setBillHdr(billHdr); + // requestData.setBillTrxInf(billTrxInf); + + // // Create and populate SystemAuth + // SystemAuth systemAuth = new SystemAuth(); + // systemAuth.setSystemCode(sytemCode); + // systemAuth.setServiceCode(serviceCode); + + // // Create and return BillSubmissionRequest + // BillSubmissionRequest billRequest = new BillSubmissionRequest(); + // billRequest.setSystemAuth(systemAuth); + // billRequest.setRequestData(requestData); + + // // Serialize RequestData to JSON for signing + // String requestDataJson = new ObjectMapper().writeValueAsString(requestData); + + // // Save the payload in a global property + // GlobalProperty globalProperty = new GlobalProperty(); + // globalProperty.setProperty("gepg.requestDataJson.icareConnect"); + // globalProperty.setPropertyValue(requestDataJson); + // administrationService.saveGlobalProperty(globalProperty); + + // // Sign the request data + // String signature = SignatureUtils.signData(requestDataJson, + // clientPrivateKey); + // systemAuth.setSignature(signature); + + // Map result = new HashMap<>(); + // result.put("billRequest", billRequest); + // result.put("signature", signature); + + // return result; + // } @Override public Map createGePGPayload(Patient patient, List invoiceItems, - Number totalBillAmount, - Date billExpirlyDate, String personPhoneAttributeTypeUuid, String personEmailAttributeTypeUuid, - String currency, - String gepgAuthSignature, String GFSCodeConceptSourceMappingUuid, String spCode, String sytemCode, - String serviceCode, String SpSysId, String subSpCode, String clientPrivateKey, String pkcs12Path, + Number totalBillAmount, Date billExpirlyDate, String personPhoneAttributeTypeUuid, + String personEmailAttributeTypeUuid, String currency, String gepgAuthSignature, + String GFSCodeConceptSourceMappingUuid, String spCode, String sytemCode, String serviceCode, + String SpSysId, String subSpCode, String clientPrivateKey, String pkcs12Path, String pkcs12Password, String enginepublicKey, String billId) throws Exception { - AdministrationService administrationService = Context.getAdministrationService(); + // Validate inputs - if (patient == null) { - throw new IllegalArgumentException("Patient cannot be null"); - } - if (invoiceItems == null || invoiceItems.isEmpty()) { - throw new IllegalArgumentException("Invoice items cannot be null or empty"); - } - if (currency == null) { - throw new IllegalArgumentException("Currency cannot be null"); - } - if (gepgAuthSignature == null) { - gepgAuthSignature = ""; - } - if (GFSCodeConceptSourceMappingUuid == null) { - throw new IllegalArgumentException("GFS Code Concept Source Mapping UUID cannot be null"); - } - if (spCode == null || sytemCode == null || serviceCode == null || SpSysId == null || subSpCode == null) { - String missingParams = ""; - if (spCode == null) - missingParams += "spCode "; - if (sytemCode == null) - missingParams += "systemCode "; - if (serviceCode == null) - missingParams += "serviceCode "; - if (SpSysId == null) - missingParams += "SpSysId "; - if (subSpCode == null) - missingParams += "subSpCode "; - throw new IllegalArgumentException("Missing system parameters: " + missingParams.trim()); - } + validateInputs(patient, invoiceItems, currency, gepgAuthSignature, GFSCodeConceptSourceMappingUuid, + spCode, sytemCode, serviceCode, SpSysId, subSpCode); // Retrieve patient attributes + String patientId = patient.getPatientId().toString(); String patientNames = patient.getGivenName() + " " + patient.getFamilyName(); - String patientUuid = patient.getId().toString(); - String patientPhoneNumber = ""; - String email = ""; - for (PersonAttribute attribute : patient.getAttributes()) { - if (personPhoneAttributeTypeUuid != null - && attribute.getAttributeType().getUuid().equals(personPhoneAttributeTypeUuid)) { - patientPhoneNumber = attribute.getValue(); - } else if (personEmailAttributeTypeUuid != null - && attribute.getAttributeType().getUuid().equals(personEmailAttributeTypeUuid)) { - email = attribute.getValue(); - } - } + String patientPhoneNumber = getPatientPhoneNumber(patient, personPhoneAttributeTypeUuid); + String email = getPatientEmail(patient, personEmailAttributeTypeUuid); // BillItems generation + BillItems billItems = createBillItems(invoiceItems, GFSCodeConceptSourceMappingUuid); - BillItems billItems = new BillItems(); + // Create and populate BillHdr + BillHdr billHdr = createBillHdr(spCode); + + // Create and populate BillTrxInf + BillTrxInf billTrxInf = createBillTrxInf(totalBillAmount, patientNames, patientPhoneNumber, email, + currency, billId, billExpirlyDate, billItems, subSpCode, SpSysId, patientId); + + // Create and populate RequestData + RequestData requestData = createRequestData(billHdr, billTrxInf, billId); + + // Create and populate SystemAuth + SystemAuth systemAuth = createSystemAuth(sytemCode, serviceCode); + + // Create the BillSubmissionRequest + BillSubmissionRequest billRequest = new BillSubmissionRequest(); + billRequest.setSystemAuth(systemAuth); + billRequest.setRequestData(requestData); + + // Serialize RequestData to JSON for signing + String requestDataJson = new ObjectMapper().writeValueAsString(requestData); + + // Sign the request data + String signature = SignatureUtils.signData(requestDataJson, clientPrivateKey); + systemAuth.setSignature(signature); + // Return the result + Map result = new LinkedHashMap<>(); + result.put("billRequest", billRequest); + result.put("signature", signature); + + return result; + } + + // Validate the inputs + private void validateInputs(Patient patient, List invoiceItems, String currency, String gepgAuthSignature, + String GFSCodeConceptSourceMappingUuid, String spCode, String sytemCode, String serviceCode, String SpSysId, + String subSpCode) { + if (patient == null || invoiceItems == null || invoiceItems.isEmpty() || currency == null || spCode == null + || sytemCode == null || serviceCode == null || SpSysId == null || subSpCode == null) { + throw new IllegalArgumentException("Invalid system inputs provided."); + } + } + + // Retrieve the patient phone number + private String getPatientPhoneNumber(Patient patient, String personPhoneAttributeTypeUuid) { + for (PersonAttribute attribute : patient.getAttributes()) { + if (attribute.getAttributeType().getUuid().equals(personPhoneAttributeTypeUuid)) { + return attribute.getValue(); + } + } + return ""; + } + + // Retrieve the patient email + private String getPatientEmail(Patient patient, String personEmailAttributeTypeUuid) { + for (PersonAttribute attribute : patient.getAttributes()) { + if (attribute.getAttributeType().getUuid().equals(personEmailAttributeTypeUuid)) { + return attribute.getValue(); + } + } + return ""; + } + + // Create BillItems + private BillItems createBillItems(List invoiceItems, String GFSCodeConceptSourceMappingUuid) { + BillItems billItems = new BillItems(); for (InvoiceItem invoiceItem : invoiceItems) { Drug drug = invoiceItem.getItem().getDrug(); Concept concept = invoiceItem.getItem().getConcept(); - if (drug == null && concept == null) { throw new IllegalStateException("Concept can not be null for InvoiceItem" + drug + concept); } else if (concept != null) { for (ConceptMap conceptMap : concept.getConceptMappings()) { if (conceptMap.getConceptReferenceTerm().getConceptSource().getUuid() - .equals(GFSCodeConceptSourceMappingUuid)) { + .equals(GFSCodeConceptSourceMappingUuid)) { String GFSCode = conceptMap.getConceptReferenceTerm().getCode(); billItems.getBillItem().add( - new BillItem(invoiceItem.getItem().getId().toString(), "N", - invoiceItem.getPrice().toString(), - invoiceItem.getPrice().toString(), "0.0", GFSCode)); + new BillItem(invoiceItem.getItem().getId().toString(), "N", invoiceItem.getPrice().toString(), + invoiceItem.getPrice().toString(), "0.0", GFSCode)); } else { throw new IllegalStateException( - "Please verify GFS CODE concept mapping if configured in a correct way"); + "Please verify GFS CODE concept mapping if configured in a correct way"); } } } else if (drug != null) { Concept drugConcept = drug.getConcept(); - GlobalProperty globalProperty = new GlobalProperty(); for (ConceptMap conceptMap : drugConcept.getConceptMappings()) { if (conceptMap.getConceptReferenceTerm().getConceptSource().getUuid() - .equals(GFSCodeConceptSourceMappingUuid)) { - globalProperty.setProperty("iCare.gepg.DrugConcept.icareConnect"); - globalProperty.setPropertyValue("if condition meet"); - administrationService.saveGlobalProperty(globalProperty); + .equals(GFSCodeConceptSourceMappingUuid)) { + String GFSCode = conceptMap.getConceptReferenceTerm().getCode(); billItems.getBillItem().add( - new BillItem(invoiceItem.getItem().getId().toString(), "N", - invoiceItem.getPrice().toString(), - invoiceItem.getPrice().toString(), "0.0", GFSCode)); + new BillItem(invoiceItem.getItem().getId().toString(), "N", invoiceItem.getPrice().toString(), + invoiceItem.getPrice().toString(), "0.0", GFSCode)); } else { throw new IllegalStateException( - "Please verify GFS CODE concept mapping if configured in a correct way"); + "Please verify GFS CODE concept mapping if configured in a correct way"); } } } - } - - // Create and populate BillHdr + return billItems; + } + + // Create BillHdr + private BillHdr createBillHdr(String spCode) { BillHdr billHdr = new BillHdr(); billHdr.setSpCode(spCode); billHdr.setRtrRespFlg("true"); - - // Create and populate BillTrxInf + return billHdr; + } + + // format Date + private String formatDate(Date date) { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); + return sdf.format(date); + } + + // Create BillTrxInf + private BillTrxInf createBillTrxInf(Number totalBillAmount, String patientNames, String patientPhoneNumber, + String email, String currency, String billId, Date billExpirlyDate, BillItems billItems, String subSpCode, + String SpSysId, String patientId) { + + Date now = new Date(); + + // Calculate 24 hours from BillGenDt + Calendar calendar = Calendar.getInstance(); + calendar.setTime(now); + calendar.add(Calendar.HOUR_OF_DAY, 24); + Date billExpiryDate = calendar.getTime(); BillTrxInf billTrxInf = new BillTrxInf(); billTrxInf.setBillId(billId); billTrxInf.setSubSpCode(subSpCode); billTrxInf.setSpSysId(SpSysId); billTrxInf.setBillAmt(totalBillAmount.toString()); billTrxInf.setMiscAmt("0"); - LocalDateTime now = LocalDateTime.now(); - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss"); - String formattedNow = now.format(formatter); - billTrxInf.setBillGenDt(formattedNow); - - LocalDateTime expirationTime = now.plusHours(24); - String formattedExpirationTime = expirationTime.format(formatter); - billTrxInf.setBillExprDt(formattedExpirationTime); - billTrxInf.setPyrId("40"); - billTrxInf.setPyrName(patientNames.toUpperCase()); + billTrxInf.setBillGenDt(formatDate(new Date())); + billTrxInf.setBillExprDt(formatDate(billExpiryDate)); + billTrxInf.setPyrId(patientId); + billTrxInf.setPyrName(patientNames); billTrxInf.setBillDesc("Hospital Bill Payments"); billTrxInf.setBillGenBy("UDSM Hospital"); - billTrxInf.setBillApprBy(patientNames.toUpperCase()); + billTrxInf.setBillApprBy("UDSM"); billTrxInf.setPyrCellNum(patientPhoneNumber); billTrxInf.setPyrEmail(email); billTrxInf.setCcy(currency); @@ -1105,7 +1372,12 @@ public Map createGePGPayload(Patient patient, List billTrxInf.setRemFlag("false"); billTrxInf.setBillPayOpt("2"); billTrxInf.setBillItems(billItems); - // Create and populate RequestData + return billTrxInf; + } + + // Create RequestData + private RequestData createRequestData(BillHdr billHdr, BillTrxInf billTrxInf, String billId) throws Exception { + AdministrationService administrationService = Context.getAdministrationService(); // Save PaymentData before Reference Number (Control Number) RequestData requestData = new RequestData(); try { @@ -1113,20 +1385,20 @@ public Map createGePGPayload(Patient patient, List Invoice invoice = invoiceDAO.findById(billUuid); if (invoice == null) { throw new Exception("Invoice of this Bill id " + billId + " is not valid"); - + } - + String paymentTypeConceptUuid = administrationService - .getGlobalProperty(ICareConfig.DEFAULT_PAYMENT_TYPE_VIA_CONTROL_NUMBER); + .getGlobalProperty(ICareConfig.DEFAULT_PAYMENT_TYPE_VIA_CONTROL_NUMBER); if (paymentTypeConceptUuid == null) { throw new Exception("No default payment type based on control number"); } - + Concept paymentType = Context.getConceptService().getConceptByUuid(paymentTypeConceptUuid); if (paymentType == null) { throw new Exception("Payment type concept not found for UUID: " + paymentTypeConceptUuid); } - + Payment payment = new Payment(); payment.setPaymentType(paymentType); payment.setReferenceNumber(null); @@ -1138,41 +1410,21 @@ public Map createGePGPayload(Patient patient, List this.paymentDAO.save(payment); Integer paymentId = payment.getId(); requestData.setRequestId(paymentId.toString()); - } catch (Exception e) { + } + catch (Exception e) { throw new Exception("Failed to Save Payments Data: " + e.getMessage()); } - requestData.setBillHdr(billHdr); requestData.setBillTrxInf(billTrxInf); - - // Create and populate SystemAuth + return requestData; + } + + // Create SystemAuth + private SystemAuth createSystemAuth(String sytemCode, String serviceCode) { SystemAuth systemAuth = new SystemAuth(); systemAuth.setSystemCode(sytemCode); systemAuth.setServiceCode(serviceCode); - - // Create and return BillSubmissionRequest - BillSubmissionRequest billRequest = new BillSubmissionRequest(); - billRequest.setSystemAuth(systemAuth); - billRequest.setRequestData(requestData); - - // Serialize RequestData to JSON for signing - String requestDataJson = new ObjectMapper().writeValueAsString(requestData); - - // Save the payload in a global property - GlobalProperty globalProperty = new GlobalProperty(); - globalProperty.setProperty("gepg.requestDataJson.icareConnect"); - globalProperty.setPropertyValue(requestDataJson); - administrationService.saveGlobalProperty(globalProperty); - - // Sign the request data - String signature = SignatureUtils.signData(requestDataJson, clientPrivateKey); - systemAuth.setSignature(signature); - - Map result = new HashMap<>(); - result.put("billRequest", billRequest); - result.put("signature", signature); - - return result; + return systemAuth; } @Override @@ -1181,7 +1433,7 @@ public String signatureData(String rowData) throws Exception { String clientPrivateKey = administrationService.getGlobalProperty(ICareConfig.CLIENT_PRIVATE_KEY); try { GlobalProperty globalProperty = new GlobalProperty(); - globalProperty.setProperty("gepg.callbackrowData.icareConnect"); + globalProperty.setProperty("gepg.signaturerowData.icareConnect"); globalProperty.setPropertyValue(rowData); administrationService.saveGlobalProperty(globalProperty); String signature = SignatureUtils.signData(rowData, clientPrivateKey); diff --git a/omods/core/api/src/main/java/org/openmrs/module/icare/billing/dao/PaymentDAO.java b/omods/core/api/src/main/java/org/openmrs/module/icare/billing/dao/PaymentDAO.java index 8c6b3a778..47165ea2c 100644 --- a/omods/core/api/src/main/java/org/openmrs/module/icare/billing/dao/PaymentDAO.java +++ b/omods/core/api/src/main/java/org/openmrs/module/icare/billing/dao/PaymentDAO.java @@ -52,7 +52,7 @@ public List findByPatientUuid(String patientUuid) { return query.list(); } - public String getReferenceNumberByRequestId(String requestId) { + public String getReferenceNumberByRequestId(Integer requestId) { DbSession session = this.getSession(); String queryStr = "SELECT p.referenceNumber FROM Payment p WHERE p.id = :requestId"; Query query = session.createQuery(queryStr); diff --git a/omods/core/api/src/main/java/org/openmrs/module/icare/billing/services/BillingService.java b/omods/core/api/src/main/java/org/openmrs/module/icare/billing/services/BillingService.java index b2aae4d51..84fd8ab16 100644 --- a/omods/core/api/src/main/java/org/openmrs/module/icare/billing/services/BillingService.java +++ b/omods/core/api/src/main/java/org/openmrs/module/icare/billing/services/BillingService.java @@ -86,7 +86,7 @@ public interface BillingService extends OpenmrsService { Map processGepgCallbackResponse(Map feedBack) throws Exception; - String fetchControlNumber(String requestId) throws Exception; + String fetchControlNumber(Integer requestId) throws Exception; List getAllPaymentsWithStatus() throws Exception; diff --git a/omods/core/api/src/main/java/org/openmrs/module/icare/billing/services/payment/gepg/BillTrxInf.java b/omods/core/api/src/main/java/org/openmrs/module/icare/billing/services/payment/gepg/BillTrxInf.java index 6916fd8b7..bf6e7e924 100644 --- a/omods/core/api/src/main/java/org/openmrs/module/icare/billing/services/payment/gepg/BillTrxInf.java +++ b/omods/core/api/src/main/java/org/openmrs/module/icare/billing/services/payment/gepg/BillTrxInf.java @@ -1,7 +1,11 @@ package org.openmrs.module.icare.billing.services.payment.gepg; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; import com.fasterxml.jackson.annotation.JsonProperty; +@JsonPropertyOrder({ "BillId", "SubSpCode", "SpSysId", "BillAmt", "MiscAmt", "BillExprDt", "PyrId", "PyrName", "BillDesc", + "BillGenDt", "BillGenBy", "BillApprBy", "PyrCellNum", "PyrEmail", "Ccy", "BillEqvAmt", "RemFlag", "BillPayOpt", + "BillItems" }) public class BillTrxInf { private String BillId; diff --git a/omods/core/api/src/main/java/org/openmrs/module/icare/billing/services/payment/gepg/GEPGService.java b/omods/core/api/src/main/java/org/openmrs/module/icare/billing/services/payment/gepg/GEPGService.java index 196b0f3b6..6a6c7e77d 100644 --- a/omods/core/api/src/main/java/org/openmrs/module/icare/billing/services/payment/gepg/GEPGService.java +++ b/omods/core/api/src/main/java/org/openmrs/module/icare/billing/services/payment/gepg/GEPGService.java @@ -25,7 +25,7 @@ public class GEPGService { private PaymentDAO paymentDAO; @Autowired - private BillingService billingService; + private BillingService billingService; private final Map> callbackResponses = new ConcurrentHashMap<>(); private final ObjectMapper objectMapper = new ObjectMapper(); @@ -46,7 +46,7 @@ public Map submitGepgRequest(String jsonPayload, String signatur // Write JSON payload try (OutputStream os = con.getOutputStream(); - BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os, "UTF-8"))) { + BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os, "UTF-8"))) { writer.write(jsonPayload); writer.flush(); } @@ -81,7 +81,9 @@ public Map submitGepgRequest(String jsonPayload, String signatur // Handle different ackCodes if ("R3001".equals(ackCode)) { - String controlNumber = billingService.fetchControlNumber(requestId); + Integer requestpaymentId = null; + requestpaymentId = Integer.parseInt(requestId); + String controlNumber = billingService.fetchControlNumber(requestpaymentId); // Save the payload in a global property AdministrationService administrationService = Context.getAdministrationService(); GlobalProperty globalProperty = new GlobalProperty(); @@ -89,7 +91,8 @@ public Map submitGepgRequest(String jsonPayload, String signatur globalProperty.setPropertyValue(controlNumber); administrationService.saveGlobalProperty(globalProperty); responseMap.put("status", "success"); - responseMap.put("controlNumber", controlNumber != null ? controlNumber : "Not found within timeout"); + responseMap.put("controlNumber", + controlNumber != null ? controlNumber : "Not found within timeout"); responseMap.put("ackCode", ackCode); responseMap.put("message", "Request processed successfully."); } else if ("CONS9005".equals(ackCode)) { diff --git a/omods/core/omod/src/main/java/org/openmrs/module/icare/web/controller/GepgBillingController.java b/omods/core/omod/src/main/java/org/openmrs/module/icare/web/controller/GepgBillingController.java index 0a9684cfe..883b2803d 100644 --- a/omods/core/omod/src/main/java/org/openmrs/module/icare/web/controller/GepgBillingController.java +++ b/omods/core/omod/src/main/java/org/openmrs/module/icare/web/controller/GepgBillingController.java @@ -233,8 +233,13 @@ public ResponseEntity handleCallback(HttpServletRequest request) { private ResponseEntity> generateErrorResponse(String errorMessage, String requestId) { Map errorResponse = new HashMap<>(); try { - // AckData as per your requested format + AdministrationService administrationService = Context.getAdministrationService(); + // Retrieve GePG user credentials + String gepgUsername = administrationService.getGlobalProperty(ICareConfig.GEPG_USERNAME); + String gepgPassword = administrationService.getGlobalProperty(ICareConfig.GEPG_PASSWORD); + Context.authenticate(gepgUsername, gepgPassword); + // AckData as per your requested format Map ackData = new HashMap<>(); ackData.put("Description", errorMessage); ackData.put("RequestId", requestId); diff --git a/ui/src/app/shared/components/patients-tabular-list/patients-tabular-list.component.ts b/ui/src/app/shared/components/patients-tabular-list/patients-tabular-list.component.ts index af15fad46..e0f7a1468 100644 --- a/ui/src/app/shared/components/patients-tabular-list/patients-tabular-list.component.ts +++ b/ui/src/app/shared/components/patients-tabular-list/patients-tabular-list.component.ts @@ -37,7 +37,7 @@ export class PatientsTabularListComponent implements OnInit, OnChanges { constructor( private visitService: VisitsService,) {} ngOnInit(): void { - console.log("payment type passed .....",this.paymentTypeSelected) + // console.log("payment type passed .....",this.paymentTypeSelected) this.dataSource = new MatTableDataSource( sanitizePatientsVisitsForTabularPatientListing( this.visits, diff --git a/ui/src/app/shared/resources/visits/services/visits.service.ts b/ui/src/app/shared/resources/visits/services/visits.service.ts index ba7443313..f6e542d66 100755 --- a/ui/src/app/shared/resources/visits/services/visits.service.ts +++ b/ui/src/app/shared/resources/visits/services/visits.service.ts @@ -356,8 +356,7 @@ export class VisitsService { parametersString += `&includeInactive=true`; } // - - console.log("url fired ...",`icare/visit?${parametersString.replace("&","" )}&startIndex=${startIndex}&limit=${limit}`); + // console.log("url fired ...",`icare/visit?${parametersString.replace("&","" )}&startIndex=${startIndex}&limit=${limit}`); return ( locationUuids?.length > 0 ? zip( diff --git a/ui/src/app/shared/store-pages/issuing-page/issuing-page.component.html b/ui/src/app/shared/store-pages/issuing-page/issuing-page.component.html index 7cfcf7405..29ba6f168 100644 --- a/ui/src/app/shared/store-pages/issuing-page/issuing-page.component.html +++ b/ui/src/app/shared/store-pages/issuing-page/issuing-page.component.html @@ -10,7 +10,7 @@ mode="indeterminate" > - + - + - {{ store?.display }} + {{ store?.display }}