The OpenMRS Logic Service provides access to granular and derived data. Medical data is extremely complex. While a dictionary-based system provides tremendous flexibility in collecting data, consuming the data for decision support, reporting, research question, or even for display within the web application can be increasingly difficult. For example, even answering a simple question like "is the patient HIV positive?" may require a complex algorithm that considers the results of multiple lab results, temporal relations of results, orders, and questionnaire responses. Ideally, this "business logic" is defined in one place and easily accessible to all aspects of the system — e.g., whether we're displaying HIV status on a web page, generating a PEPFAR report, or executing a decision support alert, the same algorithm should be used. We call this bit of business knowledge a "rule." Rules should be easily accessible and return predictable and flexible results.

Rules can be fashioned from just about any source, but must compile into a Java class that extends org.openmrs.logic.Rule (@see org.openmrs.logic.Rule).

Data can be obtained from the logic service like this:

`Patient myPatient = Context.getPatientService().getPatient(123); LogicService ls = Context.getLogicService(); Result age = ls.eval(myPatient, "AGE");`