/* * 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. */ /* * Send an NMD message out to the service/host specified on the command * line. Receive an ACK message. */ #include #include #include #include "hl7/ANYmsg.h" #include "hl7/NMDmsg.h" #include "hl7/illp-session.h" #include "xios.h" #include "logfile.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 *service; const char *address; const char *RecApp; const char *RecFac; // read arguments if(argc == 6 && strcmp(argv[1],"-q") == 0) { quiet = TRUE; service = argv[2]; address = argv[3]; RecApp = argv[4]; RecFac = argv[5]; } else if(argc == 5) { service = argv[1]; address = argv[2]; RecApp = argv[3]; RecFac = argv[4]; } else { cerr << "usage: " << argv[0] << " [-q] service host RecApp RecFac" << endl; exit(1); } log_init(argv[0], "client.log", "test"); log_level(LOGLEVEL); LOGNOTICE("NMD client startup"); /* * Assemble NMD message * * note how we don't need nmd.commit() since we never write into * the nmd message via assignment operator */ NMDmsg nmd; // MSH segment MSHseg msh; msh.setSenApp("NMDCLIENT"); msh.setRecApp(RecApp); msh.setRecFac(RecFac); TStyp ts; ts.set(); msh.setDateTimeOfMes(ts); strstream s; s.form("REQ%05u", (u_int)getpid()); s << '\0'; msh.setMesConTrolId(s.str()); s.freeze(0); msh.setProId(ProIdCode::Pro); #ifdef HL7V21 msh.setVerId(2.1); #else msh.setVerId(VerIdCode::_2_2val); #endif // NCK group segment repstruc rgrp; #ifdef HL7V21 NCKseg nck; nck.setSysDateTime(ts); NSCseg nsc; nsc.setNetChaType("SU"); rgrp[0].setSysClock(nck); rgrp[0].setStatusCha(nsc); #else NMDmsg::GRPgrp::NCKgrp nckg; NMDmsg::GRPgrp::NSCgrp nscg; NCKseg nck; nck.setSysDateTime(ts); NSCseg nsc; nsc.setNetChaType("SU"); nckg.setSysClock(nck); nscg.setStatusCha(nsc); rgrp[0].setNCKgroup(nckg); rgrp[0].setNSCgroup(nscg); #endif // Message nmd.setMesHea(msh); nmd.setGRPgroup(rgrp); /* * end of NMD message assembly. */ // print request message to be sent xios cout_x(cout); if(!quiet) cout << hl7er << nmd << endl; // initialize ANYmsg to allow only ACK as result BitSet bs; bs.set(UniMesIdCode::ACKval); ANYmsg any(bs); // do server transaction cout << "trying " << address << ", " << service << endl; chat_illp(address, service, nmd, any); // print result message if(!quiet) cout << hl7er << any << endl; return 0; }