org.openmrs
Class Obs

java.lang.Object
  extended by org.openmrs.BaseOpenmrsObject
      extended by org.openmrs.BaseOpenmrsData
          extended by org.openmrs.Obs
All Implemented Interfaces:
java.io.Serializable, Auditable, OpenmrsData, OpenmrsObject, Voidable

public class Obs
extends BaseOpenmrsData
implements java.io.Serializable

An observation is a single unit of clinical information.

Observations are collected and grouped together into one Encounter (one visit). Obs can be grouped in a hierarchical fashion.

The getObsGroup() method returns an optional parent. That parent object is also an Obs. The parent Obs object knows about its child objects through the getGroupMembers() method. (Multi-level hierarchies are achieved by an Obs parent object being a member of another Obs (grand)parent object) Read up on the obs table: http://openmrs.org/wiki/Obs_Table_Primer

See Also:
Encounter, Serialized Form

Field Summary
protected  java.lang.String accessionNumber
           
protected  java.lang.String comment
           
protected  ComplexData complexData
           
protected  Concept concept
           
protected  java.util.Date dateStarted
           
protected  java.util.Date dateStopped
           
protected  Encounter encounter
           
protected  java.util.Set<Obs> groupMembers
          The list of obs grouped under this obs.
protected  Location location
           
protected  java.util.Date obsDatetime
           
protected  Obs obsGroup
          The "parent" of this obs.
protected  java.lang.Integer obsId
           
protected  Order order
           
protected  Person person
           
protected  java.lang.Integer personId
           
static long serialVersionUID
           
protected  Concept valueCoded
           
protected  ConceptName valueCodedName
           
protected  java.lang.String valueComplex
           
protected  java.util.Date valueDatetime
           
protected  Drug valueDrug
           
protected  java.lang.Integer valueGroupId
           
protected  java.lang.String valueModifier
           
protected  java.lang.Double valueNumeric
           
protected  java.lang.String valueText
           
 
Fields inherited from class org.openmrs.BaseOpenmrsData
creator
 
Constructor Summary
Obs()
          default constructor
Obs(java.lang.Integer obsId)
          constructor with id
Obs(Person person, Concept question, java.util.Date obsDatetime, Location location)
          Required parameters constructor A value is also required, but that can be one of: valueCoded, valueDrug, valueNumeric, or valueText
 
Method Summary
 void addGroupMember(Obs member)
          Convenience method to add the given obs to this grouping.
 boolean equals(java.lang.Object obj)
          Compares two Obs for similarity.
 java.lang.String getAccessionNumber()
           
 java.lang.String getComment()
           
 ComplexData getComplexData()
          Get the ComplexData.
 Concept getConcept()
           
 ConceptDescription getConceptDescription()
          Get the concept description that is tied to the concept name that was used when making this observation
 java.util.Date getDateStarted()
           
 java.util.Date getDateStopped()
           
 Encounter getEncounter()
           
 java.util.Set<Obs> getGroupMembers()
          Get the members of the obs group, if this obs is a group.
 java.lang.Integer getId()
           
 Location getLocation()
           
 java.util.Date getObsDatetime()
           
 Obs getObsGroup()
          An obs grouping occurs when the question (#getConcept()) is a set.
 java.lang.Integer getObsGroupId()
          Deprecated. The getObsGroup() method should be used
 java.lang.Integer getObsId()
           
 Order getOrder()
           
 Patient getPatient()
          Deprecated. use getPerson()
 Person getPerson()
          Get the person object that this obs is acting on.
 java.lang.Integer getPersonId()
          The person id of the person on this object.
 java.util.Set<Obs> getRelatedObservations()
          Convenience method that returns related Obs If the Obs argument is not an ObsGroup: a Set will be returned containing all of the children of this Obs' parent that are not ObsGroups themselves.
 java.lang.Boolean getValueAsBoolean()
          Coerces a value to a Boolean representation
 java.util.Map<java.util.Locale,java.lang.String> getValueAsString()
          Deprecated.  
 java.lang.String getValueAsString(java.util.Locale locale)
          Convenience method for obtaining the observation's value as a string If the Obs is complex, returns the title of the complexData denoted by the section of getValueComplex() before the first bar '|' character; or returns the entire getValueComplex() if the bar '|' character is missing.
 java.lang.Boolean getValueBoolean()
          Returns the boolean value if the concept of this obs is of boolean datatype
 Concept getValueCoded()
           
 ConceptName getValueCodedName()
          Gets the specific name used for the coded value.
 java.lang.String getValueComplex()
          Get the value for the ComplexData.
 java.util.Date getValueDatetime()
           
 Drug getValueDrug()
           
 java.lang.Integer getValueGroupId()
           
 java.lang.String getValueModifier()
           
 java.lang.Double getValueNumeric()
           
 java.lang.String getValueText()
           
 boolean hasGroupMembers()
          Convenience method that checks for nullity and length of the (@link #getGroupMembers()) method
 int hashCode()
           
 boolean isComplex()
           
 boolean isObsGrouping()
          Convenience method that checks for nullity and length of the (@link #getGroupMembers()) method
static Obs newInstance(Obs obsToCopy)
          This is an equivalent to a copy constructor.
 void removeGroupMember(Obs member)
          Convenience method to remove an Obs from this grouping This also removes the link in the given obsobject to this obs grouper
 void setAccessionNumber(java.lang.String accessionNumber)
           
 void setComment(java.lang.String comment)
           
 void setComplexData(ComplexData complexData)
          Set the ComplexData for this Obs.
 void setConcept(Concept concept)
           
 void setDateStarted(java.util.Date dateStarted)
           
 void setDateStopped(java.util.Date dateStopped)
           
 void setEncounter(Encounter encounter)
           
 void setGroupMembers(java.util.Set<Obs> groupMembers)
          Set the members of the obs group, if this obs is a group.
 void setId(java.lang.Integer id)
           
 void setLocation(Location location)
           
 void setObsDatetime(java.util.Date obsDatetime)
           
 void setObsGroup(Obs obsGroup)
          This method does NOT add this current obs to the list of obs in obsGroup.getGroupMembers().
 void setObsGroupId(java.lang.Integer obsGroupId)
          Deprecated. This method should not be used. The #setObsGroup() method should be used instead
 void setObsId(java.lang.Integer obsId)
           
 void setOrder(Order order)
           
 void setPatient(Patient patient)
          Deprecated. use setPerson(org.openmrs.Person)
 void setPerson(Person person)
          Set the person object to this obs object.
protected  void setPersonId(java.lang.Integer personId)
          Set the person id on this obs object.
 void setRequiredProperties(User creator, java.util.Date dateCreated)
          Deprecated. no longer needed. Replaced by handlers.
 void setValueAsString(java.lang.String s)
          Sets the value for the obs from a string depending on the datatype of the question concept
 void setValueBoolean(java.lang.Boolean valueBoolean)
          Sets the value of this obs to the specified valueBoolean if this obs has a boolean concept.
 void setValueCoded(Concept valueCoded)
           
 void setValueCodedName(ConceptName valueCodedName)
          Sets the specific name used for the coded value.
 void setValueComplex(java.lang.String valueComplex)
          Set the value for the ComplexData.
 void setValueDatetime(java.util.Date valueDatetime)
           
 void setValueDrug(Drug valueDrug)
           
 void setValueGroupId(java.lang.Integer valueGroupId)
           
 void setValueModifier(java.lang.String valueModifier)
           
 void setValueNumeric(java.lang.Double valueNumeric)
           
 void setValueText(java.lang.String valueText)
           
 java.lang.String toString()
           
 
Methods inherited from class org.openmrs.BaseOpenmrsData
getChangedBy, getCreator, getDateChanged, getDateCreated, getDateVoided, getVoided, getVoidedBy, getVoidReason, isVoided, setChangedBy, setCreator, setDateChanged, setDateCreated, setDateVoided, setVoided, setVoidedBy, setVoidReason
 
Methods inherited from class org.openmrs.BaseOpenmrsObject
getUuid, setUuid
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.openmrs.OpenmrsObject
getUuid, setUuid
 

Field Detail

serialVersionUID

public static final long serialVersionUID
See Also:
Constant Field Values

obsId

protected java.lang.Integer obsId

concept

protected Concept concept

obsDatetime

protected java.util.Date obsDatetime

accessionNumber

protected java.lang.String accessionNumber

obsGroup

protected Obs obsGroup
The "parent" of this obs. It is the grouping that brings other obs together. note: obsGroup.getConcept().isSet() should be true This will be non-null if this obs is a member of another groupedObs

See Also:
(??)

groupMembers

protected java.util.Set<Obs> groupMembers
The list of obs grouped under this obs.


valueCoded

protected Concept valueCoded

valueCodedName

protected ConceptName valueCodedName

valueDrug

protected Drug valueDrug

valueGroupId

protected java.lang.Integer valueGroupId

valueDatetime

protected java.util.Date valueDatetime

valueNumeric

protected java.lang.Double valueNumeric

valueModifier

protected java.lang.String valueModifier

valueText

protected java.lang.String valueText

valueComplex

protected java.lang.String valueComplex

complexData

protected transient ComplexData complexData

comment

protected java.lang.String comment

personId

protected transient java.lang.Integer personId

person

protected Person person

order

protected Order order

location

protected Location location

encounter

protected Encounter encounter

dateStarted

protected java.util.Date dateStarted

dateStopped

protected java.util.Date dateStopped
Constructor Detail

Obs

public Obs()
default constructor


Obs

public Obs(Person person,
           Concept question,
           java.util.Date obsDatetime,
           Location location)
Required parameters constructor A value is also required, but that can be one of: valueCoded, valueDrug, valueNumeric, or valueText

Parameters:
person - The Person this obs is acting on
question - The question concept this obs is related to
obsDatetime - The time this obs took place
location - The location this obs took place

Obs

public Obs(java.lang.Integer obsId)
constructor with id

Method Detail

newInstance

public static Obs newInstance(Obs obsToCopy)
This is an equivalent to a copy constructor. Creates a new copy of the given obsToCopy with a null obs id

Parameters:
obsToCopy - The Obs that is going to be copied
Returns:
a new Obs object with all the same attributes as the given obs

equals

public boolean equals(java.lang.Object obj)
Compares two Obs for similarity. The comparison is done on obsId of both this and the given obs object. If either has a null obsId, then they are not equal

Overrides:
equals in class java.lang.Object
Parameters:
obj -
Returns:
boolean True if the obsIds match, false otherwise or if either obsId is null.

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object
See Also:
Object.hashCode()

setRequiredProperties

@Deprecated
public void setRequiredProperties(User creator,
                                             java.util.Date dateCreated)
Deprecated. no longer needed. Replaced by handlers.

This method isn't needed anymore. There are handlers that are mapped around the saveObs(obs) method that get called automatically. See SaveHandler, et al.

See Also:
SaveHandler, OpenmrsObjectSaveHandler, AuditableSaveHandler

getComment

public java.lang.String getComment()
Returns:
Returns the comment.

setComment

public void setComment(java.lang.String comment)
Parameters:
comment - The comment to set.

getConcept

public Concept getConcept()
Returns:
Returns the concept.

setConcept

public void setConcept(Concept concept)
Parameters:
concept - The concept to set.

getConceptDescription

public ConceptDescription getConceptDescription()
Get the concept description that is tied to the concept name that was used when making this observation

Returns:
ConceptDescription the description used

getEncounter

public Encounter getEncounter()
Returns:
Returns the encounter.

setEncounter

public void setEncounter(Encounter encounter)
Parameters:
encounter - The encounter to set.

getLocation

public Location getLocation()
Returns:
Returns the location.

setLocation

public void setLocation(Location location)
Parameters:
location - The location to set.

getObsDatetime

public java.util.Date getObsDatetime()
Returns:
Returns the obsDatetime.

setObsDatetime

public void setObsDatetime(java.util.Date obsDatetime)
Parameters:
obsDatetime - The obsDatetime to set.

getObsGroupId

public java.lang.Integer getObsGroupId()
Deprecated. The getObsGroup() method should be used

Returns:
Returns the obsId of the parent obs group
See Also:
getObsGroup()

setObsGroupId

public void setObsGroupId(java.lang.Integer obsGroupId)
Deprecated. This method should not be used. The #setObsGroup() method should be used instead

Parameters:
obsGroupId - The obsGroupId to set.
See Also:
setObsGroup(Obs)

getObsGroup

public Obs getObsGroup()
An obs grouping occurs when the question (#getConcept()) is a set. (@link org.openmrs.Concept#isSet()) If this is non-null, it means the current Obs is in the list returned by obsGroup.getGroupMembers()

Returns:
the Obs that is the grouping factor

setObsGroup

public void setObsGroup(Obs obsGroup)
This method does NOT add this current obs to the list of obs in obsGroup.getGroupMembers(). That must be done (and should be done) manually. (I am not doing it here for fear of screwing up the normal loading and creation of this object via hibernate/spring)

Parameters:
obsGroup - the obsGroup to set

isObsGrouping

public boolean isObsGrouping()
Convenience method that checks for nullity and length of the (@link #getGroupMembers()) method

NOTE: This method could also be called "isObsGroup" for a little less confusion on names. However, jstl in a web layer (or any psuedo-getter) access isn't good with both an "isObsGroup" method and a "getObsGroup" method. Which one should be returned with a simplified jstl call like ${obs.obsGroup} ? With this setup, ${obs.obsGrouping} returns a boolean of whether this obs is a parent and has members. ${obs.obsGroup} returns the parent object to this obs if this obs is a group member of some other group.

Returns:
true if this is the parent group of other obs

hasGroupMembers

public boolean hasGroupMembers()
Convenience method that checks for nullity and length of the (@link #getGroupMembers()) method

Returns:
true if this is the parent group of other obs

getGroupMembers

public java.util.Set<Obs> getGroupMembers()
Get the members of the obs group, if this obs is a group.

If it's not a group (i.e. getConcept().Concept.isSet() is not true, then this returns null.

Returns:
a Set of the members of this group.
See Also:
addGroupMember(Obs), hasGroupMembers()

setGroupMembers

public void setGroupMembers(java.util.Set<Obs> groupMembers)
Set the members of the obs group, if this obs is a group.

If it's not a group (i.e. getConcept().Concept.isSet() is not true, then this returns null.

Parameters:
groupMembers - the groupedObs to set
See Also:
addGroupMember(Obs), hasGroupMembers()

addGroupMember

public void addGroupMember(Obs member)
Convenience method to add the given obs to this grouping. Will implicitly make this obs an ObsGroup

Parameters:
member - Obs to add to this group
See Also:
setGroupMembers(Set), getGroupMembers()

removeGroupMember

public void removeGroupMember(Obs member)
Convenience method to remove an Obs from this grouping This also removes the link in the given obsobject to this obs grouper

Parameters:
member - Obs to remove from this group
See Also:
setGroupMembers(Set), getGroupMembers()

getRelatedObservations

public java.util.Set<Obs> getRelatedObservations()
Convenience method that returns related Obs If the Obs argument is not an ObsGroup: a Set will be returned containing all of the children of this Obs' parent that are not ObsGroups themselves. This will include this Obs by default, unless getObsGroup() returns null, in which case an empty set is returned. If the Obs argument is an ObsGroup: a Set will be returned containing 1. all of this Obs' group members, and 2. all ancestor Obs that are not themselves obsGroups.

Returns:
Set

getObsId

public java.lang.Integer getObsId()
Returns:
Returns the obsId.

setObsId

public void setObsId(java.lang.Integer obsId)
Parameters:
obsId - The obsId to set.

getOrder

public Order getOrder()
Returns:
Returns the order.

setOrder

public void setOrder(Order order)
Parameters:
order - The order to set.

getPatient

public Patient getPatient()
Deprecated. use getPerson()

Returns:
Returns the patient.

setPatient

public void setPatient(Patient patient)
Deprecated. use setPerson(org.openmrs.Person)

To associate a patient with an obs, use setPerson(org.openmrs.Person)

Parameters:
patient -

getPersonId

public java.lang.Integer getPersonId()
The person id of the person on this object. This should be the same as getPerson().getPersonId(). It is duplicated here for speed and simplicity reasons

Returns:
the integer person id of the person this obs is acting on

setPersonId

protected void setPersonId(java.lang.Integer personId)
Set the person id on this obs object. This method is here for convenience, but really the setPerson(Person) method should be used like setPerson(new Person(personId))

Parameters:
personId -
See Also:
setPerson(Person)

getPerson

public Person getPerson()
Get the person object that this obs is acting on.

Returns:
the person object
See Also:
getPersonId()

setPerson

public void setPerson(Person person)
Set the person object to this obs object. This will also set the personId on this obs object

Parameters:
person - the Patient/Person object that this obs is acting on
See Also:
setPersonId(Integer)

setValueBoolean

public void setValueBoolean(java.lang.Boolean valueBoolean)
Sets the value of this obs to the specified valueBoolean if this obs has a boolean concept.

Parameters:
valueBoolean - the boolean value matching the boolean coded concept to set to

getValueAsBoolean

public java.lang.Boolean getValueAsBoolean()
Coerces a value to a Boolean representation

Returns:
Boolean representation of the obs value
Expected behavior:
return true for value_numeric concepts if value is 1, return false for value_numeric concepts if value is 0, return null for value_numeric concepts if value is neither 1 nor 0

getValueBoolean

public java.lang.Boolean getValueBoolean()
Returns the boolean value if the concept of this obs is of boolean datatype

Returns:
true or false if value is set otherwise null
Expected behavior:
return true if value coded answer concept is true concept, return false if value coded answer concept is false concept

getValueCoded

public Concept getValueCoded()
Returns:
Returns the valueCoded.

setValueCoded

public void setValueCoded(Concept valueCoded)
Parameters:
valueCoded - The valueCoded to set.

getValueCodedName

public ConceptName getValueCodedName()
Gets the specific name used for the coded value.

Returns:
the name of the coded value

setValueCodedName

public void setValueCodedName(ConceptName valueCodedName)
Sets the specific name used for the coded value.

Parameters:
valueCodedName - the name of the coded value

getValueDrug

public Drug getValueDrug()
Returns:
Returns the valueDrug

setValueDrug

public void setValueDrug(Drug valueDrug)
Parameters:
valueDrug - The valueDrug to set.

getValueDatetime

public java.util.Date getValueDatetime()
Returns:
Returns the valueDatetime.

setValueDatetime

public void setValueDatetime(java.util.Date valueDatetime)
Parameters:
valueDatetime - The valueDatetime to set.

getValueGroupId

public java.lang.Integer getValueGroupId()
Returns:
Returns the valueGroupId.

setValueGroupId

public void setValueGroupId(java.lang.Integer valueGroupId)
Parameters:
valueGroupId - The valueGroupId to set.

getValueModifier

public java.lang.String getValueModifier()
Returns:
Returns the valueModifier.

setValueModifier

public void setValueModifier(java.lang.String valueModifier)
Parameters:
valueModifier - The valueModifier to set.

getValueNumeric

public java.lang.Double getValueNumeric()
Returns:
Returns the valueNumeric.

setValueNumeric

public void setValueNumeric(java.lang.Double valueNumeric)
Parameters:
valueNumeric - The valueNumeric to set.

getValueText

public java.lang.String getValueText()
Returns:
Returns the valueText.

setValueText

public void setValueText(java.lang.String valueText)
Parameters:
valueText - The valueText to set.

isComplex

public boolean isComplex()
Returns:
Returns true if this Obs is complex.
Since:
1.5
Expected behavior:
return true if the concept is complex

getValueComplex

public java.lang.String getValueComplex()
Get the value for the ComplexData. This method is used by the ComplexObsHandler. The valueComplex has two parts separated by a bar '|' character: part A) the title; and part B) the URI. The title is the readable description of the valueComplex that is returned by getValueAsString(). The URI is the location where the ComplexData is stored.

Returns:
readable title and URI for the location of the ComplexData binary object.
Since:
1.5

setValueComplex

public void setValueComplex(java.lang.String valueComplex)
Set the value for the ComplexData. This method is used by the ComplexObsHandler. The valueComplex has two parts separated by a bar '|' character: part A) the title; and part B) the URI. The title is the readable description of the valueComplex that is returned by Obs.getValueAsString(). The URI is the location where the ComplexData is stored.

Parameters:
valueComplex - readable title and URI for the location of the ComplexData binary object.
Since:
1.5

setComplexData

public void setComplexData(ComplexData complexData)
Set the ComplexData for this Obs. The ComplexData is stored in the file system or elsewhere, but is not persisted to the database.

ComplexObsHandlers that are registered to ConceptComplexs will persist the ComplexData.getData() object to the correct place for the given concept.

Parameters:
complexData -
Since:
1.5

getComplexData

public ComplexData getComplexData()
Get the ComplexData. This is retrieved by the ComplexObsHandler from the file system or another location, not from the database.

This will be null unless you call:
    Obs obsWithComplexData = Context.getObsService().getComplexObs(obsId, OpenmrsConstants.RAW_VIEW);
 

Returns:
the complex data for this obs (if its a complex obs)
Since:
1.5

getAccessionNumber

public java.lang.String getAccessionNumber()
Returns:
Returns the accessionNumber.

setAccessionNumber

public void setAccessionNumber(java.lang.String accessionNumber)
Parameters:
accessionNumber - The accessionNumber to set.

getDateStarted

public java.util.Date getDateStarted()
Returns:
Returns the dateStarted.

setDateStarted

public void setDateStarted(java.util.Date dateStarted)
Parameters:
dateStarted - The dateStarted to set.

getDateStopped

public java.util.Date getDateStopped()
Returns:
Returns the dateStopped.

setDateStopped

public void setDateStopped(java.util.Date dateStopped)
Parameters:
dateStopped - The dateStopped to set.

getValueAsString

public java.lang.String getValueAsString(java.util.Locale locale)
Convenience method for obtaining the observation's value as a string If the Obs is complex, returns the title of the complexData denoted by the section of getValueComplex() before the first bar '|' character; or returns the entire getValueComplex() if the bar '|' character is missing.

Parameters:
locale - locale for locale-specific depictions of value
Expected behavior:
return first part of valueComplex for complex obs, return first part of valueComplex for non null valueComplexes

setValueAsString

public void setValueAsString(java.lang.String s)
                      throws java.text.ParseException
Sets the value for the obs from a string depending on the datatype of the question concept

Parameters:
s - the string to coerce to a boolean
Throws:
java.text.ParseException
Expected behavior:
set value as boolean if the datatype of the question concept is boolean, fail if the value of the string is null, fail if the value of the string is empty

getValueAsString

public java.util.Map<java.util.Locale,java.lang.String> getValueAsString()
Deprecated. 

This was a convenience method for obtaining a Map of available locale to observation's value as a string This method is a waste and should be not be used. This was used in the web layer because jstl can't pass parameters to a method (${obs.valueAsString[locale]} was used instead of what would be convenient ${obs.valueAsString(locale)}) Now the openmrs:format tag should be used in the web layer:


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
See Also:
Object.toString()

getId

public java.lang.Integer getId()
Specified by:
getId in interface OpenmrsObject
Returns:
id - The unique Identifier for the object
Since:
1.5
See Also:
OpenmrsObject.getId()

setId

public void setId(java.lang.Integer id)
Specified by:
setId in interface OpenmrsObject
Parameters:
id - - The unique Identifier for the object
Since:
1.5
See Also:
OpenmrsObject.setId(java.lang.Integer)

OpenMRS-1.7.x

Generated Apr 27 2012 10:06 PM. NOTE - these libraries are in active development and subject to change