Public Member Functions | Static Public Member Functions | Private Attributes

hl7 Class Reference

#include <hl7.h>

List of all members.

Public Member Functions

 hl7 (const string &a_nsHost, const string &a_nsPort)
 Default constructor and destructor.
virtual ~hl7 ()
void Connect (const bool a_reconnect=false)
 Connect to HL7 CORBA servant.
void Disconnect ()
 Disconnect from HL7 CORBA servant.
bool IsConnected ()
 Retrieve connection status.
bool SendBlock (vector< string > &a_messages)
 Send a message block to the HL7 server identified in the CTOR.
string CreateHL7Message (const string &a_gid, const string &a_cid, const string &a_basePath, const string &a_fileName, hl7_msgType_e a_msgType)
 Create a HL7 Message.
void ReorderFileSequenceNumbers (string &a_message)
ostream & operator<< (ostream &a_os)

Static Public Member Functions

static string GetFileEntry (const string &a_message)
 Provide only file entry of the message (without header).

Private Attributes

 log_CLASSID_m
UInt32_t m_seqCntr
string m_nsHost
string m_nsPort
com::digithurst::ooce::HLSevenServerBridge_var m_hl7servant_p

Detailed Description

Definition at line 53 of file hl7.h.


Constructor & Destructor Documentation

hl7::hl7 ( const string &  a_nsHost,
const string &  a_nsPort 
)

Default constructor and destructor.

Definition at line 64 of file hl7.cpp.

References log_FUNC_m.

    : m_seqCntr(0),
      m_nsHost(a_nsHost),
      m_nsPort(a_nsPort),
      m_hl7servant_p(HLSevenServerBridge_Helper::_nil()) {

    log_FUNC_m(hl7);
}

hl7::~hl7 (  )  [virtual]

Definition at line 76 of file hl7.cpp.

References log_FUNC_m.

          {
    log_FUNC_m(~hl7);
}


Member Function Documentation

void hl7::Connect ( const bool  a_reconnect = false  ) 

Connect to HL7 CORBA servant.

Definition at line 83 of file hl7.cpp.

References dbg_DETAIL, dbg_LOW, dbg_NORM, log_DBG_m, log_FUNC_m, m_hl7servant_p, m_nsHost, m_nsPort, and ipc_Corba::Singleton().

Referenced by SendBlock().

                                        {
    log_FUNC_m(Connect);

    try {
        CosNaming::NamingContext_var nsContext;
        CORBA::ORB_ptr orb_p(ipc_Corba::Singleton().m_orb);
        {
            // Resolve the naming service reference
            const string objectUri("corbaname:iiop:" + m_nsHost + ":" + m_nsPort);
            log_DBG_m(dbg_NORM, "Resolving uri: " << objectUri);
            CORBA::Object_var obj = orb_p->string_to_object(objectUri.c_str());
            log_DBG_m(dbg_DETAIL, "URI resolved.");
            nsContext = CosNaming::NamingContext::_narrow(obj);
            if (CORBA::is_nil(nsContext)) {
                log_DBG_m(dbg_LOW, "Cannot connect to Naming Service.");
            }
            log_DBG_m(dbg_LOW, "Got Naming Service reference.");
        }

        string objectName("HL7overCORBA");
        log_DBG_m(dbg_NORM, "Resolving HLSevenServerBridge (" << objectName << ").");
        CosNaming::Name_var name = omni::omniURI::stringToName(objectName.c_str());

        CORBA::Object_var obj;
        try {
            obj = nsContext->resolve(name);
            if (!CORBA::is_nil(obj) && !obj->_non_existent()) {
                log_DBG_m(dbg_DETAIL, "Seems like a valid reference.");
            }
            else {
                log_DBG_m(dbg_DETAIL, "Resolved reference is NIL or non-existent.");
                return;
            }
        }
        catch (CORBA::COMM_FAILURE&) {
            log_DBG_m(dbg_LOW, "Problems accessing Naming Service.");
            return;
        }
        catch (CORBA::TRANSIENT&) {
            log_DBG_m(dbg_LOW, "Problems accessing Naming Service.");
            return;
        }
        catch(CORBA::INV_OBJREF&) {
            log_DBG_m(dbg_LOW, "Invalid object reference. Most probably not available any more.");
            return;
        }
        catch(CosNaming::NamingContext::NotFound&) {
            log_DBG_m(dbg_LOW, "Requested name does not yet exist in the NameService.");
            return;
        }
        log_DBG_m(dbg_NORM, "StoragePeak Object id : " << obj);
        log_DBG_m(dbg_DETAIL, "StoragePeak Object ref : " << CORBA::String_var(orb_p->object_to_string(obj)));

        HLSevenServerBridge_var hl7servant;
        hl7servant = HLSevenServerBridge::_narrow(obj);
        log_DBG_m(dbg_LOW, "Got StoragePeak Server reference.");

        m_hl7servant_p = hl7servant._retn();
    }
    catch (...) {
        log_DBG_m(dbg_LOW, "Cannot connect to StoragePeak.");
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

string hl7::CreateHL7Message ( const string &  a_gid,
const string &  a_cid,
const string &  a_basePath,
const string &  a_fileName,
hl7_msgType_e  a_msgType 
)

Create a HL7 Message.

Parameters:
a_gid,: Group identifier - alphanumeric. identifies the server
a_cid,: Customer identifier - alphanumeric. identifies the surgery or doctor
a_basePath,: path to the gid-cid directory relative to the managed volume
a_fileName,: path to the file relative to a_basePath
a_fileId,: fileId of a file, if needed for recovery
a_msgType (in) type of HL7 message: migrate or recall
Returns:
constructed message
Exceptions:
cmn_SysError 

Definition at line 232 of file hl7.cpp.

References cmn_HexDump(), cmn_Num2Str(), HL7_msg_delimiters, m_seqCntr, mt_Migrate, mt_Recall, and cmn_Time::Time2HL7().

                                                     {
    //log_FUNC_m(CreateHL7Message);

    string hl7Message("");

    string msg = "MSH|";                    // MSH-1
    msg += HL7_msg_delimiters;              // MSH-2
    msg += "|GAM|";                         // MSH-3
    msg += a_gid;                           // MSH-4
    msg += HL7_msg_delimiters[HL7_M_L1];
    msg += a_cid;
    if (a_msgType == mt_Migrate) {
        msg += "|DIGITHURST|ACKNOWLEDGE|";  // MSH-5,MSH-6
    }
    else if (a_msgType == mt_Recall) {
        msg += "|DIGITHURST|DCMAPPLIANCE|"; // MSH-5,MSH-6
    }
    else {
        //throw;
    }
    cmn_Time time;
    msg += time.Time2HL7();                 // MSH-7
    msg += "||DHX";                         // MSH-8, 9
    msg += HL7_msg_delimiters[HL7_M_L1];
    if (a_msgType == mt_Migrate) {
        msg += "A01";
    }
    else if (a_msgType == mt_Recall) {
        msg += "A02";
    }
    else {
        //throw;
    }
    msg += "||P|2.3|";                      // MSH-10 .. MSH-12
    msg += HL7_seg_del;                     // Segment delimiter
    msg += "DHX|";
    msg += cmn_Num2Str(++m_seqCntr);        // DHX-1
    if (a_msgType == mt_Migrate) {
        msg += "|ARCHIVE|";                 // DHX-2
    }
    else if (a_msgType == mt_Recall) {
        msg += "|RESTORE|";                 // DHX-2
    }
    else {
        //throw;
    }
    msg += a_basePath + "|";                // DHX-3
    msg += a_fileName;                      // DHX-4
    msg += "\r";

    ostringstream sstr;
    sstr << "Message " << msg << endl
         << cmn_HexDump(msg.c_str(), msg.length(), 16, true);
    //log_DBG_m(dbg_DETAIL, sstr.str());

    return msg;
}

Here is the call graph for this function:

void hl7::Disconnect (  ) 

Disconnect from HL7 CORBA servant.

string hl7::GetFileEntry ( const string &  a_message  )  [static]

Provide only file entry of the message (without header).

Parameters:
a_message complete HL7 message with one file
Returns:
file entry

Definition at line 296 of file hl7.cpp.

Referenced by SendBlock().

                                                {
    size_t beginning = a_message.find("DHX|");
    return a_message.substr(beginning);
}

Here is the caller graph for this function:

bool hl7::IsConnected (  ) 

Retrieve connection status.

Definition at line 150 of file hl7.cpp.

References dbg_DETAIL, log_DBG_m, log_FUNC_m, and m_hl7servant_p.

Referenced by operator<<(), and SendBlock().

                      {
    bool connected(false);
    if (!CORBA::is_nil(m_hl7servant_p)) {
        try {
            if (!m_hl7servant_p->_non_existent()) {
                connected = true;
            }
        }
        catch (...) {
            log_FUNC_m(IsConnected);
            log_DBG_m(dbg_DETAIL, "Invalid HL7 servant object reference.");
            m_hl7servant_p = HLSevenServerBridge_Helper::_nil();
        }
    }
    return connected;
}

Here is the caller graph for this function:

ostream & hl7::operator<< ( ostream &  a_os  ) 

Definition at line 324 of file hl7.cpp.

References IsConnected(), m_nsHost, and m_nsPort.

                                      {
    a_os << "Naming service=" << m_nsHost << ":" << m_nsPort
         << ", Connected to StoragePeak: " << boolalpha << IsConnected();
    return a_os;
}

Here is the call graph for this function:

void hl7::ReorderFileSequenceNumbers ( string &  a_message  ) 

Definition at line 303 of file hl7.cpp.

References cmn_Num2Str(), ie_INVALID_ARG, and ivd_Error.

Referenced by SendBlock().

                                                      {
    UInt32_t counter(0);
    size_t fileEntryBeginning(string::npos);
    while (true) {
        fileEntryBeginning = a_message.find("DHX|", (fileEntryBeginning + 1));
        if (fileEntryBeginning == string::npos) {
            break;
        }

        size_t sequenceNumberPos(fileEntryBeginning + strlen("DHX|"));
        size_t nextDelimiterPosition(a_message.find("|", sequenceNumberPos));
        if (nextDelimiterPosition == string::npos) {
            throw ivd_Error(ie_INVALID_ARG, "No token delimiter in HL7 message.");
        }

        a_message.replace(sequenceNumberPos, (nextDelimiterPosition - sequenceNumberPos), cmn_Num2Str(++counter));
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool hl7::SendBlock ( vector< string > &  a_messages  ) 

Send a message block to the HL7 server identified in the CTOR.

Parameters:
a_data,: HL7 data block to send
Exceptions:
cmn_SysError 

Definition at line 170 of file hl7.cpp.

References Connect(), dbg_DETAIL, dbg_LOW, evt_ERROR, GetFileEntry(), ivd_BaseException::GetFriendly(), ipc_EXEC_m, IsConnected(), log_DBG_m, log_FUNC_m, log_WriteEvent(), m_hl7servant_p, m_nsHost, and ReorderFileSequenceNumbers().

                                              {
    log_FUNC_m(SendBlock);

    if (!IsConnected()) {
        // try to connect again
        Connect();
    }

    if (!IsConnected()) {
        ostringstream msg;
        msg << "Cannot send HL7 message to StoragePeak " << m_nsHost << ". No connection.";
        log_WriteEvent(evt_ERROR, msg.str());
        return false;
    }
    else {
        pairList messageList;
        messageList.length(1);

        //creates one message from many vector elements
        string message;
        for (UInt32_t i(0); i < a_messages.size(); i++) {
            if (message.size() != 0) {
                message += GetFileEntry(a_messages[i]);
            }
            else {
                message = a_messages[i];
            }
        }
        ReorderFileSequenceNumbers(message);
        messageList[0].key = CORBA::string_dup("HL7");
        messageList[0].value = CORBA::string_dup(message.c_str());

        CORBA::Long reply(0);
        log_DBG_m(dbg_DETAIL, "Sending message:" << endl << message);
        try {
            ipc_EXEC_m(reply = m_hl7servant_p->sendMessage(0, 0, 0, messageList, 0););
            if (reply == 1) {
                log_DBG_m(dbg_DETAIL, "Message sent successfully.");
            }
            else if (reply == -1) {
                log_DBG_m(dbg_LOW, "Message sending failed.");
            }
            else {
                ostringstream msg;
                msg << "Unknown error (" << reply << ") while sending HL7 message.";
                log_WriteEvent(evt_ERROR, msg.str());
            }
        }
        catch (ivd_Exception &e) {
            log_DBG_m(dbg_DETAIL, "Exception while sending HL7 messages. " << e.GetFriendly());
        }
        catch (...) {
            log_DBG_m(dbg_DETAIL, "Unknown exception while sending HL7 messages");
        }

        return (reply == 1);
    }
}

Here is the call graph for this function:


Member Data Documentation

hl7::log_CLASSID_m [private]

Definition at line 114 of file hl7.h.

com::digithurst::ooce::HLSevenServerBridge_var hl7::m_hl7servant_p [private]

Definition at line 123 of file hl7.h.

Referenced by Connect(), IsConnected(), and SendBlock().

string hl7::m_nsHost [private]

Definition at line 120 of file hl7.h.

Referenced by Connect(), operator<<(), and SendBlock().

string hl7::m_nsPort [private]

Definition at line 121 of file hl7.h.

Referenced by Connect(), and operator<<().

Definition at line 116 of file hl7.h.

Referenced by CreateHL7Message().


The documentation for this class was generated from the following files: