From 02b2602c1f141a968f70520849bb99d0ca6f4b0e Mon Sep 17 00:00:00 2001 From: Josephat Mwakyusa Date: Mon, 5 Aug 2024 23:37:06 +0300 Subject: [PATCH] Add support to get price by conceptuuid --- .../openmrs/module/icare/core/ICareService.java | 2 +- .../icare/web/controller/ICareController.java | 15 ++++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/omods/core/api/src/main/java/org/openmrs/module/icare/core/ICareService.java b/omods/core/api/src/main/java/org/openmrs/module/icare/core/ICareService.java index 19a362649..70093fb1d 100644 --- a/omods/core/api/src/main/java/org/openmrs/module/icare/core/ICareService.java +++ b/omods/core/api/src/main/java/org/openmrs/module/icare/core/ICareService.java @@ -70,7 +70,7 @@ public interface ICareService extends OpenmrsService { ItemPrice getItemPriceByConceptId(Integer serviceConceptId, Integer paymentSchemeConceptId, Integer paymentTypeConceptId); - ItemPrice getItemPrice(Visit visit, Concept concept) throws Exception; + ItemPrice getItemPrice(Visit visit, Concept concept) throws ItemNotPayableException, ConfigurationException; ItemPrice getItemPrice(Visit visit, Drug drug) throws ItemNotPayableException, ConfigurationException; diff --git a/omods/core/omod/src/main/java/org/openmrs/module/icare/web/controller/ICareController.java b/omods/core/omod/src/main/java/org/openmrs/module/icare/web/controller/ICareController.java index a1d0c57ba..e648e1665 100644 --- a/omods/core/omod/src/main/java/org/openmrs/module/icare/web/controller/ICareController.java +++ b/omods/core/omod/src/main/java/org/openmrs/module/icare/web/controller/ICareController.java @@ -238,12 +238,10 @@ public Item onPostItem(Item item) { @RequestMapping(value = "itemprice", method = RequestMethod.GET) @ResponseBody - public Map onGet(@RequestParam(defaultValue = "100") Integer limit, @RequestParam(defaultValue = "0") Integer startIndex, @RequestParam(required = false) String paymentType, @RequestParam(required = false) String visitUuid, @RequestParam(required = false) String drugUuid ) throws ConfigurationException { + public Map onGet(@RequestParam(defaultValue = "100") Integer limit, @RequestParam(defaultValue = "0") Integer startIndex, @RequestParam(required = false) String paymentType, @RequestParam(required = false) String visitUuid, @RequestParam(required = false) String drugUuid , @RequestParam(required = false) String conceptUuid ) throws ConfigurationException { Map results = new HashMap<>(); - if (visitUuid == null && drugUuid ==null) { + if (visitUuid == null && drugUuid ==null && conceptUuid == null) { List> items = new ArrayList>(); - - for (ItemPrice item : iCareService.getItemPrices(paymentType, limit, startIndex)) { items.add(item.toMap()); } @@ -251,14 +249,17 @@ public Map onGet(@RequestParam(defaultValue = "100") Integer lim } if (visitUuid != null && drugUuid !=null){ - Visit visit = Context.getService(VisitService.class).getVisitByUuid(visitUuid); Drug drug = Context.getService(ConceptService.class).getDrugByUuid(drugUuid); - ItemPrice item = iCareService.getItemPrice(visit,drug); - results.put("results",item.toMap()); + } + if (visitUuid != null && conceptUuid !=null){ + Visit visit = Context.getService(VisitService.class).getVisitByUuid(visitUuid); + Concept concept = Context.getService(ConceptService.class).getConceptByUuid(conceptUuid); + ItemPrice item = iCareService.getItemPrice(visit, concept); + results.put("results",item.toMap()); } return results;