Sun Message Library for HL7

com.stc.hl7.dataUtils
Class HL7UtilityFunctions

java.lang.Object
  extended by com.stc.hl7.dataUtils.HL7UtilityFunctions

public class HL7UtilityFunctions
extends java.lang.Object

Utility functions for use on HL7 data. Based on the Monk Library Functions. Below is a table mapping the Java methods found in this class to the original Monk Library functions.

Java MethodsMonk Function Name
calcSurfaceBSA(java.lang.String, java.lang.String)calc-surface-bsa
calcSurfaceGG(java.lang.String, java.lang.String)calc-surface-gg
centimeterToInch(java.lang.String)cm->in
degCToDegF(java.lang.String)degc->degf
degFToDegC(java.lang.String)degf->degc
diffTwoDates(java.lang.String, java.lang.String)diff-two-dates
get2SSN(java.lang.String)get-2-ssn
get3SSN(java.lang.String)get-3-ssn
get4SSN(java.lang.String)get-4-ssn
getApartment(java.lang.String)get-apartment
getCity(java.lang.String)get-city
getFirstName(java.lang.String)get-first-name
getLastName(java.lang.String)get-last-name
getMiddleName(java.lang.String)get-middle-name
getState(java.lang.String)get-state
getStreetAddress(java.lang.String)get-street-address
getTimeStamp(java.lang.String)get-timestamp
getZipCode(java.lang.String)get-zip
inchToCentimeter(java.lang.String)in->cm
isLeapYear(java.lang.String)}leap-year?
isValidDate(java.lang.String)valid-date-yyyy?
isValidJulianDate(java.lang.String)julian-date?
isValidPhoneNumber(java.lang.String)valid-phone?
isValidSSN(java.lang.String)valid-ssn?
isValidTimeStamp(java.lang.String)valid-time?
julianToStandardDate(java.lang.String)julian->standard
ounceToGram(java.lang.String)oz->gm
ounceToPound(java.lang.String)oz->lb
poundToOunce(java.lang.String)lb->oz
standardToJulianDate(java.lang.String)standard->julian


Constructor Summary
HL7UtilityFunctions()
           
 
Method Summary
 java.lang.String calcSurfaceBSA(java.lang.String height, java.lang.String weight)
          Calculates the surface area of a human body in square meters, based on an individual's height, in centimeters, and weight, in kilograms.
 java.lang.String calcSurfaceGG(java.lang.String height, java.lang.String weight)
          Calculates the surface area of a human body using the Gehan-George formula.
 java.lang.String centimeterToInch(java.lang.String centimeter)
          Converts a number from centimeters to inches.
 java.lang.String degCToDegF(java.lang.String celcius)
          Converts a temperature from Celsius to Fahrenheit.
 java.lang.String degFToDegC(java.lang.String fahrenheit)
          Converts a temperature from Fahrenheit to Celsius.
 int diffTwoDates(java.lang.String date1, java.lang.String date2)
          Determines the number of days between two standard dates.
 java.lang.String get2SSN(java.lang.String ssn)
          Parses the specified social security number and returns the second group of digits.
 java.lang.String get3SSN(java.lang.String ssn)
          Parses the specified social security number and returns the first group of digits.
 java.lang.String get4SSN(java.lang.String ssn)
          Parses the specified social security number and returns the third group of digits.
 java.lang.String getApartment(java.lang.String address)
          Returns the apartment information from a string formatted as ADDRESS, APARTMENT, that is, everything after the comma.
 java.lang.String getCity(java.lang.String address)
          Returns the city field from the string formatted as CITY, STATE ZIP.
 java.lang.String getFirstName(java.lang.String name)
          Returns the first name in a string formatted as "LAST, FIRST MIDDLE"; that is everything after the first comma and before the next space.
 java.lang.String getLastName(java.lang.String name)
          Returns the last name in a string formatted as "LAST, FIRST MIDDLE"; that is everything before the comma.
 java.lang.String getMiddleName(java.lang.String name)
          Returns the middle name in a string formatted as "LAST, FIRST MIDDLE"; that is everything following the space after the first name.
 java.lang.String getState(java.lang.String address)
          Returns the state field from the string formatted as CITY, STATE ZIP.
 java.lang.String getStreetAddress(java.lang.String address)
          Returns the address from a string formatted as ADDRESS, APARTMENT, that is everything before the comma.
 java.lang.String getTimeStamp(java.lang.String format)
          SYNOPSIS: Returns the system time of the host machine in the form of format.
 java.lang.String getZipCode(java.lang.String address)
          Returns the zip code field from the string formatted as CITY, STATE ZIP.
 java.lang.String inchToCentimeter(java.lang.String inch)
          Converts a number from inches to centimeters.
 boolean isLeapYear(java.lang.String year)
          Determines if the year represents a leap year.
 boolean isValidDate(java.lang.String date)
          This function will verify the date for being valid.
 boolean isValidJulianDate(java.lang.String date)
          Determines if the seven-digit date provided in the call is a valid Julian date.
 boolean isValidPhoneNumber(java.lang.String number)
          Tests the supplied number to determine if it is a valid phone number A valid phone number is a string of the form NN (NNN) NNN-NNNN, where the first two groups of characters (country code and area code) are both optional, and there can be any number of spaces between the three character groups.
 boolean isValidSSN(java.lang.String ssn)
          Tests the supplied number to determine if it is a valid social security number.
 boolean isValidTimeStamp(java.lang.String timestamp)
          Tests the supplied number to determine if it is a valid timestamp.
 java.lang.String julianToStandardDate(java.lang.String julian)
          Converts a Julian date to a standard date in the form YYYYMDD.
static void main(java.lang.String[] args)
           
 java.lang.String ounceToGram(java.lang.String ounce)
          Converts a number which represents weight in ounces to grams.
 java.lang.String ounceToPound(java.lang.String ounce)
          Converts a weight in ounces to pounds.
 java.lang.String poundToOunce(java.lang.String pound)
          Converts a number expressed as weight in pounds number and converts this number from pounds to ounces.
 java.lang.String standardToJulianDate(java.lang.String std)
          Converts a standard date, in the format YYYYMMDD, to a Julian date.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HL7UtilityFunctions

public HL7UtilityFunctions()
Method Detail

main

public static void main(java.lang.String[] args)

calcSurfaceBSA

public java.lang.String calcSurfaceBSA(java.lang.String height,
                                       java.lang.String weight)
                                throws java.lang.NumberFormatException
Calculates the surface area of a human body in square meters, based on an individual's height, in centimeters, and weight, in kilograms. The formula for determining the body surface area is: bsa = 0.024265 * (weight) exp 0.5378 * (height) exp 0.3964. These calculations are generally performed on newborn babies for determining proper medication doses.

 Example
      calcSurfaceBSA(144.0, 100) => 2.0708812096829
 

Parameters:
height - Height of the individual in centimeters.
weight - Weight of the individual in kilograms.
Returns:
String - Returns the calculated body surface area in square meters.
Throws:
NumberFormatException
Throws:
java.lang.NumberFormatException

calcSurfaceGG

public java.lang.String calcSurfaceGG(java.lang.String height,
                                      java.lang.String weight)
                               throws java.lang.NumberFormatException
Calculates the surface area of a human body using the Gehan-George formula. The function takes the height of an individual in centimeters and the weight in kilograms and uses the formula ln (bsa) = -3.75080 + 0.42246 ln (height) + 0.51456 ln (weight), where ln is the loge (natural log), to calculate the body surface area in square meters. These calculations are generally performed on newborn babies for determining proper medication doses.

 Example
     calcSurfaceGG(12, 12) => 0.24113634200082
 

Parameters:
height - Height of the individual in centimeters.
weight - Weight of the individual in kilograms.
Returns:
String - Returns the calculated body surface area in square meters.
Throws:
NumberFormatException
Throws:
java.lang.NumberFormatException

centimeterToInch

public java.lang.String centimeterToInch(java.lang.String centimeter)
                                  throws java.lang.NumberFormatException
Converts a number from centimeters to inches.

 Examples
 centimeterToInch(2.54) => 1.0
 centimeterToInch(5.08) => 2.0
 

Parameters:
centimeter - Number of centimeters.
Returns:
String - Returns the number of inches resulting from the conversion.
Throws:
NumberFormatException
Throws:
java.lang.NumberFormatException

degCToDegF

public java.lang.String degCToDegF(java.lang.String celcius)
                            throws java.lang.NumberFormatException
Converts a temperature from Celsius to Fahrenheit.

 Examples
 degCToDegF(100) => 212.0
 degCToDegF(0.0) => 32.0
 

Parameters:
celcius - Degrees in Celcius.
Returns:
String - Returns a number representing the temperature, in Fahrenheit, resulting from the conversion.
Throws:
NumberFormatException
Throws:
java.lang.NumberFormatException

degFToDegC

public java.lang.String degFToDegC(java.lang.String fahrenheit)
                            throws java.lang.NumberFormatException
Converts a temperature from Fahrenheit to Celsius.

 Examples
 degFToDegC(212.0) => 100.0
 degFToDegC(32.0) => 0.0
 

Parameters:
fahrenheit - Temperature in degrees Fahrenheit.
Returns:
String - Returns a number representing the temperature, in degrees Celsius, resulting from the conversion.
Throws:
NumberFormatException
Throws:
java.lang.NumberFormatException

diffTwoDates

public int diffTwoDates(java.lang.String date1,
                        java.lang.String date2)
                 throws java.lang.Exception
Determines the number of days between two standard dates. The function converts the standard dates into a Julian form and subtracts the second date from the first. If the second date is later than the first, the result will be negative.

 Examples
     diffTwoDates("19960602", "19960225") => 98
     diffTwoDates("19960101", "19970101") => -366
 

Parameters:
date1 - First date in format YYYYMMDD.
date2 - Second date in format YYYYMMDD.
Returns:
int - Indicates the number of days between the two user-specified standard dates. The result may be positive or negative.
Throws:
Exception
Throws:
java.lang.Exception

get2SSN

public java.lang.String get2SSN(java.lang.String ssn)
Parses the specified social security number and returns the second group of digits.

 Example
     get2SSN("123-45-6789") > "45"
 

Parameters:
ssn - Social security number. A valid ssn string consists of nine digits with a hyphen following the third and fifth digits.
Returns:
String - Returns the second group of digits in a social security number.
Throws:
None.

get3SSN

public java.lang.String get3SSN(java.lang.String ssn)
Parses the specified social security number and returns the first group of digits.

 Example
     get3SSN("123-45-6789") => "123"
 

Parameters:
ssn - Social security number. A valid ssn string consists of nine digits with a hyphen following the third and fifth digits.
Returns:
String - Returns the first group of digits in a social security number.
Throws:
None.

get4SSN

public java.lang.String get4SSN(java.lang.String ssn)
Parses the specified social security number and returns the third group of digits.

 Example
     get4SSN("123-45-6789") => "6789"
 

Parameters:
ssn - Social security number. A valid ssn string consists of nine digits with a hyphen following the third and fifth digits.
Returns:
String - Returns the third group of digits in a social security number.
Throws:
None.

getApartment

public java.lang.String getApartment(java.lang.String address)
Returns the apartment information from a string formatted as ADDRESS, APARTMENT, that is, everything after the comma. Does not check the validity of the string, only that a comma exists within it.

 Examples
     getApartment("12 Main St., Apt. 22") => "Apt. 22"
     getApartment("345 Main St., #7") => "#7"
     getApartment("345 Elm Ave. #7") => "null"
 

Parameters:
address - Street address.
Returns:
String - Returns a string containing the apartment information from a string formatted as ADDRESS, APARTMENT, that is, everything after the comma.
Throws:
None.

getCity

public java.lang.String getCity(java.lang.String address)
Returns the city field from the string formatted as CITY, STATE ZIP. Does not check the validity of the string, only that a comma exists within it.

 Examples
     getCity("Arcadia, CA 91066") => "Arcadia"
     getCity("North Hills CA 91324") => NULL
 

Parameters:
address - Address formatted as CITY, STATE ZIP.
Returns:
String - Returns a string containing the city field from the string formatted as CITY, STATE ZIP. Null if no city can be found.
Throws:
None.

getFirstName

public java.lang.String getFirstName(java.lang.String name)
Returns the first name in a string formatted as "LAST, FIRST MIDDLE"; that is everything after the first comma and before the next space. Does not check the validity of the string, only that a comma exists within it.

 Example
     (getFirstName( "Astor, John Jacob") => "John"
 

Parameters:
name - Personal name.
Returns:
String - Returns the first name in a string formatted as LAST, FIRST MIDDLE; that is, everything after the first comma and before the next space. Null if no first name can be found.
Throws:
None.

getLastName

public java.lang.String getLastName(java.lang.String name)
Returns the last name in a string formatted as "LAST, FIRST MIDDLE"; that is everything before the comma. Does not check the validity of the string, only that a comma exists within it.

 Example
     getLastName( "Astor, John Jacob") => "Astor"
 

Parameters:
name - Personal name.
Returns:
String - Returns the last name in a string formatted as "LAST, FIRST MIDDLE"; that is, everything before the comma. Null if no last name could be found.
Throws:
None.

getMiddleName

public java.lang.String getMiddleName(java.lang.String name)
Returns the middle name in a string formatted as "LAST, FIRST MIDDLE"; that is everything following the space after the first name. Does not check the validity of the string, only that a comma exists within it. If the data specifies a dual first name, for example Mary Jo Elizabeth Smith, this function will interpret "Jo" as the middle name.

 Example
     getMiddleName("Astor, John Jacob") => "Jacob"
 

Parameters:
name - Personal name.
Returns:
String - Returns the middle name in a string formatted as "LAST, FIRST MIDDLE"; that is, everything after the space. Null if no middle name is found.
Throws:
None.

getState

public java.lang.String getState(java.lang.String address)
Returns the state field from the string formatted as CITY, STATE ZIP. Does not check the validity of the string, only that a comma exists within it.

 Examples
     getState("Arcadia, CA 91066") => "CA"
     getState("North Hills CA 91324") => NULL
 

Parameters:
address - Address in the form CITY, STATE, ZIP.
Returns:
String - Returns the state field from the string formatted as CITY, STATE ZIP. Null if no state is found.
Throws:
None.

getStreetAddress

public java.lang.String getStreetAddress(java.lang.String address)
Returns the address from a string formatted as ADDRESS, APARTMENT, that is everything before the comma. If no comma is specified, it returns the entire string.

 Examples
     getStreetAddress("12 Main St., Apt. 22") => "12 Main St."
     getStreetAddress("345 Elm Ave., #7") => "345 Elm Ave."
     getStreetAddress("345 Elm Ave. #7") => "345 Elm Ave. #7"
 

Parameters:
address - Street address.
Returns:
String - Returns the street address from the supplied string, that is, everything before the first comma. If the string does not contain a comma, the function returns. the entire string.
Throws:
None.

getTimeStamp

public java.lang.String getTimeStamp(java.lang.String format)
                              throws java.lang.IllegalArgumentException
SYNOPSIS: Returns the system time of the host machine in the form of format. If format is null or empty, empty string will be returned. Format is based on java.text.SimpleDateFormat. Generates a user-specified timestamp and returns it as a string.

 Letter   Date or Time Component  Presentation        Examples
 G        Era designator          Text                AD
 y        Year                    Year                1996; 96
 M        Month in year           Month               July; Jul; 07
 w        Week in year            Number              27
 W        Week in month           Number              2
 D        Day in year             Number              189
 d        Day in month            Number              10
 F        Day of week in month    Number              2
 E        Day in week             Text                Tuesday; Tue
 a        Am/pm marker            Text                PM
 H        Hour in day (0-23)      Number              0
 k        Hour in day (1-24)      Number              24
 K        Hour in am/pm (0-11)    Number              0
 h        Hour in am/pm (1-12)    Number              12
 m        Minute in hour          Number              30
 s        Second in minute        Number              55
 S        Millisecond             Number              978
 z        Time zone               General time zone   Pacific Standard Time; PST; GMT-08:00
 Z        Time zone               RFC 822 time zone   -0800
 

 Examples
  For
     getTimeStamp("yyyy.MM.dd G 'at' HH:mm:ss z") => "2004.02.24 AD at 16:39:34 PST"
     getTimeStamp("EEE, MMM d, ''yy") => "Tue, Feb 24, '04"
     getTimeStamp("h:mm a") => "4:39PM"
     getTimeStamp("xyzzy") => EXCEPTION [Illegal pattern character 'x']
 

Parameters:
format - The specification of the output format. The syntax for the format instruction is documented in Format Specification on page 34.
Returns:
String - Returns the system time of the host machine.
Throws:
IllegalArgumentException
Throws:
java.lang.IllegalArgumentException
See Also:
SimpleDateFormat

getZipCode

public java.lang.String getZipCode(java.lang.String address)
Returns the zip code field from the string formatted as CITY, STATE ZIP. Does not check the validity of the string, only that a comma exists within it.

 Example
     getZipCode("Arcadia, CA 91066") => "91066"
 

Parameters:
address - Address in the form CITY, STATE, ZIP.
Returns:
String - Returns the zip code field from the supplied string formatted as CITY, STATE ZIP. NULL if zipcode does not exist.
Throws:
None.

inchToCentimeter

public java.lang.String inchToCentimeter(java.lang.String inch)
                                  throws java.lang.NumberFormatException
Converts a number from inches to centimeters.

 Examples
     inchToCentimeter(10.0) => 25.4
     inchToCentimeter(39.4) => 100.076
 

Parameters:
inch - Number of inches.
Returns:
String - Returns a number representing the number of centimeters resulting from the conversion.
Throws:
NumberFormatException
Throws:
java.lang.NumberFormatException

isLeapYear

public boolean isLeapYear(java.lang.String year)
Determines if the year represents a leap year. The year may be specified as either an integer or as a string value.

 Examples
     isLeapYear(1990) => false
     isLeapYear(1996) => true
 

Parameters:
year - A four-digit integer representing a year.
Returns:
Boolean - Returns true if the integer does represent a leap year; otherwise, returns true.
Throws:
None.

isValidDate

public boolean isValidDate(java.lang.String date)
This function will verify the date for being valid. It will check for the number of days in a month, and the year being leapier. If the number of months exceeds 12 false will be returned, if the number of days will exceed its maximum number false will be returned. Other- wise if the date is valid true will be returned. Format: YYYYMMDD

 Examples
          isValidDate("19960322")  =>  true
          isValidDate("19893800")  =>  false
          isValidDate("000415")    =>  true
          isValidDate("010229")    =>  false
 

Parameters:
date - Valid date in the form YYYYMMDD.
Returns:
Boolean - Returns true for a valid formatted date, otherwise false.
Throws:
None.

isValidJulianDate

public boolean isValidJulianDate(java.lang.String date)
Determines if the seven-digit date provided in the call is a valid Julian date.

 Examples
     isValidJulianDate("2444239") => true
     isValidJulianDate("244239") => false
 

Parameters:
date - Seven-digit Julian date.
Returns:
Boolean - Returns true if the string is a valid Julian date; otherwise, returns a false.
Throws:
None.

isValidPhoneNumber

public boolean isValidPhoneNumber(java.lang.String number)
Tests the supplied number to determine if it is a valid phone number A valid phone number is a string of the form NN (NNN) NNN-NNNN, where the first two groups of characters (country code and area code) are both optional, and there can be any number of spaces between the three character groups. Parenthesis are required when entering an area code.

 Examples
      isValidPhoneNumber("44(326)323-5909") => true
      isValidPhoneNumber("(818)445-7000") => true
      isValidPhoneNumber("123-45-6789") => false
      isValidPhoneNumber("91066") => false
 

Parameters:
number - Number to test.
Returns:
Boolean - true if the supplied number is a phone number. Otherwise, it returns false.
Throws:
None.

isValidSSN

public boolean isValidSSN(java.lang.String ssn)
                   throws java.util.regex.PatternSyntaxException
Tests the supplied number to determine if it is a valid social security number. A valid social security number is a string formatted as DDD-DD-DDDD, where all the Ds are digits. Dashes are required between the three groups making up the social security number.

 Examples
     isValidSSN("123-45-6789") => true
     isValidSSN("91066") => false
 

Parameters:
ssn - The Social Security Number to test.
Returns:
Boolean - Returns true if the supplied number is a social security number. Otherwise, it returns false.
Throws:
java.util.regex.PatternSyntaxException

isValidTimeStamp

public boolean isValidTimeStamp(java.lang.String timestamp)
Tests the supplied number to determine if it is a valid timestamp. A valid timestamp is a string formatted as HHMM or HHMMSS or HHMMSSD or HHMMSSDD, where all the HH are hours, MM is minutes, SS is seconds, and DD is the two digit day of the month.

 Examples
     isValidTimeStamp("1234") => true
     isValidTimeStamp("134532") => true
     isValidTimeStamp("2560") => false
 

Parameters:
timestamp - valid timestamp (HHMM or HHMMSS or HHMMSSD or HHMMSSDD).
Returns:
Boolean - Returns true if S is a valid timestamp (HHMM or HHMMSS or HHMMSSD or HHMMSSDD) Returns false if not a valid timestamp.
Throws:
None.

julianToStandardDate

public java.lang.String julianToStandardDate(java.lang.String julian)
                                      throws java.lang.Exception
Converts a Julian date to a standard date in the form YYYYMDD. Based on Fliegel, H. F. and van Flandern, T. C. (1968). Communications of the ACM, Vol. 11, No. 10 (October, 1968).

See also http://aa.usno.navy.mil/faq/docs/JD_Formula.html

 o Years are positive or negative numbers.
 o Julian day number 0 corresponds to 11/24/4713 BC in the Gregorian Calendar.
 o These calculations are only valid in the Gregorian Calendar.
 o julianToStandardDate is only valid with Julian dates corresponding to
   03/01/4900 BC and onward (-68569 Julian).
 

Examples julianToStandardDate("2451449") => "19990927" julianToStandardDate("2436078") => "19570827"

Parameters:
julian - Julian date.
Returns:
String - A standard date in the form YYYYMMDD. null if date is not supported.
Throws:
None.
Throws:
java.lang.Exception

ounceToGram

public java.lang.String ounceToGram(java.lang.String ounce)
                             throws java.lang.NumberFormatException
Converts a number which represents weight in ounces to grams.

 Examples
     ounceToGram(0.035) => .99225
     ounceToGram(1.0) => 28.35
 

Parameters:
ounce - Weight in ounces.
Returns:
String - Returns a number representing weight in grams resulting from the conversion.
Throws:
NumberFormatException
Throws:
java.lang.NumberFormatException

ounceToPound

public java.lang.String ounceToPound(java.lang.String ounce)
                              throws java.lang.NumberFormatException
Converts a weight in ounces to pounds.

 Examples
     ounceToPound(32) => 2.0
     ounceToPound(100) => 6.25
 

Parameters:
ounce - Weight in ounces.
Returns:
String - Returns a number representing the weight in pounds resulting from the conversion.
Throws:
NumberFormatException
Throws:
java.lang.NumberFormatException

poundToOunce

public java.lang.String poundToOunce(java.lang.String pound)
                              throws java.lang.NumberFormatException
Converts a number expressed as weight in pounds number and converts this number from pounds to ounces.

 Examples
     poundToOunce(2.0) => 32.0
     poundToOunce(6.25) => 100.0
 

Parameters:
pound - Weight in pounds.
Returns:
String - Returns a number representing the weight in ounces resulting from the conversion.
Throws:
NumberFormatException
Throws:
java.lang.NumberFormatException

standardToJulianDate

public java.lang.String standardToJulianDate(java.lang.String std)
                                      throws java.lang.Exception
Converts a standard date, in the format YYYYMMDD, to a Julian date. Valid for any Gregorian calendar date producing a Julian date greater than zero. Based on Fliegel, H. F. and van Flandern, T. C. (1968). Communications of the ACM, Vol. 11, No. 10 (October, 1968).

See also http://aa.usno.navy.mil/faq/docs/JD_Formula.html

 o Years are positive or negative numbers.
 o Julian day number 0 corresponds to 11/24/4713 BC in the Gregorian Calendar.
 o These calculations are only valid in the Gregorian Calendar.
 o standardToJulianDate is only valid with standard date of 03/01/4800 BC and onward.
 

Examples standardToJulianDate("19480115") => "2432556" standardToJulianDate("18980215") => "2414336"

Parameters:
std - A standard date in the form YYYYMMDD.
Returns:
String - Returns the Julian date. null if date is not supported.
Throws:
Exception
Throws:
java.lang.Exception

Sun Message Library for HL7