/* * 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. */ /* * Translate patient ID strings to CareVue 060_IOP bed identifiers of * the form: -. The ABL300 allows numbers and colons in the * PTID input, thus we translate : into -. This * is still highly dependent on the local conventions but shall suffice * for the time being. Allowed combinations of room and bed are as * follows: * * 601-1 601-2 602-3 603-4 603-5 604-6 604-7 607-8 607-9 609-10 * 609-11 653-12 653-13 651-14 651-15 648-16 648-17 647-18 647-19 646-20 * 645-21 645-22 * * these are, however, not checked for. The patient data is fetched * indirectly from the carevue system via a shell script which in turn * issues a remore shell job to CareVue's idb. */ #pragma implementation "patinfo.h" #include "patinfo.h" #include #ifdef USE_PROCBUF # include #else # include # include #endif #include #include #include #include #define PAT_BY_BED PGETC "/PatByBed" patinfo::patinfo(const char *s) { int nostrings = ( (void **)&bed - (void **)&patient_id ) + 1; char **strings = &patient_id; for(int i = 0; i < nostrings; i++) strings[i] = NULL; line = NULL; char *ptid = NULL; if(s == NULL) { LOGWARNING("PTID: not present"); return; } else { ptid = strdup(s); LOGINFO("PTID: %s", ptid); } /* make the bed identifier */ char *colon = strchr(ptid, ':'); if(colon == NULL) { LOGWARNING("PTID `%s' is not a valid room:bed term", ptid); return; } *colon = '\0'; // catch room and bed numbers on the fly room = strdup(ptid); bed = strdup(colon + 1); *colon = '-'; // now we have the - term /* construct the call "PatByBed " */ char *cmd = (char *)alloca(sizeof(PAT_BY_BED " ") + strlen(ptid) + 1); strcpy(cmd, PAT_BY_BED " "); strcat(cmd, ptid); /* create the pipe now */ #ifdef USE_PROCBUF procbuf pipe(cmd, ios::in); istream is(&pipe); if(is.ipfx(1)) is.gets(&line); if(!is) ERROS("error on pipe: `%s'", cmd); else ERROS("can't open pipe: `%s'", cmd); #else { char buf[1024]; FILE* pipe = popen(cmd, "r"); if(pipe == NULL) ERROS("popen `%s'", cmd); int len = read(fileno(pipe), buf, 1024); if(len == -1) ERROS("error on pipe: `%s'", cmd); else if(len == 0) line = NULL; else { line = new char[len + 1]; strncpy(line,buf,len); line[len] = '\0'; } pclose(pipe); } #endif if(line == NULL) { LOGWARNING("unable to resolve bed `%s'", ptid); return; } /* analyze the input */ char *p = line; for(int i = 0; i < nostrings; i++) { char del; if( *p == '"') { del = '"'; p++; } else del = '\t'; strings[i] = p; while(*p != del) p++; *p++ = '\0'; if(del == '\t' && strcmp(strings[i], "NULL") == 0) strings[i] = NULL; if(del == '"' && *p == '\t') p++; if(*p == '\n') break; } if(sex != NULL) { if(*sex != '\0') { if(strcasecmp(sex,"F") != 0) { if(strcasecmp(sex,"W") == 0) sex[0] = 'F'; else if(!strcasecmp(sex,"M") == 0) { sex[0] = 'O'; sex[1] = '\0'; } } } } if(date_of_birth != NULL && *date_of_birth != '\0') { /* resolve dates of the form DDxMMx[CC]YY where x is any non * numeric character */ char *p = date_of_birth; dob_day = strtol(p, &p, 10); p++; // any delimiter '.' '/' or whatever (even '-' works) dob_month = strtol(p, &p, 10); p++; // any delimiter '.' '/' or whatever (even '-' works) dob_year = strtol(p, &p, 10); /* optional century */ if(dob_year < 100) dob_year += 1900; } else /* no DOB could be found */ { dob_day = 0; dob_month = 0; dob_year = 0; } } patinfo::~patinfo() { if(line!=NULL) delete [] line; if(room!=NULL) delete [] room; if(bed!=NULL) delete [] bed; }