Skip to content

Commit

Permalink
Extend BaseRestController
Browse files Browse the repository at this point in the history
  • Loading branch information
jayasanka-sack committed Dec 16, 2024
1 parent 494e9b9 commit e8c79b1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import lombok.Setter;
import org.openmrs.Diagnosis;
import org.openmrs.Patient;
import org.openmrs.module.emrapi.visit.VisitWithDiagnoses;
import org.openmrs.module.emrapi.visit.EmrApiVisitService;
import org.openmrs.module.webservices.rest.SimpleObject;
Expand All @@ -10,12 +11,14 @@
import org.openmrs.module.webservices.rest.web.RestUtil;
import org.openmrs.module.webservices.rest.web.representation.Representation;
import org.openmrs.module.webservices.rest.web.resource.impl.NeedsPaging;
import org.openmrs.module.webservices.rest.web.v1_0.controller.BaseRestController;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
Expand All @@ -24,15 +27,17 @@

@Setter
@Controller
public class VisitController {
public class VisitController extends BaseRestController {

EmrApiVisitService emrApiVisitService;

@RequestMapping(method = RequestMethod.GET, value = "/rest/**/emrapi/patient/{patientUuid}/visitWithNotesAndDiagnoses")
public ResponseEntity<?> getVisitsWithDiagnosesByPatient(
HttpServletRequest request,
HttpServletResponse response,
@PathVariable("patientUuid") String patientUuid) {
@PathVariable("patientUuid") String patientUuid,
@RequestParam("patient") Patient patient) {

RequestContext context = RestUtil.getRequestContext(request, response, Representation.DEFAULT);
List<VisitWithDiagnoses> visitsEntries;
visitsEntries = emrApiVisitService.getVisitsWithNotesAndDiagnosesByPatient(patientUuid, context.getStartIndex(), context.getLimit());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void shouldGetVisitsWithNotesAndDiagnosesByPatient() throws Exception {
String secondVisitUuid = "1c72e1ac-9b18-11e0-93c3-18a905e044dc";
String thirdVisitUuid = "3c72f2bc-9b18-11e0-93c3-18a905e044ec";

MvcResult response = mockMvc.perform(get("/rest/v1/emrapi/patient/" + patientUuid + "/visitWithNotesAndDiagnoses")
MvcResult response = mockMvc.perform(get("/rest/v1/emrapi/patient/" + patientUuid + "/visitWithNotesAndDiagnoses?patient="+patientUuid)
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andReturn();
Expand Down

0 comments on commit e8c79b1

Please sign in to comment.