/* * 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 "abl500.h" #include #include #include #include #include #include #include "exception.h" #include "logfile.h" #include "xios.h" #include "ASTMmsg.h" #include "ORUmsg.h" #include "ACKmsg.h" #include "results.h" #ifndef APPLICATION # define APPLICATION "ABL" #endif #ifndef FACILITY # define FACILITY NULL #endif #ifndef REC_APP # define REC_APP "CLI" #endif #ifndef REC_FAC # define REC_FAC "060_IOP" #endif const char *App = APPLICATION; const char *Fac = FACILITY; const char *RecApp = REC_APP; const char *RecFac = REC_FAC; main(int argc, char *argv[]) { init(); log_init(argv[0], "/tmp/abl500.log", (char *)App); if(argc > 1 && strcmp(argv[1],"-d") == 0) { log_level(L_JUNK); argv++; argc--; } else { log_level(L_MESG); } xios _xin(cin); astmer(cin); LOGINFO("ABL-HL7 interface started"); ASTMmsg astmrep; ORUmsg hl7rep; ACKmsg hl7ack; astmrep.input(cin); astm2hl7(astmrep, hl7rep); if(! hl7rep.GRPgroup[0].PIDgroup.PatVisit.commit()) // i.e. no patient { if(hl7rep.GRPgroup[0].PIDgroup.PatIde.AltPatId.ispresent()) LOGWARNING("patient id %s could not be resolved, message not sent", (const char *)hl7rep.GRPgroup[0].PIDgroup.PatIde.AltPatId); else LOGWARNING("patient id could not be resolved, message not sent"); } else { // if the PatVisit segment is present, we send the message on to // the queue. // the transaction id is used for the journal and acklog files as well // construct a unique message id strstream umid; umid << time(NULL) % ( 3600 * 24 * 30 * 12 /* s/year */ ); umid.form("%05u", (u_int)getpid()); umid << ends; strstream mfs; mfs << PGSPOOL << '/' << App << '/' << Fac << '/' << "msg" << umid.str() << ".dat" << ends; strstream lcks; lcks << PGSPOOL << '/' << App << '/' << Fac << '/' << "msg" << umid.str() << ".lck" << ends; // update MSH segment strstream mci; mci << "R" << umid.str() << ends; hl7rep.MesHea.MesConTrolId = mci.str(); hl7rep.MesHea.SenApp = App; hl7rep.MesHea.SenFac = Fac; hl7rep.MesHea.RecApp = RecApp; hl7rep.MesHea.RecFac = RecFac; stamp(hl7rep.MesHea.DateTimeOfMes); hl7rep.MesHea.ProId = ProIdCode::Pro; hl7rep.MesHea.VerId = VerIdCode::_2_2val; hl7rep.commit(); fstream mout(mfs.str(), ios::out); // this is the message file fstream lout(lcks.str(), ios::out); // and this is the lock file lout.close(); umid.freeze(0); mci.freeze(0); mfs.freeze(0); xios xmout(mout); // put the request to the queue mout << hl7er << hl7rep << flush; mout.close(); unlink(lcks.str()); // remove lock lcks.freeze(0); } return SUCCESS; }