Developer How-To Use the OpenMRS API
[edit]
Demarcating start and end of API work
- When coding against the database API, domain objects (
Patient code>,User code>, etc.) provided from the API are only guaranteed to be valid between calls tocontext.openSession() code>andcontext.closeSession() code>.- You needn't worry about this within a web application environment as long as your are using a filter such as
org.openmrs.web.OpenmrsFilter code> (since the filter marks the boundaries around each HTTP request) - You cannot use domain objects across transactions (or requests) (e.g., if you loaded a
Patient code> object on one web page, you must reload that object, before using it on subsequent pages)
- You needn't worry about this within a web application environment as long as your are using a filter such as
- It is the developer's responsibility to ensure that
context.closeSession() code>is called (if not within webapp environment) to release precious resources (even in the event of an exception) - These transaction boundary calls are lightweight -- i.e., there is little penalty for calling them
