/* * 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. */ /* * Read a message from a file and send it to the service/host specified * on the command line. Receive any result message. This is a good example * for a HL7 client application using the ILLP. */ #include #include #include #include #include "hl7/ANYmsg.h" #include "hl7/illp-session.h" #include "xios.h" #include "logfile.h" #include "ParseTrace.h" #ifdef DEBUG # ifdef LOGLEVEL # undef LOGLEVEL # endif # define LOGLEVEL L_JUNK #else # ifndef LOGLEVEL # define LOGLEVEL L_MESG # endif #endif main(int argc, char *argv[]) { bool quiet = FALSE; const char *message; const char *service; const char *address; // read arguments if(argc == 5 && strcmp(argv[1],"-q") == 0) { quiet = TRUE; message = argv[2]; service = argv[3]; address = argv[4]; } else if(argc == 4) { message = argv[1]; service = argv[2]; address = argv[3]; } else { cerr << "usage: " << argv[0] << " [-q] file service host" << endl; exit(1); } log_init(argv[0], "client.log", "test"); log_level(LOGLEVEL); LOGNOTICE("HL7TEST client started by user %u on file %s", (u_int)getuid(), message); // initialize input file istream *msgin; if(strcmp(message,"-") == 0) msgin = &cin; else msgin = new ifstream(message); xios _xin(*msgin); hl7er(*msgin); // initialize ANYmsg to allow any configured message ANYmsg any; any.allow(); // read message from file if(any.input(*msgin) != SUCCESS) { cerr << "couldn't read message from " << message << endl; exit(1); } // update MSH segment stamp(any->MesHea.DateTimeOfMes); any->MesHea.ProId = ProIdCode::Pro; #ifdef HL7V21 any->MesHea.VerId = 2.1; #else any->MesHea.VerId = VerIdCode::_2_2val; #endif strstream s; s.form("REQ%05u",(u_int)getpid()); s << '\0'; any->MesHea.MesConTrolId = s.str(); s.freeze(0); any->commit(); // print request message to be sent xios cout_x(cout); if(!quiet) cout << hl7er << any << flush; // do server transaction if(!quiet) cout << "trying " << address << ", " << service << endl; any.freeze(); // otherwhise we cannot say `.., any, any ..' if(chat_illp(address, service, any, any) == FAIL) { if(any.ispresent()) cout << hl7er << any << flush; return 1; } // print result message cout << hl7er << any << flush; return 0; }