/* * 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_A01msg.h" #include "ADT_A08msg.h" #include #include #include #include HL7Message *admit_patient(HL7Message &msg) // ADT^A01 { ADT_A01msg &request = (ADT_A01msg &)msg; IDtyp bed = request.PatVisit.AssPatLoc.Bed; IDtyp adn = request.PatVisit.VisitNum.IdNum; strstream cmds; xios _cmds(cmds); cmds << hl7er << PGETC "/idb_direct -e 1 -l '" << bed << "' -r '" << adn << "'"; for(repstruc*robx=&request.Obs; !robx->end(); robx=robx->next()) adtobx(cmds, robx->first()); cmds << ends; int ret = runcmd(cmds.str()); if(ret & IDB_ERR) ERROR("%s returned error status %o", cmds.str(), ret); if(! (ret & IDB_PAT1)) { // patient is not yet known (normal case) if(ret&IDB_BED1) { // bed is occupied by other patient: // unset the bed thus that CareVue sets patient on the // waiting list (admission without bed) LOGWARNING("bed occupied, patient will be set on the waiting list"); request.PatVisit.AssPatLoc.Bed.unset(); } request.MesHea.RecApp = "ADT"; request.HpConFigDem = assemble_zdm(request.PatIde, request.PatVisit, request.NextOfKin, request.PatAllInf, request.DiaGno[0], request.Obs); request.Obs.unset(); fix_pid(request.PatIde, request.PatVisit); request.PatVisit.DisDis.unset(); request.PatVisit.DisToLoc.unset(); HL7Message *response = forward_message(request); // commit (fill in obx values if necessary) cmds.str()[strlen(cmds.str())] = ' '; cmds.freeze(0); cmds << "-c" << ends; runcmd(cmds.str()); cmds.freeze(0); return response; } else { // patient is known already, just update patient information (A08) LOGWARNING("patient known already, update the patient information"); ADT_A08msg a08; a08.MesHea = request.MesHea; a08.EventType = request.EventType; a08.PatIde = request.PatIde; a08.PatVisit = request.PatVisit; a08.PatVisitAddInf = request.PatVisitAddInf; a08.Obs = request.Obs; a08.PatAllInf = request.PatAllInf; a08.DiaGno = request.DiaGno; a08.Pro = request.Pro; a08.Gua = request.Gua; a08.IN1group = request.IN1group; a08.Acc = request.Acc; a08.Ub82Data = request.Ub82Data; a08.Ub92Data = request.Ub92Data; a08.HpConFigDem = request.HpConFigDem; return update_pat_info(a08); } }