/* * 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 as a simple block of text, assuming that * it is a single HL7 message. Send it to the service/host specified * on the command line. Receive any result message and analyze it for * error reports. The idea is to save CPU resources by not having to * parse the request message. */ #include #include #include #include #include #include #include #include #include #ifdef DEBUG # ifdef LOGLEVEL # undef LOGLEVEL # endif # define LOGLEVEL L_JUNK #else # ifndef LOGLEVEL # define LOGLEVEL L_MESG # endif #endif #ifdef HL7V21 # define CAval AAval #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; return 5; } log_init(argv[0], "/tmp/client.log", "F2I"); log_level(LOGLEVEL); LOGNOTICE("file-to-illp 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); // read message from file char *buf; msgin->gets(&buf, 0); // print request message to be sent xios cout_x(cout); if(!quiet) cout << buf << flush; // connect to server iosockinet *io = connect_illp(address, service); if(io == NULL) { cerr << "connection to " << address << ":" << service << " failed" << endl; return 4; } (*io) << buf << flush; (*io)->shutdown(sockbuf::shut_write); // initialize ANYmsg to allow any configured message ANYmsg any; any.allow(); if(receive_message(io, any) == SUCCESS) { if(any.type() == UniMesIdCode::ACKval) { ACKmsg &ack = (ACKmsg &)*any; switch(ack.MesAck.Ack) { case AckCode::AEval: case AckCode::CEval: cout << hl7er << any << flush; cerr << (const char *)ack.MesAck.Ack << ": " << (const char *)ack.MesAck.TextMes << endl; return 1; case AckCode::ARval: case AckCode::CRval: cout << hl7er << any << flush; cerr << (const char *)ack.MesAck.Ack << ": " << (const char *)ack.MesAck.TextMes << endl; return 2; } } } else { cerr << "couldn't receive reply message" << endl; return 3; } cout << hl7er << any << flush; return 0; }