|
From: Ian V. <Ian...@he...> - 2012-05-29 02:01:13
|
Last year I posted when I had a problem setting TS values using Date or Calendar, as per this code:
CommonTM tmbad = new CommonTM();
tmbad.setOffset(signedOffset);
tmbad.setValue(theCalendar);
System.out.println("Result of tmbad.setValue(theCalendar) = " + tmbad.getValue());
CommonTS ts = new CommonTS();
ts.setValue(theCalendar);
System.out.println("Result of ts.setValue(theCalendar) = " + ts.getValue());
ts.setValue(new Date());
System.out.println("Result of ts.setValue(new Date()) = " + ts.getValue());
For my time zone of GMT+10 the code threw this exception:
The GMT offset minute value of the TM datatype must be >=0 and <=59
ca.uhn.hl7v2.model.DataTypeException: The GMT offset minute value of the TM datatype must be >=0 and <=59
at ca.uhn.hl7v2.model.primitive.CommonTM.setOffset(CommonTM.java:457)
at ca.uhn.hl7v2.model.primitive.CommonTS.setOffset(CommonTS.java:362)
at ca.uhn.hl7v2.model.primitive.CommonTS.setValue(CommonTS.java:397)
at au.gov.qld.health.sit.hl7.CommonTSTesting.testCommonTS(CommonTSTesting.java:75)
I managed to work around it, but it came up again recently, and I took the time try some more things out and look at the source.
What I found:
>From the CommonTM source that downloads with the HAPI library 1.2
public void setValue(Calendar theCalendar) throws DataTypeException {
if (theCalendar == null) {
setValue((String)null);
return;
}
int hr = theCalendar.get(Calendar.HOUR_OF_DAY);
int min = theCalendar.get(Calendar.MINUTE);
float sec = theCalendar.get(Calendar.SECOND) + (theCalendar.get(Calendar.MILLISECOND) / 1000.0F);
setHourMinSecondPrecision(hr, min, sec);
int zoneOffset = (theCalendar.get(Calendar.ZONE_OFFSET)*100) / (1000 * 60 * 60);
setOffset(zoneOffset);
}
>From the CommonTM source that downloads from the source trunk
public void setValue(Calendar theCalendar) throws DataTypeException {
if (theCalendar == null) {
setValue((String)null);
return;
}
int hr = theCalendar.get(Calendar.HOUR_OF_DAY);
int min = theCalendar.get(Calendar.MINUTE);
float sec = theCalendar.get(Calendar.SECOND) + (theCalendar.get(Calendar.MILLISECOND) / 1000.0F);
setHourMinSecondPrecision(hr, min, sec);
int hourOffset= theCalendar.get(Calendar.ZONE_OFFSET) / (1000 * 60 * 60);
int minuteOffset = (theCalendar.get(Calendar.ZONE_OFFSET) / (1000 * 60)) % 60;
int zoneOffset = hourOffset * 100 + minuteOffset;
setOffset(zoneOffset);
}
>From the CommonTS source that downloads with the HAPI library 1.2
public void setValue(Calendar theCalendar) throws DataTypeException {
if (theCalendar == null) {
setValue((String)null);
return;
}
int yr = theCalendar.get(Calendar.YEAR);
int mnth = theCalendar.get(Calendar.MONTH) + 1;
int dy = theCalendar.get(Calendar.DATE);
int hr = theCalendar.get(Calendar.HOUR_OF_DAY);
int min = theCalendar.get(Calendar.MINUTE);
float sec = theCalendar.get(Calendar.SECOND) + (theCalendar.get(Calendar.MILLISECOND) / 1000.0F);
setDateSecondPrecision(yr, mnth, dy, hr, min, sec);
int zoneOffset = (theCalendar.get(Calendar.ZONE_OFFSET)*100) / (1000 * 60 * 60);
setOffset(zoneOffset);
}
>From the CommonTS source that downloads from the source trunk
public void setValue(Calendar theCalendar) throws DataTypeException {
if (theCalendar == null) {
setValue((String)null);
return;
}
int yr = theCalendar.get(Calendar.YEAR);
int mnth = theCalendar.get(Calendar.MONTH) + 1;
int dy = theCalendar.get(Calendar.DATE);
int hr = theCalendar.get(Calendar.HOUR_OF_DAY);
int min = theCalendar.get(Calendar.MINUTE);
float sec = theCalendar.get(Calendar.SECOND) + (theCalendar.get(Calendar.MILLISECOND) / 1000.0F);
setDateSecondPrecision(yr, mnth, dy, hr, min, sec);
// 3410095: care for integer overflow and timezones not at the full hour, e.g. India
int hourOffset= theCalendar.get(Calendar.ZONE_OFFSET) / (1000 * 60 * 60);
int minuteOffset = (theCalendar.get(Calendar.ZONE_OFFSET) / (1000 * 60)) % 60;
int zoneOffset = hourOffset * 100 + minuteOffset;
setOffset(zoneOffset);
}
So, what is in the distribution, and what is on the trunk differs.
The code on the trunk works. Version 2.0 beta distribution also works.
Since the beta isn't considered complete yet, I am not game to use it in production.
So my question is, how do I get the code that works into the distribution I am using?
Thanks
Ian
********************************************************************************
This email, including any attachments sent with it, is confidential and for the sole use of the intended recipient(s). This confidentiality is not waived or lost, if you receive it and you are not the intended recipient(s), or if it is transmitted/received in error.
Any unauthorised use, alteration, disclosure, distribution or review of this email is strictly prohibited. The information contained in this email, including any attachment sent with it, may be subject to a statutory duty of confidentiality if it relates to health service matters.
If you are not the intended recipient(s), or if you have received this email in error, you are asked to immediately notify the sender by telephone collect on Australia +61 1800 198 175 or by return email. You should also delete this email, and any copies, from your computer system network and destroy any hard copies produced.
If not an intended recipient of this email, you must not copy, distribute or take any action(s) that relies on it; any form of disclosure, modification, distribution and/or publication of this email is also prohibited.
Although Queensland Health takes all reasonable steps to ensure this email does not contain malicious software, Queensland Health does not accept responsibility for the consequences if any person's computer inadvertently suffers any disruption to services, loss of information, harm or is infected with a virus, other malicious computer programme or code that may occur as a consequence of receiving this email.
Unless stated otherwise, this email represents only the views of the sender and not the views of the Queensland Government.
**********************************************************************************
|