jnsereko
(Joshua Nsereko)
July 19, 2022, 2:19am
1
Hey all!
I have created a module trying out some customised get api like below
@RequestMapping("/patient")
@ResponseBody
public ResponseEntity< List<Patient> > search(@RequestParam(value = "mobile", required = false) String mobile) throws ResponseException {
List<Patient> results = null;
if (StringUtils.isNotBlank(mobile)) {
if(!StringUtils.isNumericSpace(mobile)) {
return new ResponseEntity<>(new ArrayList<>(), HttpStatus.NO_CONTENT);
}else if( validateNumber(mobile)) {
results = Context.getPatientService().getAllPatients()
.stream()
.filter(person -> sameMobile(person.getAttributes(), mobile))
.collect(Collectors.toList());
/**
List<Patient> allPatients = Context.getPatientService().getAllPatients();
for(Patient patiient: allPatients){
if(sameMobile(patiient.getPerson().getAttributes(), mobile)) {
results.add(patiient);
}
}
**/
}
Boolean resultsExist = results != null && !results.isEmpty();
if (!resultsExist) {
return new ResponseEntity<>(new ArrayList<>(), HttpStatus.NO_CONTENT);
}
return new ResponseEntity<>(results, HttpStatus.OK);
}
return new ResponseEntity<>(new ArrayList<>(), HttpStatus.NO_CONTENT);
}
on executing my api with postman /mymodule/patient?mobile=0708443737
, i get an Infinite recursion (StackOverflowError) but if i add this functionality as a search handler in openmrs-module-webservices.rest , it works pretty well.
I am running openmrs instance using the sdk, Reference Application 2.12.2 .
@ibacher @dkayiwa what might i be missing here
dkayiwa
(Daniel Kayiwa)
July 19, 2022, 9:25am
2
The link you shared for your error log does not seem to work.
jnsereko
(Joshua Nsereko)
July 19, 2022, 10:26am
3
@dkayiwa , i dont know what my earlier link was invalidated, am sorry for that. i have created another on https://pastebin.com/f4zEumaj
jnsereko
(Joshua Nsereko)
July 19, 2022, 10:31am
4
ohhhh
its broken
i guess i have exceeded the characters limit
jnsereko
(Joshua Nsereko)
July 19, 2022, 10:52am
5
@dkayiwa pastebin is invalidating my log each time i create a new paste so am going to upload it here
log.txt (418.4 KB)
dkayiwa
(Daniel Kayiwa)
July 19, 2022, 11:50am
6
Are you trying to duplicate the already existing patient
end point?
jnsereko
(Joshua Nsereko)
July 19, 2022, 12:15pm
7
I first created the class in openmrs-module-web services.rest until it worked. I migrated the logic in my new module and deleted the handler I had created
dkayiwa
(Daniel Kayiwa)
July 19, 2022, 1:05pm
8
But the patient
end point is already implemented. So my point is, why migrate it to your custom module?
jnsereko
(Joshua Nsereko)
July 19, 2022, 1:23pm
9
i wanted to introduce in another simple functionality of searching by mobile and i thought of keeping the name would give a better hint of the results of the endpoint.
dkayiwa
(Daniel Kayiwa)
July 19, 2022, 1:35pm
10
jnsereko
(Joshua Nsereko)
July 19, 2022, 1:49pm
11
Yes
I am using openmrs web services rest version 2.36.0
dkayiwa
(Daniel Kayiwa)
July 19, 2022, 2:09pm
12
1 Like
jnsereko
(Joshua Nsereko)
July 19, 2022, 2:20pm
13
i didn’t create any resource, for now. So my Module only has one controller Task1RestController.java · GitHub and 2 classes responsible for the module’s activation
dkayiwa
(Daniel Kayiwa)
July 19, 2022, 4:44pm
14
You need a resource to handle your end point’s domain object.
1 Like
jnsereko
(Joshua Nsereko)
July 20, 2022, 1:26pm
15
hey @dkayiwa creating a corresponding handler resource didn’t work for me, unless there are more tweaks to do with the resource.
dkayiwa
(Daniel Kayiwa)
July 20, 2022, 1:36pm
16
Which OpenMRS platform versions does your resource support?
jnsereko
(Joshua Nsereko)
July 20, 2022, 1:55pm
17
i am using openmrs version 2.5.0 in my module. I am running my module against Reference application 2.12 which runs core version 2.4.3
dkayiwa
(Daniel Kayiwa)
July 20, 2022, 2:02pm
18
Take a second look at your resource, and you will understand what am asking for.
jnsereko
(Joshua Nsereko)
July 20, 2022, 3:06pm
19
@dkayiwa i have changed
supportedOpenmrsVersions = { "1.8.*" }
to supportedOpenmrsVersions = { "1.*", "2.*" }
but the error has persisted
dkayiwa
(Daniel Kayiwa)
July 20, 2022, 4:30pm
20
Commit your entire module on github. And also share the exact full url that you are accessing for this end point, to get the error.