int MHL7Compare::findSegment(HL7MSG* mMsg, const MString& segName) { if (!mMsg) return 0; if (!segName.size()) return 0; char *seg = segName.strData(); int iResult = HL7FindSegm(mMsg, seg); delete [] seg; if ((iResult != HL7_OK) && (iResult != HL7_END_OF_STRUCT)) { cout << "HL7Compare: Cannot find the segment: " << segName << endl; cout << HL7ErrTxt(mMsg, iResult) << endl; return 0; } if (iResult == HL7_END_OF_STRUCT) return 0; return 1; }
void MHL7Msg::setValue(const char* segment, int field, int component, const MString& value) { char *s = value.strData(); this->setValue(segment, field, component, s); delete [] s; };
int MHL7Factory::copyFields(MHL7Msg& source, HL7MSG* target) { // copy all the fields from the current segment of the source to the target int numFlds = source.numberOfFields(); for (int inx = 1; inx <= numFlds; inx++) { MString v = source.getValue(inx, 0); char* vCpy = v.strData(); ::HL7PutFld(target, vCpy, inx); delete []vCpy; } return 0; }
MString MCGIParser::getValue(const MString& key) { if (ptrLlist == 0) return ""; llist* p = (llist*) ptrLlist; char* keyChar = key.strData(); char* c = cgi_val(*p, keyChar); if (c == 0) c = ""; delete []keyChar; return c; }
int MHL7DomainXlate::translateDomain(MHL7Msg& hl7, HL7_MAP* m, const MDomainObject& o) { MString key; for (key = m->attribute; key != ""; key = (++m)->attribute) { MString v = o.value(key); char* val = v.strData(); hl7.setValue(m->segment, m->field, m->component, val); delete [] val; } return 0; }
CONDITION MLStorageCommitment::handleNActionDataSet(DUL_PRESENTATIONCONTEXT* ctx, MSG_N_ACTION_REQ** message, MSG_N_ACTION_RESP* response, DUL_ASSOCIATESERVICEPARAMETERS* params, MString& directoryName) { MLogClient logClient; logClient.log(MLogClient::MLOG_VERBOSE, params->callingAPTitle, "MLStorageCommitment::handleNActionDataSet", __LINE__, "Storage Commit N-Action dataset received"); MFileOperations f; MString apTitle(params->callingAPTitle); MString fullPath = mLogDir + "/" + apTitle; f.createDirectory(fullPath); MString s = f.uniqueFile(fullPath, "opn"); char* s1 = s.strData(); ::DCM_WriteFile(&(*message)->actionInformation, DCM_ORDERLITTLEENDIAN, s1); logClient.log(MLogClient::MLOG_VERBOSE, params->callingAPTitle, "MLStorageCommitment::handleNActionDataSet", __LINE__, "Storage Commit N-Action dataset written to " + s); delete []s1; response->dataSetType = DCM_CMDDATANULL; response->conditionalFields = 0; response->status = MSG_K_SUCCESS; return SRV_NORMAL; }
// Private methods below int MHL7Factory::copyFields(HL7_COPY_MAP* copyMap, MHL7Msg& source, HL7MSG* target) { while (copyMap->sourceSegment[0] != '\0') { MString v = source.getValue(copyMap->sourceSegment, copyMap->sourceField, 0); char* cPtr = 0; ::HL7FirstSegm(target, &cPtr); ::HL7FindSegm(target, copyMap->targetSegment); char* vCpy = v.strData(); ::HL7PutFld(target, vCpy, copyMap->targetField); delete []vCpy; copyMap++; } return 0; }
int MCGIParser::parse(const MString& buffer) { if (ptrLlist != 0) { llist* p = (llist*) ptrLlist; ::list_clear(p); delete p; } llist* p1 = new llist; ptrLlist = p1; ::list_create(p1); char* c = buffer.strData(); int status = ::parse_CGI_encoded(p1, c); delete []c; if (status >= 0) return 0; else return 1; }
MSyslogMessage5424::MSyslogMessage5424(int facility, int severity, int version, const MString& message, const MString& timeStamp, const MString& hostName, const MString& appName, const MString& procID, const MString& msgID, bool flagUTF8) : mFacility(facility), mSeverity(severity), mVersion(version), mTimeStamp(timeStamp), mHostName(hostName), mAppName(appName), mProcID(procID), mMsgID(msgID), mUTF8Flag(flagUTF8), mOwnMessage(false) { if (version <= 0) { mVersion = 1; } else if (version > 999) { mVersion = 999; } if (message == "") { mMessage = 0; mUTF8Flag = true; mMessageSize = 3; // BOM } else { mMessage = (unsigned char*)message.strData(); mMessageSize = message.length(); if (mUTF8Flag) mMessageSize += 3; } if (mTimeStamp == "") this->computeTimeStamp(); if (mHostName == "") this->getHostName(); if (mAppName == "") mAppName = "-"; if (mProcID == "") mProcID = "-"; if (mMsgID == "") mMsgID = "-"; }
void MHL7Compare::initializeFormat(const MString& fileName) { // read the ini file and add segment/field information in the multimap // MSegmentInfo (mSegInfo) if (!fileName.size()) return; char* fn = fileName.strData(); ifstream f(fn); delete [] fn; char buf[1024]; char *p; MString segName; memset(buf, 0, sizeof(buf)); while (f.getline(buf, sizeof(buf))) { // ignore comments if ((buf[0] == '#') || (buf[0] == ' ')) continue; p = buf; if (buf[0] == '[') //found a new section { // get segment name p++; char *tmp = strchr(p, ']'); if (tmp != NULL) { *tmp = 0; segName = p; *tmp = ']'; } } // endif else if (isdigit(buf[0])) { // get field specific information FIELD_INFO fldInfo; // get information on a particular field int fldnum = -1, compnum = -1, subcompnum = -1; char num[1024]; memset(num, 0, sizeof(num)); int i = 0; // while (*p != 0) while (1) { if (!isdigit(*p)) { num[i] = 0; if (fldnum < 0) fldnum = atoi(num); else if (compnum < 0) compnum = atoi(num); else subcompnum = atoi(num); if (*p == ';') break; if (*p == 0) break; i = 0; memset(num, 0, sizeof(num)); } else { num[i] = *p; i++; } if (*p == '.') p++; // move to the next character else if ( !isdigit(*p) ) break; else p++; } // endwhile if ( fldnum > 0 ) fldInfo.fldNum = fldnum; else fldInfo.fldNum = 0; if (compnum > 0) fldInfo.compNum = compnum; else fldInfo.compNum = 0; if (subcompnum > 0) fldInfo.subCompNum = subcompnum; else fldInfo.subCompNum = 0; // now that we have complete information about a particular field, we can insert if (segName.size()) mSegInfo.insert (MSegmentInfo::value_type (segName, fldInfo) ); //reinitialize FIELD_INFO struct fldInfo.fldNum = 0; fldInfo.compNum = 0; fldInfo.subCompNum = 0; memset(buf, 0, sizeof(buf)); } // endif } //endwhile if (!f.eof()) cout << "Could Not Read From File" << endl; }
CONDITION MLQueryUPS::handleCFindCommand(DUL_PRESENTATIONCONTEXT* ctx, MSG_C_FIND_REQ** message, MSG_C_FIND_RESP* response, DUL_ASSOCIATESERVICEPARAMETERS* params, const MString& queryLevelString) { MLogClient logClient; MString callingAPTitle; if (!params) { // We have been called by mwlQuery callingAPTitle = "mwlQuery()"; } else { callingAPTitle = params->callingAPTitle; } logClient.log(MLogClient::MLOG_VERBOSE, callingAPTitle, "MLQueryUPS::handleCFindCommand", __LINE__, "C-Find command received"); MFileOperations f; MDICOMWrapper w((*message)->identifier); // Section in braces stores the query in a file // in case we want to examine it later for debugging { char path[] = "logs/ordfil_mwl"; f.createDirectory("MESA_TARGET", path); MString s = f.uniqueFile("MESA_TARGET", path, "qry"); char* s1 = s.strData(); ::DCM_WriteFile(&(*message)->identifier, DCM_ORDERLITTLEENDIAN, s1); logClient.log(MLogClient::MLOG_VERBOSE, callingAPTitle, "MLQueryUPS::handleCFindCommand", __LINE__, MString("C-Find query stored in ") + s); delete []s1; w.log(logClient, MLogClient::MLOG_VERBOSE); } // Add return values to empty sequences this->inflateEmptySequences((*message)->identifier); //clear the MUPSObjectsVector MUPSObjectsVector::iterator mObjIt = mObjectsVector.end(); for (; mObjIt != mObjectsVector.begin(); mObjIt--) { mObjectsVector.pop_back(); } MDICOMDomainXlate xlate; MUPS ups; // MActionItemVector aiv; // xlate.translateDICOM(w, ups, aiv); MUWLScheduledStationNameCodeVector ssnCodeVector; xlate.translateDICOM(w, ups, ssnCodeVector); mOrderFiller.queryUnifiedWorkList(ups, *this); //add logging here to report number of items returned for query char rows[64]; sprintf(rows, "%d", mObjectsVector.size()); logClient.log(MLogClient::MLOG_VERBOSE, callingAPTitle, "MLQueryUPS::handleCFindCommand", __LINE__, MString("C-Find query returned ") + rows + MString(" work list items")); return SRV_NORMAL; }
CONDITION MLMPPS::handleNSetDataSet(DUL_PRESENTATIONCONTEXT* ctx, MSG_N_SET_REQ** message, MSG_N_SET_RESP* response, DUL_ASSOCIATESERVICEPARAMETERS* params, MString& directoryName) { MLogClient logClient; logClient.log(MLogClient::MLOG_VERBOSE, params->callingAPTitle, "MLMPPS::handleNSetDataSet", __LINE__, "MPPS N-Set dataset received"); //::DCM_DumpElements(&(*message)->dataSet, 1); MFileOperations f; MString instanceUID((*message)->instanceUID); MString slash("/"); MString callingAPTitle(params->callingAPTitle); MString newDirectory = mStorageDir + slash + params->callingAPTitle + slash + instanceUID; f.createDirectory(newDirectory); f.createDirectory(newDirectory); MString s = f.uniqueFile(newDirectory, "set"); char* s1 = s.strData(); ::DCM_WriteFile(&(*message)->dataSet, DCM_ORDERLITTLEENDIAN, s1 ); logClient.log(MLogClient::MLOG_VERBOSE, params->callingAPTitle, "MLMPPS::handleNSetDataSet", __LINE__, "MPPS N-Set data set written to " + s); char mppsPath[512]; newDirectory.safeExport(mppsPath, sizeof(mppsPath)); strcat (mppsPath, "/mpps.dcm"); MPPSAssistant assistant; int rslt; rslt = assistant.validateNSetDataSet(mppsPath, s1); rslt = assistant.mergeNSetDataSet(mppsPath, s1); logClient.log(MLogClient::MLOG_VERBOSE, params->callingAPTitle, "MLMPPS::handleNSetDataSet", __LINE__, MString("MPPS status updated ") + mppsPath); delete [] s1; response->dataSetType = DCM_CMDDATANULL; response->conditionalFields = 0; ::strcpy(response->classUID, (*message)->classUID); ::strcpy(response->instanceUID, (*message)->instanceUID); response->status = MSG_K_SUCCESS; return SRV_NORMAL; }
void MLDispatchOrderPlacerJapanese::processInfo(MHL7Msg& message, const MString& event, const MPatient& patient, const MPlacerOrder& placerOrder) { MString orderControl = message.getValue("ORC", 1, 1); MLogClient logClient; logClient.log(MLogClient::MLOG_VERBOSE, "peer", "MLDispatchOrderPlacerJapanese::processInfo", __LINE__, MString("Processing event ")+event+MString(" with Order Control ")+orderControl); // There can be only two possibilities of trigger events: // O01: Order Message and O02: Order Response if (orderControl == "NW") // new order request { // should not really receive it if (event == "O01") { mDatabase->enterOrder(placerOrder); // send an OK response } else { orderError(event, orderControl); } } else if (orderControl == "OK") { // order accepted OK if (event == "O02") { MPatient p(patient); MPlacerOrder po(placerOrder); // check to see if this order exists in our database if (!mDatabase->getOrder(p, po)) { logClient.log(MLogClient::MLOG_ERROR, "peer", "MLDispatchOrderPlacerJapanese::processInfo", __LINE__, MString("Order Number: ")+placerOrder.placerOrderNumber() + MString(" for patient: ") + patient.patientID() + MString(" does not exist")); orderError(event, orderControl); } } else { orderError(event, orderControl); } } else if (orderControl == "UA") { // unable to accept order if (event == "O02") { MPatient p(patient); MPlacerOrder po(placerOrder); // check to see if this order exists in our database if (!mDatabase->getOrder(p, po)) { // update order with order control code "UA" mDatabase->updateOrder(placerOrder); logClient.log(MLogClient::MLOG_ERROR, "peer", "MLDispatchOrderPlacerJapanese::processInfo", __LINE__, MString("Server did not accept order: ")+placerOrder.placerOrderNumber() + MString(" for patient: ") + patient.patientID()); } else { logClient.log(MLogClient::MLOG_ERROR, "peer", "MLDispatchOrderPlacerJapanese::processInfo", __LINE__, MString("Order Number: ")+placerOrder.placerOrderNumber() + MString(" for patient: ") + patient.patientID() + MString(" does not exist")); orderError(event, orderControl); } } else { orderError(event, orderControl); } } else if (orderControl == "CA") { // cancel order request // should not really receive it // if the order exists, delete it from the database. if (event == "O01") { MPatient p(patient); MPlacerOrder po(placerOrder); if (!mDatabase->getOrder(p, po)) { mDatabase->cancelOrder(placerOrder); // generate response CR } else { // generate response UC } } else { orderError(event, orderControl); } } else if (orderControl == "OC") { // order cancelled // Filler cancelled the order. Delete it from the database // No reply needed if (event == "O01") mDatabase->cancelOrder(placerOrder); else orderError(event, orderControl); } else if (orderControl == "CR") { // order cancelled as requested // Filler cancelled the order. Now delete it from the database if (event == "O02") { mDatabase->cancelOrder(placerOrder); } else { orderError(event, orderControl); } } else if (orderControl == "UC") { // unable to cancel if (event == "O02") { MPatient p(patient); MPlacerOrder po(placerOrder); // check to see if this order exists in our database if (!mDatabase->getOrder(p, po)) { // update order with order control "UC" mDatabase->updateOrder(placerOrder); logClient.log(MLogClient::MLOG_ERROR, "peer", "MLDispatchOrderPlacerJapanese::processInfo", __LINE__, MString("Server did not cancel order: ")+placerOrder.placerOrderNumber() + MString(" for patient: ") + patient.patientID()); } else { logClient.log(MLogClient::MLOG_ERROR, "peer", "MLDispatchOrderPlacerJapanese::processInfo", __LINE__, MString("Order Number: ")+placerOrder.placerOrderNumber() + MString(" for patient: ") + patient.patientID() + MString(" does not exist")); orderError(event, orderControl); } } else { orderError(event, orderControl); } } else if (orderControl == "DC") { // discontinue order request logClient.log(MLogClient::MLOG_ERROR, "peer", "MLDispatchOrderPlacerJapanese::processInfo", __LINE__, MString("Order Control (DC) not supported")); orderError(event, orderControl); } else if (orderControl == "OD") { // order discontinued logClient.log(MLogClient::MLOG_ERROR, "peer", "MLDispatchOrderPlacerJapanese::processInfo", __LINE__, MString("Order Control (OD) not supported")); orderError(event, orderControl); } else if (orderControl == "UD") { // unable to discontinue logClient.log(MLogClient::MLOG_ERROR, "peer", "MLDispatchOrderPlacerJapanese::processInfo", __LINE__, MString("Order Control (UD) not supported")); orderError(event, orderControl); } else if (orderControl == "OD") { // discontinued as requested logClient.log(MLogClient::MLOG_ERROR, "peer", "MLDispatchOrderPlacerJapanese::processInfo", __LINE__, MString("Order Control (OD) not supported")); orderError(event, orderControl); } else if (orderControl == "PA") { // parent order logClient.log(MLogClient::MLOG_ERROR, "peer", "MLDispatchOrderPlacerJapanese::processInfo", __LINE__, MString("Order Control (PA) not supported")); orderError(event, orderControl); } else if (orderControl == "CH") { // child order logClient.log(MLogClient::MLOG_ERROR, "peer", "MLDispatchOrderPlacerJapanese::processInfo", __LINE__, MString("Order Control (CH) not supported")); orderError(event, orderControl); } else if (orderControl == "SC") { // status changed // update order. Since it is a notification, no response needed if (event == "O01") { mDatabase->updateOrder(placerOrder); } else { orderError(event, orderControl); } } else if (orderControl == "SN") {// send order number // Order Filler has entered a new order and assigned it an filler order num if (event == "O01") { // Assign a placer order number MString poNum = getNewPlacerOrderNumber(); // store in the database MPlacerOrder po(placerOrder); po.placerOrderNumber(poNum); for (int i = po.numOrders()-1; i >= 0; i--) { MOrder o = po.order(i); o.orderControl("NA"); } mDatabase->enterOrder(po); // send a response NA #if 0 char* cValue = poNum.strData(); MString seg = message.firstSegment(); while(seg != "") { if ((seg == "ORC") || (seg == "OBR")) message.setValue(2, 0, cValue); seg = message.nextSegment(); } delete [] cValue; #endif sendORR(message, "NA", poNum); } else { orderError(event, orderControl); } } else if (orderControl == "NA") { // number assigned // should not really receive it if (event == "O02") { // a new filler order number was assigned. Update tables mDatabase->updateOrder(placerOrder); } else { orderError(event, orderControl); } } else { orderError(event, orderControl); logClient.log(MLogClient::MLOG_ERROR, "peer", "MLDispatchOrderPlacerJapanese::processInfo", __LINE__, MString("Order Control ") + orderControl + MString(" not supported")); } }
MHL7Msg* MHL7Factory::produceORR(MHL7Msg& ormMsg, const MString& orderControl, const MString& placerOrderNumber) { HL7MSG* pMsg = ::HL7Alloca(mFlavor); if (pMsg == 0) { cerr << "Could not allocate HL7 Message" << endl; exit(1); } ::HL7InsSegm(pMsg, "MSH"); ::HL7PutFld(pMsg, "^~\\&", 2); ::HL7PutFld(pMsg, "ORR^O02", 9); ::HL7PutFld(pMsg, "xxx", 10); ::HL7PutFld(pMsg, "P", 11); ::HL7PutFld(pMsg, "2.3.1", 12); ::HL7InsSegm(pMsg, "MSA"); ::HL7PutFld(pMsg, "AA", 1); HL7_COPY_MAP m[] = { { "MSH", 5, "MSH", 3}, // Sending Application { "MSH", 6, "MSH", 4}, // Sending Facility { "MSH", 3, "MSH", 5}, // Receiving Application { "MSH", 4, "MSH", 6}, // Receiving Application { "MSH", 11,"MSA", 2}, // Message Control ID { "", 0, "", 0} }; this->copyFields(m, ormMsg, pMsg); ormMsg.firstSegment(); MString seg = ormMsg.nextSegment(); char* ordCon = orderControl.strData(); char placerOrderNumberText[100]; placerOrderNumber.safeExport(placerOrderNumberText, sizeof(placerOrderNumberText)); while(seg != "") { if ((seg == "PV1") || (seg == "PID")) { // ORR message does not contain PID or PV1 segment seg = ormMsg.nextSegment(); continue; } char* cSeg = seg.strData(); ::HL7InsSegm(pMsg, cSeg); this->copyFields(ormMsg, pMsg); delete [] cSeg; // if an ORC segment, then insert the order control that the caller wants if (seg == "ORC") { ::HL7PutFld(pMsg, ordCon, 1); if (placerOrderNumber != "") { ::HL7PutFld(pMsg, placerOrderNumberText, 2); } } else if (seg == "OBR") { if (placerOrderNumber != "") { ::HL7PutFld(pMsg, placerOrderNumberText, 2); } } seg = ormMsg.nextSegment(); } delete [] ordCon; MHL7Msg* returnMsg = new MHL7Msg(pMsg); return returnMsg; }
CONDITION MLMPPS::handleNCreateDataSet(DUL_PRESENTATIONCONTEXT* ctx, MSG_N_CREATE_REQ** message, MSG_N_CREATE_RESP* response, DUL_ASSOCIATESERVICEPARAMETERS* params, MString& directoryName) { MLogClient logClient; logClient.log(MLogClient::MLOG_VERBOSE, params->callingAPTitle, "MLMPPS::handleNCreateDataSetCommand", __LINE__, "MPPS N-Create dataset received"); //::DCM_DumpElements(&(*message)->dataSet, 1); MFileOperations f; MString instanceUID((*message)->instanceUID); if (instanceUID == "") { logClient.log(MLogClient::MLOG_ERROR, params->callingAPTitle, "MLMPPS::handleNCreateDataSetCommand", __LINE__, "Zero-length instance UID received with N-Create message"); } MString slash("/"); MString callingAPTitle(params->callingAPTitle); MString newDirectory = mStorageDir + slash + params->callingAPTitle + slash + instanceUID; f.createDirectory(newDirectory); MString s = f.uniqueFile(newDirectory, "crt"); char* s1 = s.strData(); ::DCM_WriteFile(&(*message)->dataSet, DCM_ORDERLITTLEENDIAN, s1 ); logClient.log(MLogClient::MLOG_CONVERSATION, params->callingAPTitle, "MLMPPS::handleNCreateDataSetCommand", __LINE__, "N-Create stored in " + s); delete [] s1; char mppsPath[512]; newDirectory.safeExport(mppsPath, sizeof(mppsPath)); strcat (mppsPath, "/mpps.dcm"); ::DCM_WriteFile(&(*message)->dataSet, DCM_ORDERLITTLEENDIAN, mppsPath); logClient.log(MLogClient::MLOG_CONVERSATION, params->callingAPTitle, "MLMPPS::handleNCreateDataSetCommand", __LINE__, MString("MPPS status stored in ") + mppsPath); response->dataSetType = DCM_CMDDATANULL; response->conditionalFields = 0; response->status = MSG_K_SUCCESS; return SRV_NORMAL; }