Dear @dkayiwa @tendomart,
Which REST api should i call to get all the location where parent pointer is null,please help me
Thanks in advance
Dear @dkayiwa @tendomart,
Which REST api should i call to get all the location where parent pointer is null,please help me
Thanks in advance
@rajuraghuwanshi is this https://wiki.openmrs.org/display/docs/REST+Web+Service+Resources+in+OpenMRS+1.9 what you need ?
No, How do i get all the location WHERE parent pointer is null,beacuse this REST api http://localhost:8080/openmrs/ws/rest/v1/location return all the location objects.
Thanks in Advance.
First read through the documentation,i believe there is something near to what you’re looking for if you don’t mind.
Dear @tendomart,
I have already gone through the documentation and code as well.i did not find anything related to this.
Please help me.
@rajuraghuwanshi did you see something like this in the documentation ?
Location URLs
GET /ws/rest/v1/location
Fetch all non-retired that match any specified parameters otherwise fetch all non-retired
GET /ws/rest/v1/location/{uuid}
Fetch by unique uuid
POST /ws/rest/v1/location
Create with properties in request
POST /ws/rest/v1/location/{uuid}
Edit with given uuid, only modifying properties in request
DELETE /ws/rest/v1/location/{uuid}?!purge
Retire/Void this object
DELETE /ws/rest/v1/location/{uuid}?purge
Delete this object from the database
Yes but the given REST api GET /ws/rest/v1/location return all location objects.
In HibernateLocationDAO class two method is there
1.return all location
@SuppressWarnings("unchecked") public List<Location> getAllLocations(boolean includeRetired) { Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Location.class); if (!includeRetired) { criteria.add(Restrictions.eq("retired", false)); } else { //push retired locations to the end of the returned list criteria.addOrder(Order.asc("retired")); } criteria.addOrder(Order.asc("name")); return criteria.list(); }
2.` /** * @see LocationDAO#getRootLocations(boolean) */ @SuppressWarnings(“unchecked”) @Override public List getRootLocations(boolean includeRetired) throws DAOException {
Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Location.class);
if (!includeRetired) {
criteria.add(Restrictions.eq("retired", false));
}
criteria.add(Restrictions.isNull("parentLocation"));
criteria.addOrder(Order.asc("name"));
return criteria.list();
}`
My requirment is to call second method which returns all location object where parentPointer is null.
@rajuraghuwanshi i’d suggest you use the context object,which gives you access to the whole Api,if not then create your own controller or introduce a controller method which does that specific Job.
for instance :
List locations = Context.getLocationService().getAllLocations();
simply call the service method in the controller you want,and the service in turn will expose all the methods in the corresponding Repository Object.
Then the result in the controller may be Mapped onto ViewMapping object or configured as a Rest service.
Kindly take a look at these links if you don’t mind
https://wiki.openmrs.org/display/docs/API
https://docs.openmrs.org/doc/org/openmrs/api/LocationService.html
Dear @tendomart,
I have updated the code of getAllLocations(boolean includeRetired) function inside HibernateLocationDAO. Thanks for helping me.