public interface ObsService extends OpenmrsService
ObsService obsService = Context.getObsService(); // get the obs for patient with internal identifier of 1235 List<Obs> someObsList = obsService.getObservationsByPerson(new Patient(1235));There are also a number of convenience methods for extracting obs pertaining to certain Concepts, people, or encounters
Modifier and Type | Method and Description |
---|---|
Obs |
getComplexObs(Integer obsId,
String view)
Deprecated.
as of 2.1.0, use
getObs(Integer) |
ComplexObsHandler |
getHandler(Obs obs)
Get the ComplexObsHandler associated with a complex observation
Returns the ComplexObsHandler.
|
ComplexObsHandler |
getHandler(String key)
Get the ComplexObsHandler that has been registered with the given key
|
Map<String,ComplexObsHandler> |
getHandlers()
Gets the handlers map registered
|
Obs |
getObs(Integer obsId)
Get an observation
|
Obs |
getObsByUuid(String uuid)
Get Obs by its UUID
|
Integer |
getObservationCount(List<ConceptName> conceptNames,
boolean includeVoided)
Gets the number of observations(including voided ones) that are using the specified
conceptNames as valueCodedName answers
|
Integer |
getObservationCount(List<Person> whom,
List<Encounter> encounters,
List<Concept> questions,
List<Concept> answers,
List<OpenmrsConstants.PERSON_TYPE> personTypes,
List<Location> locations,
Integer obsGroupId,
Date fromDate,
Date toDate,
boolean includeVoidedObs)
This method fetches the count of observations according to the criteria in the given
arguments.
|
Integer |
getObservationCount(List<Person> whom,
List<Encounter> encounters,
List<Concept> questions,
List<Concept> answers,
List<OpenmrsConstants.PERSON_TYPE> personTypes,
List<Location> locations,
Integer obsGroupId,
Date fromDate,
Date toDate,
boolean includeVoidedObs,
String accessionNumber) |
Integer |
getObservationCount(List<Person> whom,
List<Encounter> encounters,
List<Concept> questions,
List<Concept> answers,
List<OpenmrsConstants.PERSON_TYPE> personTypes,
List<Location> locations,
List<Visit> visits,
Integer obsGroupId,
Date fromDate,
Date toDate,
boolean includeVoidedObs,
String accessionNumber) |
List<Obs> |
getObservations(List<Person> whom,
List<Encounter> encounters,
List<Concept> questions,
List<Concept> answers,
List<OpenmrsConstants.PERSON_TYPE> personTypes,
List<Location> locations,
List<String> sort,
Integer mostRecentN,
Integer obsGroupId,
Date fromDate,
Date toDate,
boolean includeVoidedObs)
This method fetches observations according to the criteria in the given arguments.
|
List<Obs> |
getObservations(List<Person> whom,
List<Encounter> encounters,
List<Concept> questions,
List<Concept> answers,
List<OpenmrsConstants.PERSON_TYPE> personTypes,
List<Location> locations,
List<String> sort,
Integer mostRecentN,
Integer obsGroupId,
Date fromDate,
Date toDate,
boolean includeVoidedObs,
String accessionNumber) |
List<Obs> |
getObservations(List<Person> whom,
List<Encounter> encounters,
List<Concept> questions,
List<Concept> answers,
List<OpenmrsConstants.PERSON_TYPE> personTypes,
List<Location> locations,
List<String> sort,
List<Visit> visits,
Integer mostRecentN,
Integer obsGroupId,
Date fromDate,
Date toDate,
boolean includeVoidedObs,
String accessionNumber) |
List<Obs> |
getObservations(String searchString)
This method searches the obs table based on the given
searchString . |
List<Obs> |
getObservationsByPerson(Person who)
Get all Observations for the given person, sorted by obsDatetime ascending.
|
List<Obs> |
getObservationsByPersonAndConcept(Person who,
Concept question)
Get all nonvoided observations for the given patient with the given concept as the question
concept (conceptId)
|
Obs |
getRevisionObs(Obs initialObs)
Get Revision Obs for initial Obs
|
void |
purgeObs(Obs obs)
Completely remove an observation from the database.
|
void |
purgeObs(Obs obs,
boolean cascade)
Completely remove an observation from the database.
|
void |
registerHandler(String key,
ComplexObsHandler handler)
Registers the given handler with the given key If the given String key exists, that handler
is overwritten with the given handler
|
void |
registerHandler(String key,
String handlerClass)
Convenience method for
registerHandler(String, ComplexObsHandler) |
void |
removeHandler(String key)
Remove the handler associated with the key from list of available handlers
|
Obs |
saveObs(Obs obs,
String changeMessage)
Save the given obs to the database.
|
void |
setHandlers(Map<String,ComplexObsHandler> handlers)
Add the given map to this service's handlers.
|
void |
setObsDAO(ObsDAO dao)
Set the given
dao on this obs service. |
Obs |
unvoidObs(Obs obs)
Revive an observation (pull a Lazarus)
|
Obs |
voidObs(Obs obs,
String reason)
Equivalent to deleting an observation
|
onShutdown, onStartup
void setObsDAO(ObsDAO dao)
dao
on this obs service. The dao will act as the conduit through
with all obs calls get to the databasedao
- specific ObsDAO to use for this service@Authorized(value="Get Observations") Obs getObs(Integer obsId) throws APIException
obsId
- integer obsId of observation desiredAPIException
- Should get obs matching given obsId@Authorized(value="Get Observations") Obs getObsByUuid(String uuid) throws APIException
uuid
- APIException
@Authorized(value="Get Observations") Obs getRevisionObs(Obs initialObs)
initialObs
- @Authorized(value={"Add Observations","Edit Observations"}) Obs saveObs(Obs obs, String changeMessage) throws APIException
Save the given obs to the database. The behavior differs for first-time save, and edit.
When you save a new observation to the database:
When you edit an existing observation:
obs
- the Obs to save to the databasechangeMessage
- String explaining why obs
is being changed. If
obs
is a new obs, changeMessage is nullable, or if it is being
updated, it would be requiredAPIException
- Should create new file from complex data for new obs
Should not overwrite file when updating a complex obs
Should void the given obs in the database
Should create very basic obs and add new obsId
Should allow setting properties on obs
Should return a different object when updating an obs
Should set creator and dateCreated on new obs
Should cascade save to child obs groups
Should cascade update to new child obs groups
Should link original and updated obs
Should set void reason message to changeMessage
Should not void an Obs with no changes@Authorized(value="Edit Observations") Obs voidObs(Obs obs, String reason) throws APIException
obs
- Obs to voidreason
- String reason it's being voidedAPIException
- Should set voided bit on given obs
Should fail if reason parameter is empty@Authorized(value="Edit Observations") Obs unvoidObs(Obs obs) throws APIException
obs
- Obs to unvoidAPIException
- Should unset voided bit on given obs
Should cascade unvoid to child grouped obs@Authorized(value="Delete Observations") void purgeObs(Obs obs) throws APIException
obs
- APIException
Should delete the given obs from the database
@Authorized(value="Delete Observations") void purgeObs(Obs obs, boolean cascade) throws APIException
obs
- the observation to remove from the databasecascade
- true/false whether or not to cascade down to other things that link to this
observation (like Orders and ObsGroups)APIException
Should throw APIException if given true cascade
Should delete any obsGroupMembers before deleting the obs
Should not delete referenced orders when purging obs
@Authorized(value="Get Observations") List<Obs> getObservationsByPerson(Person who)
who
- the user to match onShould get all observations assigned to given person
@Authorized(value="Get Observations") List<Obs> getObservations(List<Person> whom, List<Encounter> encounters, List<Concept> questions, List<Concept> answers, List<OpenmrsConstants.PERSON_TYPE> personTypes, List<Location> locations, List<String> sort, Integer mostRecentN, Integer obsGroupId, Date fromDate, Date toDate, boolean includeVoidedObs) throws APIException
location
and a
fromDate
are given, only Obs that are both at that Location and after the
fromDate are returned). whom
has elements, personType
is ignored whom
- List<Person> to restrict obs to (optional)encounters
- List<Encounter> to restrict obs to (optional)questions
- List<Concept> to restrict the obs to (optional)answers
- List<Concept> to restrict the valueCoded to (optional)personTypes
- List<PERSON_TYPE> objects to restrict this to. Only used if
whom
is an empty list (optional)locations
- The org.openmrs.Location objects to restrict to (optional)sort
- list of column names to sort on (obsId, obsDatetime, etc) if null, defaults to
obsDatetime (optional)mostRecentN
- restrict the number of obs returned to this size (optional)obsGroupId
- the Obs.getObsGroupId() to this integer (optional)fromDate
- the earliest Obs date to get (optional)toDate
- the latest Obs date to get (optional)includeVoidedObs
- true/false whether to also include the voided obs (required)APIException
@Authorized(value="Get Observations") List<Obs> getObservations(List<Person> whom, List<Encounter> encounters, List<Concept> questions, List<Concept> answers, List<OpenmrsConstants.PERSON_TYPE> personTypes, List<Location> locations, List<String> sort, Integer mostRecentN, Integer obsGroupId, Date fromDate, Date toDate, boolean includeVoidedObs, String accessionNumber) throws APIException
whom
- List<Person> to restrict obs to (optional)encounters
- List<Encounter> to restrict obs to (optional)questions
- List<Concept> to restrict the obs to (optional)answers
- List<Concept> to restrict the valueCoded to (optional)personTypes
- List<PERSON_TYPE> objects to restrict this to. Only used if
whom
is an empty list (optional)locations
- The org.openmrs.Location objects to restrict to (optional)sort
- list of column names to sort on (obsId, obsDatetime, etc) if null, defaults to
obsDatetime (optional)mostRecentN
- restrict the number of obs returned to this size (optional)obsGroupId
- the Obs.getObsGroupId() to this integer (optional)fromDate
- the earliest Obs date to get (optional)toDate
- the latest Obs date to get (optional)includeVoidedObs
- true/false whether to also include the voided obs (required)accessionNumber
- accession number (optional)APIException
- Should compare dates using lte and gte
Should get all obs assigned to given encounters
Should get all obs with question concept in given questions parameter
Should get all obs with answer concept in given answers parameter
Should return all obs whose person is a person only
Should return obs whose person is a patient only
Should return obs whose person is a user only
Should return obs with location in given locations parameter
Should sort returned obs by obsDatetime if sort is empty
Should sort returned obs by conceptId if sort is concept
Should limit number of obs returned to mostReturnN parameter
Should return obs whose groupId is given obsGroupId
Should not include voided obs
Should include voided obs if includeVoidedObs is true
Should only return observations with matching accession numberThis method works exactly the same; it only adds accession number search criteria.
It effectively surpasses the above method; the old one is however kept for backward
compatibility reasons.
@Authorized(value="Get Observations") Integer getObservationCount(List<Person> whom, List<Encounter> encounters, List<Concept> questions, List<Concept> answers, List<OpenmrsConstants.PERSON_TYPE> personTypes, List<Location> locations, Integer obsGroupId, Date fromDate, Date toDate, boolean includeVoidedObs) throws APIException
location
and a fromDate
are given, only Obs that are both at
that Location and after the fromDate are returned). whom
has elements, personType
is ignored whom
- List<Person> to restrict obs to (optional)encounters
- List<Encounter> to restrict obs to (optional)questions
- List<Concept> to restrict the obs to (optional)answers
- List<Concept> to restrict the valueCoded to (optional)personTypes
- List<PERSON_TYPE> objects to restrict this to. Only used if
whom
is an empty list (optional)locations
- The org.openmrs.Location objects to restrict to (optional) obsDatetime
(optional)obsGroupId
- the Obs.getObsGroupId() to this integer (optional)fromDate
- the earliest Obs date to get (optional)toDate
- the latest Obs date to get (optional)includeVoidedObs
- true/false whether to also include the voided obs (required)APIException
@Authorized(value="Get Observations") Integer getObservationCount(List<Person> whom, List<Encounter> encounters, List<Concept> questions, List<Concept> answers, List<OpenmrsConstants.PERSON_TYPE> personTypes, List<Location> locations, Integer obsGroupId, Date fromDate, Date toDate, boolean includeVoidedObs, String accessionNumber) throws APIException
whom
- List<Person> to restrict obs to (optional)encounters
- List<Encounter> to restrict obs to (optional)questions
- List<Concept> to restrict the obs to (optional)answers
- List<Concept> to restrict the valueCoded to (optional)personTypes
- List<PERSON_TYPE> objects to restrict this to. Only used if
whom
is an empty list (optional)locations
- The org.openmrs.Location objects to restrict to (optional) obsDatetime
(optional)obsGroupId
- the Obs.getObsGroupId() to this integer (optional)fromDate
- the earliest Obs date to get (optional)toDate
- the latest Obs date to get (optional)includeVoidedObs
- true/false whether to also include the voided obs (required)accessionNumber
- accession number (optional)APIException
- Should compare dates using lte and gte
Should get the count of all obs assigned to given encounters
Should get the count of all obs with question concept in given questions parameter
Should get the count of all obs with answer concept in given answers parameter
Should return the count of all obs whose person is a person only
Should return the count of all obs whose person is a patient only
Should return the count of obs whose person is a user only
Should return the count of obs with location in given locations parameter
Should return the count of obs whose groupId is given obsGroupId
Should not include count of voided obs
Should include count of voided obs if includeVoidedObs is true
Should return count of obs with matching accession numberThis method works exactly the same; it only adds accession number search criteria.
It effectively surpasses the above method; the old one is however kept for backward
compatibility reasons.
@Authorized(value="Get Observations") List<Obs> getObservations(String searchString) throws APIException
searchString
.searchString
- The string to search onAPIException
- Should get obs matching patient identifier in searchString
Should get obs matching encounterId in searchString
Should get obs matching obsId in searchString@Authorized(value="Get Observations") List<Obs> getObservationsByPersonAndConcept(Person who, Concept question) throws APIException
who
- person to match onquestion
- conceptId to match onAPIException
Should get observations matching person and question
Should not fail with null person parameter
@Deprecated @Authorized(value="Get Observations") Obs getComplexObs(Integer obsId, String view) throws APIException
getObs(Integer)
obsId
- APIException
ComplexObsHandler getHandler(String key) throws APIException
key
- that has been registered with a handler classAPIException
ComplexObsHandler getHandler(Obs obs) throws APIException
obs
- A complex Obs.APIException
void setHandlers(Map<String,ComplexObsHandler> handlers) throws APIException
handlers
- Map of class to handler objectAPIException
Map<String,ComplexObsHandler> getHandlers() throws APIException
APIException
- Should never return nullvoid registerHandler(String key, ComplexObsHandler handler) throws APIException
key
- the key name to use for this handlerhandler
- the class to register with this keyAPIException
void registerHandler(String key, String handlerClass) throws APIException
registerHandler(String, ComplexObsHandler)
key
- the key name to use for this handlerhandlerClass
- the class to register with this keyAPIException
void removeHandler(String key) throws APIException
key
- the key of the handler to unregisterAPIException
@Authorized(value="Get Observations") Integer getObservationCount(List<ConceptName> conceptNames, boolean includeVoided)
conceptNames
- the conceptNames to be searched againstincludeVoided
- whether voided observation should be included@Authorized(value="Get Observations") List<Obs> getObservations(List<Person> whom, List<Encounter> encounters, List<Concept> questions, List<Concept> answers, List<OpenmrsConstants.PERSON_TYPE> personTypes, List<Location> locations, List<String> sort, List<Visit> visits, Integer mostRecentN, Integer obsGroupId, Date fromDate, Date toDate, boolean includeVoidedObs, String accessionNumber) throws APIException
visits
- List<Visit> to restrict obs to (optional)APIException
This method works exactly the same; it only adds visits to the search criteria.
It effectively surpasses the above method; the old one is however kept for backward
compatibility reasons.
@Authorized(value="Get Observations") Integer getObservationCount(List<Person> whom, List<Encounter> encounters, List<Concept> questions, List<Concept> answers, List<OpenmrsConstants.PERSON_TYPE> personTypes, List<Location> locations, List<Visit> visits, Integer obsGroupId, Date fromDate, Date toDate, boolean includeVoidedObs, String accessionNumber) throws APIException
visits
- List<Visit> to restrict obs to (optional)APIException
This method works exactly the same; it only adds visits to the search criteria.
It effectively surpasses the above method; the old one is however kept for backward
compatibility reasons.
Copyright © 2024 OpenMRS Inc.. All rights reserved.