/* * 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("@(#) HL7Message.cc (Gunther Schadow) 12/19/96"); #pragma implementation #include "HL7Message.h" #include "xios.h" #include "misc.h" #include "logfile.h" #include "exception.h" #include "ParseTrace.h" void HL7Message::setMesHea(const MSHseg& x) { MesHea = x; MesHea.setMesType(ZM(type())); } void HL7Message::unset() { LOGDEBUG("unset"); MesHea.unset(); SegStruc::unset(); MesHea.setMesType(ZM(type())); } bool HL7Message::commit() { MesHea.setMesType(ZM(type())); // because we set the mesage type MesHea.commit(); // the header will always exist SegStruc::commit(); // and even though the body might be void set(); // the message will never be missed! return TRUE; } result HL7Message::input(istream& is) { SegStrucTracer tracer(type()); if(isdebug(is)) FATAL("can't read from debug stream"); if(!istouched(is)) { LOGDEBUG("untouched stream"); streammarker spos(is.rdbuf()); if( MesHea.input(is) != SUCCESS ) { unset(); is.rdbuf()->seekmark(spos); record_parse_error("could not read MSH"); EPARSE("could not read MSH"); return FAIL; } if(!MesHea.getMesType().ispresent() || MesHea.getMesType().isnull()) { record_parse_error("message type is not present or null"); EPARSE("message type is not present or null"); return FAIL; } UniMesIdCode::Value umid = UniMesId(MesHea.getMesType()); if(umid==UniMesIdCode::invalid) { record_parse_error("invalid message type"); EPARSE("invalid message type"); return FAIL; } if( umid != type() ) { record_parse_warning("unexpected message type %d", umid); LOGWARNING("unexpected message type %d", umid); unset(); is.rdbuf()->seekmark(spos); return FAIL; } tracer++; } else /* istouched(is) means that the MSH is read already */ { LOGDEBUG("touched stream"); untouch(is); } return SegStruc::input(is); } void HL7Message::output(ostream& os) const { if (ishl7er(os) || isastmer(os)) { LOGDEBUG("hl7/astm"); if(ispresent()) MesHea.output(os); } else { LOGDEBUG("debug"); os << DSBGR0 << (const char *)UniMesIdCode(type()) << "msg" << DSBGR1; if (ispresent()) os << DSFRST << MesHea; } SegStruc::output(os); }