/* * Copyright (c) 1995, 1996 Gunther Schadow. All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "pg_config.h" IDENT("@(#) DTtyp.cc (Gunther Schadow) 12/19/96"); #pragma implementation #include "DTtyp.h" #include "logfile.h" #include "exception.h" #include "xios.h" DTtyp::DTtyp(int year, int month, int day) : Timebase(DataTypeCode::DTval) { set(_day, day, DayMin, DayMax); set(_month, month, MonthMin, MonthMax); set(_year, year, YearMin, YearMax); } DTtyp::DTtyp() : Timebase(DataTypeCode::DTval) { _year = YearMin; _month = MonthMin; _day = DayMin; } int DTtyp::getYear() const { if(ispresent() && ! isnull()) return _year; else FATAL("access into non-present object"); } int DTtyp::getMonth() const { if(ispresent() && ! isnull()) return _month; else FATAL("access into non-present object"); } int DTtyp::getDay() const { if(ispresent() && ! isnull()) return _day; else FATAL("access into non-present object"); } void DTtyp::unset() { _year = YearMin; _month = MonthMin; _day = DayMin; Timebase::unset(); } void DTtyp::nullify() { _year = YearMin; _month = MonthMin; _day = DayMin; Timebase::nullify(); } result DTtyp::input(istream& is) { if(isdebug(is)) FATAL("can't read from debug stream"); LOGDEBUG("hl7/astm"); if(!no_value(is)) { if( input_number(_year, is, 4, YearMin, YearMax) == FAIL || input_number(_month, is, 2, MonthMin, MonthMax) == FAIL || input_number(_day, is, 2, DayMin, DayMax) == FAIL ) TIMEBASE_SYNTAX_ERROR(is); } return SUCCESS; } void DTtyp::output(ostream& os) const { if(ishl7er(os) || isastmer(os)) { LOGDEBUG("hl7/astm"); if (ispresent()) if (isnull()) os << NULLVAL; else os.form("%04d%02d%02d",_year,_month,_day); } else { LOGDEBUG("debug"); os << DSBGR0 "DTtyp" DSBGR1; if (!ispresent()) os << DSNOPS; else { if (isnull()) os << DSNULL; else { os << DSFRST << dec << DSBGR0 "Year" DSBGR1 DSFRST << _year << DSEGRP DSSEPR DSBGR0 "Month" DSBGR1 DSFRST << _month << DSEGRP DSSEPR DSBGR0 "Day" DSBGR1 DSFRST << _day << DSEGRP; } } os << DSEGRP; } }