Skip to content

Commit

Permalink
Merge pull request #490 from udsm-dhis2-lab/hotfix/gepgerrorhandling
Browse files Browse the repository at this point in the history
Hotfix/gepgerrorhandling and clinic medication on dose
  • Loading branch information
iamgaspardev authored Nov 28, 2024
2 parents dd5ac9c + 6d9213c commit 2bc1042
Show file tree
Hide file tree
Showing 15 changed files with 392 additions and 113 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

import javax.naming.ConfigurationException;

import java.io.IOException;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
Expand Down Expand Up @@ -807,7 +808,7 @@ public Map<String, Object> processGepgCallbackResponse(Map<String, Object> callb
response.put("SystemAuth", systemAuth);
response.put("AckData", ackData);

}else{
} else {
ackData.put("SystemAckCode", "0");
ackData.put("Description", "Fail, No Data with this RequestId");
ackData.put("RequestId", requestId);
Expand Down Expand Up @@ -876,7 +877,7 @@ public Map<String, Object> processGepgCallbackResponse(Map<String, Object> callb
int rowsUpdated = this.paymentDAO.setReferenceNumberByPaymentId(requestId_, payCntrNum);

if (rowsUpdated > 0) {

ackData.put("SystemAckCode", "0");
ackData.put("Description", "Successfully Updated");
} else {
Expand Down Expand Up @@ -1173,4 +1174,22 @@ public Map<String, Object> createGePGPayload(Patient patient, List<InvoiceItem>

return result;
}

@Override
public String signatureData(String rowData) throws Exception {
AdministrationService administrationService = Context.getAdministrationService();
String clientPrivateKey = administrationService.getGlobalProperty(ICareConfig.CLIENT_PRIVATE_KEY);
try {
GlobalProperty globalProperty = new GlobalProperty();
globalProperty.setProperty("gepg.callbackrowData.icareConnect");
globalProperty.setPropertyValue(rowData);
administrationService.saveGlobalProperty(globalProperty);
String signature = SignatureUtils.signData(rowData, clientPrivateKey);
return signature;
}
catch (IOException e) {
throw new Exception("Error signing data due to I/O: " + e.getMessage(), e);
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
package org.openmrs.module.icare.billing.models;

public class CallbackData {

private SystemAuth systemAuth;

private FeedbackData feedbackData;

private Status status;

// Getters and setters
public SystemAuth getSystemAuth() {
return systemAuth;
}

public void setSystemAuth(SystemAuth systemAuth) {
this.systemAuth = systemAuth;
}

public FeedbackData getFeedbackData() {
return feedbackData;
}

public void setFeedbackData(FeedbackData feedbackData) {
this.feedbackData = feedbackData;
}

public Status getStatus() {
return status;
}

public void setStatus(Status status) {
this.status = status;
}

// Nested classes for the structure
public static class SystemAuth {

private String serviceCode;

private String signature;

// Getters and setters
public String getServiceCode() {
return serviceCode;
}

public void setServiceCode(String serviceCode) {
this.serviceCode = serviceCode;
}

public String getSignature() {
return signature;
}

public void setSignature(String signature) {
this.signature = signature;
}
}

public static class FeedbackData {

private GepgBillSubResp gepgBillSubResp;

// Getter and setter
public GepgBillSubResp getGepgBillSubResp() {
return gepgBillSubResp;
}

public void setGepgBillSubResp(GepgBillSubResp gepgBillSubResp) {
this.gepgBillSubResp = gepgBillSubResp;
}

public static class GepgBillSubResp {

private BillTrxInf billTrxInf;

// Getter and setter
public BillTrxInf getBillTrxInf() {
return billTrxInf;
}

public void setBillTrxInf(BillTrxInf billTrxInf) {
this.billTrxInf = billTrxInf;
}

public static class BillTrxInf {

private String billId;

private String payCntrNum;

private String trxSts;

private String trxStsCode;

// Getters and setters
public String getBillId() {
return billId;
}

public void setBillId(String billId) {
this.billId = billId;
}

public String getPayCntrNum() {
return payCntrNum;
}

public void setPayCntrNum(String payCntrNum) {
this.payCntrNum = payCntrNum;
}

public String getTrxSts() {
return trxSts;
}

public void setTrxSts(String trxSts) {
this.trxSts = trxSts;
}

public String getTrxStsCode() {
return trxStsCode;
}

public void setTrxStsCode(String trxStsCode) {
this.trxStsCode = trxStsCode;
}
}
}
}

public static class Status {

private String requestId;

private String code;

private String description;

// Getters and setters
public String getRequestId() {
return requestId;
}

public void setRequestId(String requestId) {
this.requestId = requestId;
}

public String getCode() {
return code;
}

public void setCode(String code) {
this.code = code;
}

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.openmrs.module.icare.billing.models;

import java.util.Map;

import org.hibernate.validator.constraints.NotEmpty;

public class RequestDto {

@NotEmpty(message = "Callback data cannot be null or empty.")
private Map<String, Object> callbackData;

private String fallback;

// Getters and Setters
public Map<String, Object> getCallbackData() {
return callbackData;
}

public void setCallbackData(Map<String, Object> callbackData) {
this.callbackData = callbackData;
}

public String getFallback() {
return fallback;
}

public void setFallback(String fallback) {
this.fallback = fallback;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,6 @@ Map<String, Object> createGePGPayload(Patient patient, List<InvoiceItem> invoice
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;

String signatureData(String rowData) throws Exception;
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.net.URL;
import org.openmrs.api.AdministrationService;
import org.openmrs.api.context.Context;
import org.openmrs.module.icare.ICareConfig;
import org.openmrs.module.icare.billing.models.Invoice;
import org.openmrs.module.icare.billing.models.InvoiceItem;
import org.openmrs.module.icare.billing.services.BillingService;
Expand Down Expand Up @@ -236,4 +237,31 @@ public Map<String, Object> createGePGPayload(Patient patient, List<InvoiceItem>

return result;
}

public Map<String, Object> generateErrorResponse(String errorMessage) throws Exception {
Map<String, Object> errorResponse = new HashMap<>();
AdministrationService administrationService = Context.getAdministrationService();
String clientPrivateKey = administrationService.getGlobalProperty(ICareConfig.CLIENT_PRIVATE_KEY);

// AckData as per your requested format
Map<String, Object> ackData = new HashMap<>();
ackData.put("Description", errorMessage);
ackData.put("RequestId", null);
ackData.put("SystemAckCode", "0");

// Serialize RequestData to JSON for signing
String requestDataJson = new ObjectMapper().writeValueAsString(ackData);
String signature = SignatureUtils.signData(requestDataJson, clientPrivateKey);

// SystemAuth as per your requested format
Map<String, Object> systemAuth = new HashMap<>();
systemAuth.put("SystemCode", "1001");
systemAuth.put("Signature", signature);

errorResponse.put("AckData", ackData);
errorResponse.put("SystemAuth", systemAuth);

return errorResponse;

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -144,30 +144,6 @@ private Map<String, Object> parseJsonResponse(String responseString) {
return resultMap;
}

// private String fetchControlNumber(String requestId) {
// String controlNumber = null;
// long startTime = System.currentTimeMillis();
// long timeout = 32000;

// while (System.currentTimeMillis() - startTime < timeout) {
// controlNumber = paymentDAO.getReferenceNumberByRequestId(requestId);
// AdministrationService administrationService = Context.getAdministrationService();
// GlobalProperty globalProperty = new GlobalProperty();
// globalProperty.setProperty("gepg.controlNumberRes.icareConnect");
// globalProperty.setPropertyValue(controlNumber);
// administrationService.saveGlobalProperty(globalProperty);
// if (controlNumber != null) {
// break;
// }
// try {
// Thread.sleep(4000);
// } catch (InterruptedException e) {
// Thread.currentThread().interrupt();
// }
// }
// return controlNumber;
// }

private void handleErrorResponse(HttpURLConnection con, Map<String, Object> responseMap) throws IOException {
try (BufferedReader errorReader = new BufferedReader(new InputStreamReader(con.getErrorStream()))) {
StringBuilder errorContent = new StringBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,6 @@ public List<Visit> getVisitsByOrderType(String search, String orderTypeUuid, Str
if (attributeValueReference != null) {
queryStr += " AND v IN ( SELECT va.visit FROM VisitAttribute va WHERE va.valueReference=:attributeValueReference)";
}

if (paymentStatus != null) {
if (paymentStatus == VisitWrapper.PaymentStatus.PAID) {
queryStr += " AND v IN (SELECT invoice.visit FROM Invoice invoice WHERE "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,8 @@ public ItemPrice saveItemPrice(ItemPrice itemPrice) throws APIException {
itemPrice.setPaymentType(paymentType);
if (itemPrice.getPayable() != null && itemPrice.getPayablePaymentMode() == null) {
throw new APIException("Payment mode for payable not provided");
} else if (itemPrice.getPayablePaymentMode() != null
&& itemPrice.getPayablePaymentMode().getUuid() != null
&& conceptService.getConceptByUuid(itemPrice.getPayablePaymentMode().getUuid()) != null) {
} else if (itemPrice.getPayablePaymentMode() != null && itemPrice.getPayablePaymentMode().getUuid() != null
&& conceptService.getConceptByUuid(itemPrice.getPayablePaymentMode().getUuid()) != null) {
Concept payablePaymentMode = conceptService.getConceptByUuid(itemPrice.getPayablePaymentMode().getUuid());
itemPrice.setPayablePaymentMode(payablePaymentMode);
}
Expand Down
Loading

0 comments on commit 2bc1042

Please sign in to comment.