This document gives all the details about adding new resource to an openmrs module.
For our convenience let us take an example of Surgical Block resource in Operation theater. The resource is available here.
Web API is usually added in omod folder in module code. For adding a new resource go to
openmrs-module-operationtheater/omod/src/main/java/org/openmrs/module/operationtheater/web/resource
folder.
Eg:
@Resource(name = "/surgicalBlock1", supportedClass = SurgicalBlock.class, supportedOpenmrsVersions = {"2.0.*", "2.1.*"}) public class SurgicalOperationResource extends DataDelegatingCrudResource<SurgicalBlock> |
if ((representation instanceof DefaultRepresentation) || (representation instanceof RefRepresentation)) { DelegatingResourceDescription description = new DelegatingResourceDescription(); description.addProperty("id"); description.addProperty("uuid"); description.addProperty("provider", Representation.DEFAULT); } |
How to write Integration tests?
Integration tests test from end to end. They create an in-memory database. All the necessary hbm files need to be added <module>/omod/src/test/resources/test-hibernate.cfg.xml.
In hibernate-configuration section like below
<mapping resource="BedPatientAssignment.hbm.xml"/> <mapping resource="Bed.hbm.xml"/> |
At run time the hibernate configurations are picked up from here <module>/omod/src/test/resources/TestingApplicationContext.xml.
<property name="configLocations"> <list> <value>classpath:test-hibernate.cfg.xml</value> </list> </property> |
........ work in progress...