org.openmrs.logic.result
Class Result

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<E>
          extended by java.util.ArrayList<Result>
              extended by org.openmrs.logic.result.Result
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.lang.Iterable<Result>, java.util.Collection<Result>, java.util.List<Result>, java.util.RandomAccess
Direct Known Subclasses:
EmptyResult

public class Result
extends java.util.ArrayList<Result>

A result from the logic service. A result can be 0-to-n date-values pairs. You can treat the result as a list or easily coerce it into a simple value as needed.

When possible, results carry references to more complex objects so that code that deals with results and has some prior knowledge of the objects returned by a particular rule can more easily get to the full-featured objects instead of the simplified values in the date-value pairs.

TODO: eliminate unnecessary methods (toDatetime(), getDatetime(), and getDate() should all do the same thing)
TODO: better support/handling of NULL_RESULT

See Also:
Serialized Form

Nested Class Summary
static class Result.Datatype
          Core datatypes for a result.
 
Field Summary
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
Result()
           
Result(java.lang.Boolean valueBoolean)
          Builds a boolean result with a result date of today
Result(Concept valueCoded)
          Builds a coded result with a result date of today
Result(java.util.Date valueDatetime)
          Builds a datetime result with a result date of today
Result(java.util.Date resultDate, java.lang.Boolean valueBoolean, java.lang.Object obj)
          Builds a boolean result with a specific result date
Result(java.util.Date resultDate, Concept valueCoded, java.lang.Object obj)
          Builds a coded result with a specific result date
Result(java.util.Date resultDate, java.util.Date valueDatetime, java.lang.Object obj)
          Builds a datetime result with a specific result date
Result(java.util.Date resultDate, java.lang.Double valueNumeric, java.lang.Object obj)
          Builds a numeric result with a specific result date
Result(java.util.Date resultDate, java.lang.Integer valueNumeric, java.lang.Object obj)
          Builds a numeric result with a specific result date
Result(java.util.Date resultDate, Result.Datatype datatype, java.lang.Boolean valueBoolean, Concept valueCoded, java.util.Date valueDatetime, java.lang.Double valueNumeric, java.lang.String valueText, java.lang.Object object)
          Builds a result date with specific (overloaded) values — i.e., instead of simply accepting the default translation of one datatype into another (e.g., a date translated automatically into string format), this contructor allows the various datatype representations of the result to be individually controlled.
Result(java.util.Date resultDate, java.lang.String valueText, java.lang.Object obj)
          Builds a text result with a specific result date
Result(java.lang.Double valueNumeric)
          Builds a numeric result with a result date of today
Result(java.lang.Integer valueNumeric)
          Builds a numeric result with a result date of today
Result(java.util.List<Result> list)
          Builds a result from a list of results
Result(Obs obs)
          Builds a coded result from an observation
Result(Result result)
          Builds result upon another result — the first step in create a result that contains a list of other results.
Result(java.lang.String valueText)
          Builds a text result with a result date of today
 
Method Summary
 boolean contains(Concept concept)
           
 boolean contains(Result result)
           
 boolean containsConcept(java.lang.Integer conceptId)
           
 Result earliest()
           
static Result emptyResult()
           
 boolean equals(java.lang.Object obj)
           
 boolean exists()
           
 Result get(int index)
           
 Result.Datatype getDatatype()
          Returns the datatype of the result.
 java.util.Date getResultDate()
          Returns the data of the result (not to be confused with a data value).
 java.lang.Object getResultObject()
          Get the result object
 Result gt(java.lang.Integer value)
           
 boolean isNull()
           
 Result latest()
           
static Result nullResult()
          Deprecated. 
 void setDatatype(Result.Datatype datatype)
          Changes the default datatype of the result
 void setResultDate(java.util.Date resultDatetime)
          Changes the result date time — not to be confused with a value that is a date.
 void setResultObject(java.lang.Object object)
          Set the result object
 void setValueBoolean(java.lang.Boolean valueBoolean)
          Overrides the boolean representation of ths result without changing the default datatype
 void setValueCoded(Concept valueCoded)
          Overrides the coded representation of ths result without changing the default datatype
 void setValueDatetime(java.util.Date valueDatetime)
          Overrides the datetime representation of ths result without changing the default datatype
 void setValueNumeric(java.lang.Double valueNumeric)
          Overrides the numeric representation of ths result without changing the default datatype
 void setValueNumeric(java.lang.Integer valueNumeric)
          Overrides the numeric representation of ths result without changing the default datatype
 void setValueText(java.lang.String valueText)
          Overrides the text representation of ths result without changing the default datatype
 java.lang.Boolean toBoolean()
           
 Concept toConcept()
           
 java.util.Date toDatetime()
           
 java.lang.Double toNumber()
           
 java.lang.Object toObject()
           
 java.lang.String toString()
           
 Result unique()
           
 
Methods inherited from class java.util.ArrayList
add, add, addAll, addAll, clear, clone, contains, ensureCapacity, indexOf, isEmpty, lastIndexOf, remove, remove, removeRange, set, size, toArray, toArray, trimToSize
 
Methods inherited from class java.util.AbstractList
hashCode, iterator, listIterator, listIterator, subList
 
Methods inherited from class java.util.AbstractCollection
containsAll, removeAll, retainAll
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
containsAll, hashCode, iterator, listIterator, listIterator, removeAll, retainAll, subList
 

Constructor Detail

Result

public Result()

Result

public Result(Result result)
Builds result upon another result — the first step in create a result that contains a list of other results.

Parameters:
result - the result that will be the sole member of the new result
Expected behavior:
not fail with null result

Result

public Result(java.util.List<Result> list)
Builds a result from a list of results

Parameters:
list - a list of results
Expected behavior:
not fail with null list, not fail with empty list

Result

public Result(java.lang.Boolean valueBoolean)
Builds a boolean result with a result date of today

Parameters:
valueBoolean -

Result

public Result(java.util.Date resultDate,
              java.lang.Boolean valueBoolean,
              java.lang.Object obj)
Builds a boolean result with a specific result date

Parameters:
resultDate -
valueBoolean -

Result

public Result(Concept valueCoded)
Builds a coded result with a result date of today

Parameters:
valueCoded -

Result

public Result(java.util.Date resultDate,
              Concept valueCoded,
              java.lang.Object obj)
Builds a coded result with a specific result date

Parameters:
resultDate -
valueCoded -

Result

public Result(Obs obs)
Builds a coded result from an observation

Parameters:
obs -

Result

public Result(java.util.Date valueDatetime)
Builds a datetime result with a result date of today

Parameters:
valueDatetime -

Result

public Result(java.util.Date resultDate,
              java.util.Date valueDatetime,
              java.lang.Object obj)
Builds a datetime result with a specific result date

Parameters:
resultDate -
valueDatetime -

Result

public Result(java.lang.Double valueNumeric)
Builds a numeric result with a result date of today

Parameters:
valueNumeric -

Result

public Result(java.util.Date resultDate,
              java.lang.Double valueNumeric,
              java.lang.Object obj)
Builds a numeric result with a specific result date

Parameters:
resultDate -
valueNumeric -

Result

public Result(java.lang.Integer valueNumeric)
Builds a numeric result with a result date of today

Parameters:
valueNumeric -

Result

public Result(java.util.Date resultDate,
              java.lang.Integer valueNumeric,
              java.lang.Object obj)
Builds a numeric result with a specific result date

Parameters:
resultDate -
valueNumeric -

Result

public Result(java.lang.String valueText)
Builds a text result with a result date of today

Parameters:
valueText -

Result

public Result(java.util.Date resultDate,
              java.lang.String valueText,
              java.lang.Object obj)
Builds a text result with a specific result date

Parameters:
resultDate -
valueText -

Result

public Result(java.util.Date resultDate,
              Result.Datatype datatype,
              java.lang.Boolean valueBoolean,
              Concept valueCoded,
              java.util.Date valueDatetime,
              java.lang.Double valueNumeric,
              java.lang.String valueText,
              java.lang.Object object)
Builds a result date with specific (overloaded) values — i.e., instead of simply accepting the default translation of one datatype into another (e.g., a date translated automatically into string format), this contructor allows the various datatype representations of the result to be individually controlled. Any values set to null will yield the natural translation of the default datatype. For example,
 Result result = new Result(new Date(), 2.5);
 assertEqualtes("2.5", result.toString());
 
 Result result = new Result(new Date(),
                            Result.Datatype.NUMERIC,
                            2.5,
                            null,
                            null,
                            "Two and a half",
                            null);
 assertEquals("Two and a half", result.toString());
 

Parameters:
resultDate -
datatype -
valueBoolean -
valueCoded -
valueDatetime -
valueNumeric -
valueText -
object -
Method Detail

nullResult

@Deprecated
public static final Result nullResult()
Deprecated. 


emptyResult

public static final Result emptyResult()
Returns:
null/empty result

getDatatype

public Result.Datatype getDatatype()
Returns the datatype of the result. If the result is a list of other results, then the datatype of the first element is returned

Returns:
datatype of the result

setResultDate

public void setResultDate(java.util.Date resultDatetime)
Changes the result date time — not to be confused with a value that is a date. The result date time is typically the datetime that the observation was recorded.

Parameters:
resultDatetime -

setDatatype

public void setDatatype(Result.Datatype datatype)
Changes the default datatype of the result

Parameters:
datatype -

setValueBoolean

public void setValueBoolean(java.lang.Boolean valueBoolean)
Overrides the boolean representation of ths result without changing the default datatype

Parameters:
valueBoolean -

setValueCoded

public void setValueCoded(Concept valueCoded)
Overrides the coded representation of ths result without changing the default datatype

Parameters:
valueCoded -

setValueDatetime

public void setValueDatetime(java.util.Date valueDatetime)
Overrides the datetime representation of ths result without changing the default datatype

Parameters:
valueDatetime -

setValueNumeric

public void setValueNumeric(java.lang.Integer valueNumeric)
Overrides the numeric representation of ths result without changing the default datatype

Parameters:
valueNumeric -

setValueNumeric

public void setValueNumeric(java.lang.Double valueNumeric)
Overrides the numeric representation of ths result without changing the default datatype

Parameters:
valueNumeric -

setValueText

public void setValueText(java.lang.String valueText)
Overrides the text representation of ths result without changing the default datatype

Parameters:
valueText -

getResultDate

public java.util.Date getResultDate()
Returns the data of the result (not to be confused with a data value). For example, if a result represents an observation like DATE STARTED ON HIV TREATMENT, the result date (returned by this method) would be the date the observation was recorded while the toDatetime() method would be used to get the actual answer (when the patient started their treatment).

Returns:
date of the result (usually the date the result was recorded or observed)
See Also:
toDatetime()

getResultObject

public java.lang.Object getResultObject()
Get the result object

Returns:
the underlying result object

setResultObject

public void setResultObject(java.lang.Object object)
Set the result object

Parameters:
object -

toBoolean

public java.lang.Boolean toBoolean()
Returns:
boolean representation of the result. For non-boolean results, this will either be the overridden boolean value (if specifically defined) or a boolean representation of the default datatype. If the result is a list, then return false only if all members are false
Datatype Returns
CODED false for concept FALSE
true for all others
DATETIME true for any date value
false if the date is null
NUMERIC true for any non-zero number
false for zero
TEXT true for any non-blank value
false if blank or null

toConcept

public Concept toConcept()
Returns:
concept for result. For non-concept results, returns the concept value if it was overridden (specifically defined for the result), otherwise returns null. If the result is a list, then the concept for the first member is returned.

toDatetime

public java.util.Date toDatetime()
Returns:
the datetime representation of the result value (not to be confused with the result's own datetime). For non-datetime results, this will return the overridden datetime value (if specifically defined) or datetime representation of the default datatype. If the result is a list, then the datetime representation of the first member is returned.
Datatype Returns
BOOLEAN null
CODED null
NUMERIC null
TEXT If the text can be parsed into a date, then that value is returned;
otherwise returns null

toNumber

public java.lang.Double toNumber()
Returns:
numeric representation of the result. For non-numeric results, this will either be the overridden numeric value (if specifically defined) or a numeric representation of the default datatype. If the result is a list, then the value of the first element is returned.
Datatype Returns
BOOLEAN 1 for true
0 for false
CODED zero (0)
DATETIME Number of milliseconds since Java's epoch
TEXT numeric value of text if it can be parsed into a number
otherwise zero (0)

toString

public java.lang.String toString()
Overrides:
toString in class java.util.AbstractCollection<Result>
Returns:
string representation of the result. For non-text results, this will either be the overridden text value (if specifically defined) or a string representation of the default datatype value. If the result is a list, then the string representation of all members a joined with commas.

toObject

public java.lang.Object toObject()
Returns:
the object associated with the result (generally, this is used internally or for advanced rule design)
Expected behavior:
return resultObject for single results, return all results for result list

isNull

public boolean isNull()
Returns:
true if result is empty

exists

public boolean exists()
Returns:
true if the result has any non-zero, non-empty value

contains

public boolean contains(Concept concept)

gt

public Result gt(java.lang.Integer value)
Returns:
all results greater than the given value

containsConcept

public boolean containsConcept(java.lang.Integer conceptId)
Returns:
true if result contains a coded value with the given concept id (if the result is a list, then returns true if any member has a matching coded value)

contains

public boolean contains(Result result)
Returns:
true if the result is equal to the given result or is a list containing a member equal to the given result

unique

public Result unique()
Returns:
a result with all duplicates removed

equals

public boolean equals(java.lang.Object obj)
Specified by:
equals in interface java.util.Collection<Result>
Specified by:
equals in interface java.util.List<Result>
Overrides:
equals in class java.util.AbstractList<Result>
See Also:
Object.equals(java.lang.Object)

get

public Result get(int index)
Specified by:
get in interface java.util.List<Result>
Overrides:
get in class java.util.ArrayList<Result>
Returns:
the index element of a list. If the result is not a list, then this will return the result only if index is equal to zero (0); otherwise, returns an empty result
See Also:
List.get(int)
Expected behavior:
get empty result for indexes out of range

earliest

public Result earliest()
Returns:
the chronologically (based on result date) first result
Expected behavior:
get the first result given multiple results, get the result given a single result, get an empty result given an empty result, not get the result with null result date given other results, get one result with null result dates for all results

latest

public Result latest()
Returns:
the chronologically (based on result date) last result
Expected behavior:
get the most recent result given multiple results, get the result given a single result, get an empty result given an empty result, get the result with null result date

OpenMRS-1.7.x

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