Launching and Connecting the Module



Please observe that you are only allowed to have a single instance of the ModuleAPI per module.

The following is a simplified example of how to instantiate the ModuleAPI, and how to setup callback’s and event handling and connecting to Noah:



// Connect Module to Noah 4 and subscribe to the events.

// Use MyNoahEventHandler as event receiver

public void MyConnectToNoahMethod()

{

try

{

        // myModuleAPI represents the modules only instance of the ModuleAPI.

        if (myModuleAPI == null)

        {

            myModuleAPI = new Himsa.Noah.Modules.ModuleAPI();



     /* Subscribe to ModuleAPI events. ‘MyNoahEventHandler’ represents a method that handles

    the Noah events. A simple implementation has been shown in a previous sample.*/

             myModuleAPI.EventPublisher.Notify += MyNoahEventHandler;

        }



        /* before the module connects to Noah it can read the ‘Print’ and ‘ActionGroup’ properties

        via the GetLaunchInfo() method of the moduleAPI instance.

                 launchInfo.Print which indicates that the module is expected to perform a print job.

        launchInfo.ActionGroup which indicates that if the module is launched to perform a print job

        it must print action belonging to this action group.*/

        LaunchInfo launchInfo = myModuleAPI.GetLaunchInfo();

       



        /* moduleid represents the modules identifier and callback is an instance of a class that

        implements the Himsa.Noah.Modules.ICallbackHandler Interface.

        This is where the module connects to Noah.

        if launchInfo.Print is true, the module connects as print handler. In this situation the

        module must do the printing and immediately after

        printing disconnect.    */

        ConnectRes res;

                  res = moduleAPI.Connect(moduleID, callback, launchInfo.Print, true);

                  if (res != ConnectRes.Ok) {

                        if (res == ConnectRes.ModuleNotRegistered)    {

                            // Register module and connect again

                       }

                        }else {

                  // Report error and exist

                }

                 }

       

    /* when successfully connected to Noah the module can read various properties from the

  moduleAPI instance.

    e.g. myModuleAPI.EditOldActionsAllowed returns true then the business system allows actions

    older than the current calendar day to be edited.

    e.g. myModuleAPI.CurrentPatient returns a Patient object if a current patient has been

    selected otherwise null.

    e.g. myModuleAPI.CurrentUser returns a User object that represents the current user.

    e.g. myModuleAPI.LanguageId returns a windows LCID representing the selected language of the

    business system.



    when successfully connected to Noah the module can read various properties via the

    GetLaunchInfo() method of the moduleAPI instance.*/

     launchInfo = myModuleAPI.GetLaunchInfo();

    /* e.g. launchInfo.ModuleId represents the module id that is expected to launch.

    e.g. launchInfo.IMCClient represents an IMC handle that the module is expected to connect

    to.

    e.g. launchInfo.Action represents an action object that the module is expected to launch

    with.

    e.g. launchInfo.UnboundAction represents an unbound action object that the module is

    expected to launch with.

    }

    catch (Exception ex)

    {

    myModuleAPI.Dispose();

    myModuleAPI = null;

    }

}