/* * 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 #include #include #include #include #include #ifndef CAREVUE_F_VERSION HL7Message *transfer_patient(HL7Message &msg) { ADT_A02msg &request = (ADT_A02msg &)msg; IDtyp obed = request.PatVisit.PriorPatLoc.Bed; IDtyp nbed = request.PatVisit.AssPatLoc.Bed; IDtyp adn = request.PatVisit.VisitNum.IdNum; strstream cmds; xios _cmds(cmds); cmds << hl7er << PGETC "/idb_direct -c -e 2 -l '" << obed << "' -n '" << nbed << "' -r '" << adn << "'" << ends; int ret = runcmd(cmds.str()); cmds.freeze(0); if(! (ret & IDB_PAT1)) { // patient is unknown, try admission if(request.PatVisit.AssPatLoc.NurseUnit == RecFac) { // transfer within care unit -> admit LOGWARNING("patient not known, admit the patient"); ADT_A01msg a01; a01.MesHea = request.MesHea; a01.EventType = request.EventType; a01.PatIde = request.PatIde; a01.PatVisit = request.PatVisit; return admit_patient(a01); } else { // transfer out of care unit -> do nothing LOGWARNING("patient unknown and receiving facility is %s " "instead of %s", (const char *)request.MesHea.RecFac, (const char *)RecFac); return make_ack(request, AckCode::AEval, "patient unknown and transfer out of care unit"); } } else if(ret & IDB_BED2) { if(ret & IDB_PIB2) { LOGWARNING("patient is already transferred"); return make_ack(request, AckCode::AAval, "patient is already transferred"); } else { LOGWARNING("destination bed is occupied"); return make_ack(request, AckCode::AEval, "destination bed is occupied"); } } else { request.MesHea.RecApp = "ADT"; request.HpConFigDem = assemble_zdm(request.PatIde, request.PatVisit); fix_pid(request.PatIde, request.PatVisit); request.PatVisit.DisDis = dis2hp(request.PatVisit.DisDis); if(! request.PatVisit.PriorPatLoc.ispresent()) request.PatVisit.PriorPatLoc = request.PatVisit.AssPatLoc; return forward_message(request); } } #else /* * CareVue F version didn't support A02 to be a transfer within the same * careunit. * * THIS IS NO LONGER SUPPORTED */ #error carevue F version is no longer supported #include "ADT_A26msg.h" HL7Message *transfer_patient(HL7Message &msg) { ADT_A02msg &request = (ADT_A02msg &)msg; request.MesHea.RecApp = "ADT"; request.HpConFigDem = assemble_zdm(request.PatIde, request.PatVisit); fix_pid(request.PatIde, request.PatVisit); if(request.PatVisit.AssPatLoc.NurseUnit == RecFac) // i.e. our Care Unit { ADT_A26msg hp_move; hp_move.MesHea = request.MesHea; hp_move.EventType = request.EventType; hp_move.PatIde = request.PatIde; hp_move.PatVisit = request.PatVisit; hp_move.HpConFigDem = request.HpConFigDem; IDtyp new_bed = hp_move.PatVisit.AssPatLoc.Bed; /* * 1. Move patient out */ hp_move.PatVisit.AssPatLoc.Bed.unset(); delete forward_message(hp_move); /* * 2. Move patient back in */ hp_move.PatVisit.AssPatLoc.Bed = new_bed; return forward_message(hp_move); } else return forward_message(request); } #endif /* CAREVUE_F_VERSION */