From 7bb59ece6091069d55c24b95cd4531d7f6befb89 Mon Sep 17 00:00:00 2001 From: gaspar-dev Date: Wed, 27 Nov 2024 18:43:18 +0300 Subject: [PATCH 1/3] added empty error handling on gepg --- .../icare/billing/BillingServiceImpl.java | 23 ++- .../icare/billing/models/CallbackData.java | 166 +++++++++++++++ .../icare/billing/models/RequestDto.java | 30 +++ .../billing/services/BillingService.java | 2 + .../payment/gepg/BillSubmissionRequest.java | 28 +++ .../services/payment/gepg/GEPGService.java | 24 --- .../module/icare/core/dao/ICareDao.java | 1 - .../web/controller/GepgBillingController.java | 193 +++++++++++------- 8 files changed, 365 insertions(+), 102 deletions(-) create mode 100644 omods/core/api/src/main/java/org/openmrs/module/icare/billing/models/CallbackData.java create mode 100644 omods/core/api/src/main/java/org/openmrs/module/icare/billing/models/RequestDto.java 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 d78251cfd..2c8f6416d 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 @@ -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; @@ -807,7 +808,7 @@ public Map processGepgCallbackResponse(Map 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); @@ -876,7 +877,7 @@ public Map processGepgCallbackResponse(Map callb int rowsUpdated = this.paymentDAO.setReferenceNumberByPaymentId(requestId_, payCntrNum); if (rowsUpdated > 0) { - + ackData.put("SystemAckCode", "0"); ackData.put("Description", "Successfully Updated"); } else { @@ -1173,4 +1174,22 @@ public Map createGePGPayload(Patient patient, List 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); + } + + } } diff --git a/omods/core/api/src/main/java/org/openmrs/module/icare/billing/models/CallbackData.java b/omods/core/api/src/main/java/org/openmrs/module/icare/billing/models/CallbackData.java new file mode 100644 index 000000000..c5d7b3443 --- /dev/null +++ b/omods/core/api/src/main/java/org/openmrs/module/icare/billing/models/CallbackData.java @@ -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; + } + } +} diff --git a/omods/core/api/src/main/java/org/openmrs/module/icare/billing/models/RequestDto.java b/omods/core/api/src/main/java/org/openmrs/module/icare/billing/models/RequestDto.java new file mode 100644 index 000000000..8b48cc123 --- /dev/null +++ b/omods/core/api/src/main/java/org/openmrs/module/icare/billing/models/RequestDto.java @@ -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 callbackData; + + private String fallback; + + // Getters and Setters + public Map getCallbackData() { + return callbackData; + } + + public void setCallbackData(Map callbackData) { + this.callbackData = callbackData; + } + + public String getFallback() { + return fallback; + } + + public void setFallback(String fallback) { + this.fallback = fallback; + } +} 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 32bf7219b..b2aae4d51 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 @@ -95,4 +95,6 @@ Map createGePGPayload(Patient patient, List 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; } diff --git a/omods/core/api/src/main/java/org/openmrs/module/icare/billing/services/payment/gepg/BillSubmissionRequest.java b/omods/core/api/src/main/java/org/openmrs/module/icare/billing/services/payment/gepg/BillSubmissionRequest.java index 83cf3aeeb..f4723c138 100644 --- a/omods/core/api/src/main/java/org/openmrs/module/icare/billing/services/payment/gepg/BillSubmissionRequest.java +++ b/omods/core/api/src/main/java/org/openmrs/module/icare/billing/services/payment/gepg/BillSubmissionRequest.java @@ -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; @@ -236,4 +237,31 @@ public Map createGePGPayload(Patient patient, List return result; } + + public Map generateErrorResponse(String errorMessage) throws Exception { + Map errorResponse = new HashMap<>(); + AdministrationService administrationService = Context.getAdministrationService(); + String clientPrivateKey = administrationService.getGlobalProperty(ICareConfig.CLIENT_PRIVATE_KEY); + + // AckData as per your requested format + Map 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 systemAuth = new HashMap<>(); + systemAuth.put("SystemCode", "1001"); + systemAuth.put("Signature", signature); + + errorResponse.put("AckData", ackData); + errorResponse.put("SystemAuth", systemAuth); + + return errorResponse; + + } } 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 a07009b2b..196b0f3b6 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 @@ -144,30 +144,6 @@ private Map 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 responseMap) throws IOException { try (BufferedReader errorReader = new BufferedReader(new InputStreamReader(con.getErrorStream()))) { StringBuilder errorContent = new StringBuilder(); diff --git a/omods/core/api/src/main/java/org/openmrs/module/icare/core/dao/ICareDao.java b/omods/core/api/src/main/java/org/openmrs/module/icare/core/dao/ICareDao.java index 8ca613b75..059a336b4 100644 --- a/omods/core/api/src/main/java/org/openmrs/module/icare/core/dao/ICareDao.java +++ b/omods/core/api/src/main/java/org/openmrs/module/icare/core/dao/ICareDao.java @@ -563,7 +563,6 @@ public List 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 " 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 ac4b3361d..32f6017a4 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 @@ -1,29 +1,43 @@ package org.openmrs.module.icare.web.controller; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +import javax.servlet.http.HttpServletRequest; + import org.openmrs.GlobalProperty; -import org.openmrs.Patient; import org.openmrs.Visit; import org.openmrs.api.AdministrationService; -import com.fasterxml.jackson.databind.ObjectMapper; import org.openmrs.api.context.Context; import org.openmrs.api.context.ContextAuthenticationException; 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.models.Payment; +import org.openmrs.module.icare.billing.models.RequestDto; import org.openmrs.module.icare.billing.services.BillingService; import org.openmrs.module.icare.billing.services.payment.gepg.BillSubmissionRequest; import org.openmrs.module.icare.billing.services.payment.gepg.GEPGService; import org.openmrs.module.icare.billing.services.payment.gepg.SignatureUtils; +import org.openmrs.module.webservices.rest.web.RestConstants; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.*; -import com.fasterxml.jackson.core.JsonProcessingException; -import org.openmrs.module.webservices.rest.web.RestConstants; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; +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.RestController; -import java.util.*; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; @RestController @RequestMapping(value = "/rest/" + RestConstants.VERSION_1 + "/gepg") @@ -44,7 +58,7 @@ public Map generateControlNumber(@RequestBody List invoiceItems = new ArrayList<>(); for (Map invoiceReference : requestPayload) { @@ -58,7 +72,7 @@ public Map generateControlNumber(@RequestBody List generateControlNumber(@RequestBody List generateControlNumber(@RequestBody List generateControlNumber(@RequestBody List> handleCallback( - @RequestBody(required = false) Map callbackData, - @RequestParam(required = false) String fallback) throws Exception { - AdministrationService administrationService = Context.getAdministrationService(); - - if (callbackData == null || callbackData.isEmpty()) { - Map response = new HashMap<>(); - - String serviceCode = administrationService.getGlobalProperty(ICareConfig.SERVICE_CODE); - String clientPrivateKey = administrationService.getGlobalProperty(ICareConfig.CLIENT_PRIVATE_KEY); - - // Initialize response parts + public ResponseEntity handleCallback(HttpServletRequest request) { + try { + // Read the raw body from the request + AdministrationService administrationService = Context.getAdministrationService(); + String requestBody = new BufferedReader(new InputStreamReader(request.getInputStream())).lines().collect( + Collectors.joining("\n")); + + // Parse the body as JSON into a Map + ObjectMapper objectMapper = new ObjectMapper(); + Map requestDto = objectMapper.readValue(requestBody, Map.class); + + // Validate and process the data + // if (requestDto == null || !requestDto.containsKey("callbackData")) { + // return generateErrorResponse("Invalid or missing callback data."); + // } + + Map callbackData = (Map) requestDto; + + if (callbackData == null || callbackData.isEmpty()) { + return generateErrorResponse("Empty content not allowed", ""); + } + + // Retrieve GePG user credentials + String gepgUsername = administrationService.getGlobalProperty(ICareConfig.GEPG_USERNAME); + String gepgPassword = administrationService.getGlobalProperty(ICareConfig.GEPG_PASSWORD); + Map status = (Map) callbackData.get("Status"); + if (status == null) { + return generateErrorResponse("Status is missing in callback data.", ""); + } + String requestId = (String) status.get("RequestId"); + + Map systemAuth = (Map) callbackData.get("SystemAuth"); + if (systemAuth == null || !systemAuth.containsKey("Signature")) { + return generateErrorResponse("Missing or invalid signature in callback data.", requestId); + } + String signature = (String) systemAuth.get("Signature"); + + Map feedbackData = (Map) callbackData.get("FeedbackData"); + if (feedbackData == null) { + return generateErrorResponse("FeedbackData is missing in callback data.", requestId); + } + + try { + Context.authenticate(gepgUsername, gepgPassword); + + Map processResponse = billingService.processGepgCallbackResponse(callbackData); + return ResponseEntity.ok(processResponse); + + } + catch (ContextAuthenticationException e) { + return generateErrorResponse("Authentication failed please contact an Admin", requestId); + } + finally { + Context.logout(); + } + + } + catch (IOException e) { + return generateErrorResponse("Error reading request body for this request", ""); + } + catch (Exception ex) { + return generateErrorResponse("Error processing callback body for this request", ""); + } + } + + private ResponseEntity> generateErrorResponse(String errorMessage, String requestId) { + Map errorResponse = new HashMap<>(); + try { + // AckData as per your requested format Map ackData = new HashMap<>(); - ackData.put("Description", "Empty content not allowed"); - ackData.put("RequestId", null); + ackData.put("Description", errorMessage); + ackData.put("RequestId", requestId); ackData.put("SystemAckCode", "0"); - + + // Serialize RequestData to JSON for signing + String requestDataJson = new ObjectMapper().writeValueAsString(ackData); + String signature = billingService.signatureData(requestDataJson); + + // SystemAuth as per your requested format Map systemAuth = new HashMap<>(); - systemAuth.put("SystemCode", serviceCode); - systemAuth.put("Signature", ""); - - // Build final response - response.put("AckData", ackData); - response.put("SystemAuth", systemAuth); - - // Return response with 200 OK - return ResponseEntity.ok(response); + systemAuth.put("SystemCode", "1001"); + systemAuth.put("Signature",signature); + + errorResponse.put("AckData", ackData); + errorResponse.put("SystemAuth", systemAuth); + + return ResponseEntity.badRequest().body(errorResponse); + + } catch (Exception e) { + // Handle the error without using Map.of() + Map errorMap = new HashMap<>(); + errorMap.put("error", "Failed to sign data: " + e.getMessage()); + + return ResponseEntity.badRequest().body(errorMap); } - - // GePG user credentials - String gepgUsername = administrationService.getGlobalProperty(ICareConfig.GEPG_USERNAME); - String gepgPassword = administrationService.getGlobalProperty(ICareConfig.GEPG_PASSWORD); - - String signature = (String) ((Map) callbackData.get("SystemAuth")).get("Signature"); - - Map feedbackData = (Map) callbackData.get("FeedbackData"); - - String payload = new ObjectMapper().writeValueAsString(feedbackData); - - String enginePublicKey = administrationService.getGlobalProperty(ICareConfig.ENGINE_PUBLIC_KEY); - - try { - - Context.authenticate(gepgUsername, gepgPassword); - //TODOO - //Agreed to proceed with verification after UUCC insuring lenght of signature - // boolean isVerified = SignatureUtils.verifyData(payload, signature, enginePublicKey); - - // if (!isVerified) { - // Map errorResponse = new HashMap<>(); - // errorResponse.put("status", "error"); - // errorResponse.put("message", "Signature verification failed"); - // return errorResponse; - // } - return ResponseEntity.ok(billingService.processGepgCallbackResponse(callbackData)) ; - - } catch (ContextAuthenticationException e) { - Map errorResponse = new HashMap<>(); - - errorResponse.put("status", "error"); - errorResponse.put("message", "Authentication failed: " + e.getMessage()); - return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(errorResponse) ; - } finally { - Context.logout(); - } - } + } } From 4aeb25dbb5921cc36d4ff6b9fcd6012cc9235006 Mon Sep 17 00:00:00 2001 From: gaspar-dev Date: Wed, 27 Nov 2024 18:55:32 +0300 Subject: [PATCH 2/3] added empty error handling on gepg and merges --- .../dispensing-patient-list.component.html | 8 ++------ .../components/patient-list/patient-list.component.ts | 5 ++++- .../patients-tabular-list.component.ts | 1 + .../shared/resources/visits/services/visits.service.ts | 2 ++ 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/ui/src/app/modules/dispensing/pages/dispensing-patient-list/dispensing-patient-list.component.html b/ui/src/app/modules/dispensing/pages/dispensing-patient-list/dispensing-patient-list.component.html index 27f3f379a..1411a08fa 100644 --- a/ui/src/app/modules/dispensing/pages/dispensing-patient-list/dispensing-patient-list.component.html +++ b/ui/src/app/modules/dispensing/pages/dispensing-patient-list/dispensing-patient-list.component.html @@ -27,10 +27,7 @@ [itemsPerPage]="10" [orderType]=" params?.useGenericPrescription && - params?.useGenericPrescription === 'true' - ? params?.generalPrescriptionOrderType - : 'iCARESTS-PRES-1111-1111-525400e4297f' - " + params?.useGenericPrescription === 'true'? params?.generalPrescriptionOrderType : 'iCARESTS-PRES-1111-1111-525400e4297f'" [orderStatusCode]="'EMPTY'" (selectPatient)="onSelectPatient($event)" > @@ -52,8 +49,7 @@ diff --git a/ui/src/app/shared/components/patient-list/patient-list.component.ts b/ui/src/app/shared/components/patient-list/patient-list.component.ts index ad42228f6..c655d72ec 100644 --- a/ui/src/app/shared/components/patient-list/patient-list.component.ts +++ b/ui/src/app/shared/components/patient-list/patient-list.component.ts @@ -111,8 +111,8 @@ export class PatientListComponent implements OnInit, OnChanges { private getVisits(visits: Visit[]) { this.loadingPatients = true; + console.log("visit ----- ") // this.service = "LABS"; - this.visits$ = visits ? of(visits) : this.service && this.service === "LABS" @@ -148,6 +148,9 @@ export class PatientListComponent implements OnInit, OnChanges { } }) ); + this.visits$.subscribe((visit)=>{ + console.log("visit data .....",visit) + }); } 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 2e00a20f1..af15fad46 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,6 +37,7 @@ export class PatientsTabularListComponent implements OnInit, OnChanges { constructor( private visitService: VisitsService,) {} ngOnInit(): void { + 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 77b2771d8..ba7443313 100755 --- a/ui/src/app/shared/resources/visits/services/visits.service.ts +++ b/ui/src/app/shared/resources/visits/services/visits.service.ts @@ -356,6 +356,8 @@ export class VisitsService { parametersString += `&includeInactive=true`; } // + + console.log("url fired ...",`icare/visit?${parametersString.replace("&","" )}&startIndex=${startIndex}&limit=${limit}`); return ( locationUuids?.length > 0 ? zip( From 6d9213ce3aa1cfaff187fd82ce64db79cf2e5c29 Mon Sep 17 00:00:00 2001 From: gaspar-dev Date: Thu, 28 Nov 2024 16:24:53 +0300 Subject: [PATCH 3/3] Added support to ensure field type input is taken on dose and duration --- .../icare/core/impl/ICareServiceImpl.java | 5 ++--- .../web/controller/GepgBillingController.java | 21 ++++++++++++------- .../components/field/field.component.html | 8 ++++++- .../form/components/field/field.component.ts | 4 ++++ 4 files changed, 26 insertions(+), 12 deletions(-) diff --git a/omods/core/api/src/main/java/org/openmrs/module/icare/core/impl/ICareServiceImpl.java b/omods/core/api/src/main/java/org/openmrs/module/icare/core/impl/ICareServiceImpl.java index 7164397d9..56cd96613 100644 --- a/omods/core/api/src/main/java/org/openmrs/module/icare/core/impl/ICareServiceImpl.java +++ b/omods/core/api/src/main/java/org/openmrs/module/icare/core/impl/ICareServiceImpl.java @@ -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); } 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 32f6017a4..0a9684cfe 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 @@ -164,8 +164,14 @@ public Map generateControlNumber(@RequestBody List handleCallback(HttpServletRequest request) { try { - // Read the raw body from the request + 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); + // Read the raw body from the request + String requestBody = new BufferedReader(new InputStreamReader(request.getInputStream())).lines().collect( Collectors.joining("\n")); @@ -184,9 +190,6 @@ public ResponseEntity handleCallback(HttpServletRequest request) { return generateErrorResponse("Empty content not allowed", ""); } - // Retrieve GePG user credentials - String gepgUsername = administrationService.getGlobalProperty(ICareConfig.GEPG_USERNAME); - String gepgPassword = administrationService.getGlobalProperty(ICareConfig.GEPG_PASSWORD); Map status = (Map) callbackData.get("Status"); if (status == null) { return generateErrorResponse("Status is missing in callback data.", ""); @@ -206,10 +209,10 @@ public ResponseEntity handleCallback(HttpServletRequest request) { try { Context.authenticate(gepgUsername, gepgPassword); - + Map processResponse = billingService.processGepgCallbackResponse(callbackData); return ResponseEntity.ok(processResponse); - + } catch (ContextAuthenticationException e) { return generateErrorResponse("Authentication failed please contact an Admin", requestId); @@ -231,10 +234,12 @@ private ResponseEntity> generateErrorResponse(String errorMe Map errorResponse = new HashMap<>(); try { // AckData as per your requested format + AdministrationService administrationService = Context.getAdministrationService(); Map ackData = new HashMap<>(); ackData.put("Description", errorMessage); ackData.put("RequestId", requestId); ackData.put("SystemAckCode", "0"); + String systemCode = administrationService.getGlobalProperty(ICareConfig.GEPG_SYSTEM_CODE); // Serialize RequestData to JSON for signing String requestDataJson = new ObjectMapper().writeValueAsString(ackData); @@ -242,8 +247,8 @@ private ResponseEntity> generateErrorResponse(String errorMe // SystemAuth as per your requested format Map systemAuth = new HashMap<>(); - systemAuth.put("SystemCode", "1001"); - systemAuth.put("Signature",signature); + systemAuth.put("SystemCode", systemCode); + systemAuth.put("Signature", signature); errorResponse.put("AckData", ackData); errorResponse.put("SystemAuth", systemAuth); diff --git a/ui/src/app/shared/modules/form/components/field/field.component.html b/ui/src/app/shared/modules/form/components/field/field.component.html index 6802a9ba9..e15a4d261 100644 --- a/ui/src/app/shared/modules/form/components/field/field.component.html +++ b/ui/src/app/shared/modules/form/components/field/field.component.html @@ -63,7 +63,13 @@ [disabled]="shouldDisable || field?.disabled" [placeholder]="field?.placeholder" class="{{ fieldClass || 'field-input' }}" - [type]="field?.type === 'number' ? 'text' : field?.type" + [type]=" + (field?.label === 'Dose' || field?.label === 'Duration') + ? 'number' + : field?.type === 'number' + ? 'text' + : field?.type + " [required]="field?.required" matInput step="any" diff --git a/ui/src/app/shared/modules/form/components/field/field.component.ts b/ui/src/app/shared/modules/form/components/field/field.component.ts index 6cbc340b6..422b93181 100644 --- a/ui/src/app/shared/modules/form/components/field/field.component.ts +++ b/ui/src/app/shared/modules/form/components/field/field.component.ts @@ -51,6 +51,8 @@ export class FieldComponent implements AfterViewInit { @Output() fileFieldUpdate: EventEmitter = new EventEmitter(); ngAfterViewInit() { + + console.log("field?.key .....",this.field); if (typeof this.field?.value === "object") { this.value = this.field?.value && (this.field?.value as any)?.length > 0 @@ -175,7 +177,9 @@ export class FieldComponent implements AfterViewInit { } onListenKeyEvent(event: KeyboardEvent, fieldtype: any): void { + console.log("test in ----",fieldtype); if (fieldtype === "number") { + if ( event.key === "Backspace" || event.key === "ArrowLeft" ||