/* * 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 "carevue.h" #include "cvgateway.h" #include "ADT_A17msg.h" #include "ADT_A02msg.h" #include #include #include HL7Message *swap_patients(HL7Message &msg) { ADT_A17msg &request = (ADT_A17msg &)msg; IDtyp bed1 = request.PatVisit1.AssPatLoc.Bed; IDtyp adn1 = request.PatVisit1.VisitNum.IdNum; IDtyp bed2 = request.PatVisit2.AssPatLoc.Bed; IDtyp adn2 = request.PatVisit2.VisitNum.IdNum; strstream cmds; xios _cmds(cmds); cmds << hl7er << PGETC "/idb_direct -c -e 17 -l '" << bed1 << "' -r '" << adn1 << "' -m '" << bed2 << "' -s '" << adn2 << "'" << ends; int res=runcmd(cmds.str()); cmds.freeze(0); // unknown patients are not admitted even though we could arrange // this here if((res&IDB_PAT1) && (res&IDB_PAT2)) { // both patients are known if((res&IDB_PIB1) && (res&IDB_PIB2)) { // swap already done LOGWARNING("swap already done"); return make_ack(request, AckCode::AAval, "swap already done"); } if(!(res&IDB_PIB1) && !(res&IDB_PIB2)) { // normal or unharmful cases: give it a try! request.MesHea.RecApp = "ADT"; request.HpConFigDem1 = assemble_zdm(request.PatIde1, request.PatVisit1); fix_pid(request.PatIde1, request.PatVisit1); request.HpConFigDem2 = assemble_zdm(request.PatIde2, request.PatVisit2); fix_pid(request.PatIde2, request.PatVisit2); return forward_message(request); } // the rest is treated below } else if(!(res&IDB_PAT1) && !(res&IDB_PAT2)) { // both patients unknown LOGWARNING("both patients are unknown"); return make_ack(request, AckCode::AEval, "both patients are unknown"); } if(res&IDB_PAT1 && !(res&IDB_PIB1)) { LOGWARNING("try to transfer the first patient"); ADT_A02msg a02; a02.MesHea = request.MesHea; a02.EventType = request.EventType; a02.PatIde = request.PatIde1; a02.PatVisit = request.PatVisit1; a02.PatVisit.PriorPatLoc = request.PatVisit1.AssPatLoc; a02.PatVisit.AssPatLoc = request.PatVisit2.AssPatLoc; return transfer_patient(a02); } else if(res&IDB_PAT2 && !(res&IDB_PIB2)) { LOGWARNING("try to transfer the second patient"); ADT_A02msg a02; a02.MesHea = request.MesHea; a02.EventType = request.EventType; a02.PatIde = request.PatIde2; a02.PatVisit = request.PatVisit2; a02.PatVisit.PriorPatLoc = request.PatVisit2.AssPatLoc; a02.PatVisit.AssPatLoc = request.PatVisit1.AssPatLoc; return transfer_patient(a02); } else { LOGWARNING("nothing to do"); return make_ack(request, AckCode::AAval, "nothing to do"); } }