/* * 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. */ /* * Transact with FSI Server / LLP Driver resp. */ #include "cvgateway.h" #include "carevue.h" #include "illp-session.h" #include "logfile.h" #include "exception.h" #include "HL7Message.h" #include "ACKmsg.h" #include "xios.h" #include #include #include HL7Message *forward_message(HL7Message &request) { STtyp SenApp = request.MesHea.SenApp; STtyp SenFac = request.MesHea.SenFac; STtyp RqMesConId = request.MesHea.MesConTrolId; /* * Update Message Header */ request.MesHea.SenApp = App; request.MesHea.SenFac = Fac; //request.MesHea.RecApp = RecApp; request.MesHea.RecFac = RecFac; stamp(request.MesHea.DateTimeOfMes); // the transaction id is used for the journal and acklog files as well strstream s; s.form("REQ%05u", (u_int)getpid()) << '\0'; strstream js; js << PGLOG << '/' << App << '/' << Fac << '/' << s.str() << '\0'; strstream as; as << PGLOG << '/' << App << '/' << Fac << '/'; as.form("ACK%05u", (u_int)getpid()) << '\0'; fstream jout(js.str(), ios::out); // this is the journal file fstream aout(as.str(), ios::out); // and this is the acklog file xios xjout(jout), xaout(aout); request.MesHea.MesConTrolId = s.str(); request.MesHea.ProId = ProIdCode::Pro; request.MesHea.VerId = VerIdCode::_2_2val; request.commit(); s.freeze(0); js.freeze(0); as.freeze(0); // the strings may be deleted Strbase::do_8th_bit_protection = false; // log outgoing request message to journal jout << hl7er << request << endl; ANYmsg any; any.forbid(); any.allow(UniMesIdCode::ACKval); result txn_result = chat_illp(fsi_host, fsi_service, request, any); // log result message from carevue aout << hl7er << any << endl; Strbase::do_8th_bit_protection = true; ACKmsg *ackp = (ACKmsg *)any.msg(); // this was again a contravariance violation, however, any was allowed // to read an ACKmsg only // we need an ACKmsg anyway ACKmsg &ack = ackp != NULL ? *ackp : *new ACKmsg; if(txn_result == FAIL) if(ack.MesAck.MesConTrolId != request.MesHea.MesConTrolId) { ZEtyp &err = ack.Error.ErrorCodeAndLoc.prepend(); err.CodeIdeError.Text = "message control ids do not match: "; err.CodeIdeError.Text += ack.MesAck.MesConTrolId; err.CodeIdeError.Text += " "; err.CodeIdeError.Text += request.MesHea.MesConTrolId; ack.MesAck.Ack = AckCode::ARval; ack.MesAck.TextMes = "message control ids do not match: "; } else if(ack.MesAck.Ack != AckCode::AAval && ack.MesAck.Ack != AckCode::CAval) { // AE from CareVue is generally mapped to AR if(ack.MesAck.Ack == AckCode::AEval) { // except for: // an AE ERRor 2 just because lab results have been sent twice if(ack.Error.ErrorCodeAndLoc[0].CodeIdeError.Ide == "2" && request.type() == UniMesIdCode::ORUval) ack.MesAck.Ack = AckCode::AAval; else if(strstr((const char *)ack.MesAck.TextMes, "TRY AGAIN LATER")) { runcmd( PGBIN "/restartfsiclient" ); ack.MesAck.Ack = AckCode::ARval; } } } ack.MesAck.MesConTrolId = RqMesConId; ack.MesHea.RecApp = SenApp; ack.MesHea.RecFac = SenFac; ack.MesHea.SenApp = App; ack.MesHea.SenFac = Fac; stamp(ack.MesHea.DateTimeOfMes); { strstream s; s.form("ACK%05u", (u_int)getpid()) << '\0'; ack.MesHea.MesConTrolId = s.str(); s.freeze(0); } ack.MesHea.ProId = ProIdCode::Pro; ack.MesHea.VerId = VerIdCode::_2_2val; ack.commit(); return &ack; } HL7Message *make_ack(HL7Message &request, AckCode::Value ac, const char *err) { ACKmsg &ack = *new ACKmsg; STtyp SenApp = request.MesHea.SenApp; STtyp SenFac = request.MesHea.SenFac; STtyp RqMesConId = request.MesHea.MesConTrolId; ack.MesAck.Ack = ac; ack.MesAck.TextMes = err; ack.MesAck.MesConTrolId = RqMesConId; ack.MesHea.RecApp = SenApp; ack.MesHea.RecFac = SenFac; ack.MesHea.SenApp = App; ack.MesHea.SenFac = Fac; ack.MesHea.ProId = ProIdCode::Pro; ack.MesHea.VerId = VerIdCode::_2_2val; stamp(ack.MesHea.DateTimeOfMes); { strstream s; s.form("ACK%05u", (u_int)getpid()) << '\0'; ack.MesHea.MesConTrolId = s.str(); s.freeze(0); } ack.commit(); return &ack; }