Required Programming Tasks



This section describes the necessary programming tasks a business system supplier must complete in order to be able to create a business system which successfully embeds the Noah 4 Business API.

 

These tasks include:

  • Initializing

o   Setting the user

o   Setting the patient

o   Setting the language id

  • Event handling 

o   Cross threading issue

  • Launching/Connecting to and disconnecting from a NOAH 2/3 module.

  • Error handling

o   Noah 4 exceptions

 

IMPORTANT: The code in these examples consists of extracts from the sample business system made by HIMSA. This means that the code is for illustration purposes only, and cannot be used directly as written in the developers business system implementation. The full sample code for this business system is available on Noah 4 Business System Development page on himsa.com.



Initializing the Business API

In order to get started, the Business API assembly dll must be installed on the development PC. This dll comes with the Noah 4 installation.

           Figure: BusinessAPI.dll



The first step is to reference the dll in your development environment. If you are using Visual Studio 2010 this is done by opening your References folder, selecting the popup menu Add, and browsing to BusinessAPI.dll. This Dll will give a number of classes/objects which re-sample the object model and which the developer can use in the development of the business system. The figure below shows the Object browser in VS2010, which gives an overview for the Business API referenced.

Figure: Object browser in VS2010



The first step in order to use the BusinessAPI is to Register BusinessAPI instance with Noah before it tries to connect.  Noah Apps will only be allowed to connect to Noah if they are set as the preferred apps of any of Noah AppType as part of registration. Therefore, we register BusinessAPI instance as preferred app.

Below is a sample Register class that contains Install() and Uninstall methods that register and unregister app towards Noah.

Note: The business system developers should call these methods appropriately.

public class Register

    {

        //Registration towards Noah

        private const string _companyName = "HIMSA";

        private const string _cmdLineArgs = ""; //"2";

        private static string _exePath = System.Reflection.Assembly.GetExecutingAssembly().Location;

        private static string _exeStartIn = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);

        private static string _appName = Path.GetFileNameWithoutExtension(_exePath);

        public static NoahAppType AppType = NoahAppType.BusinessSystem;

       

        public static void Install()

        {

            bool isPreferedApp = true;

            bool b = BusinessAPI.RegisterNoahApp(_companyName, _appName, AppType, _exePath, _exeStartIn, _cmdLineArgs,

isPreferedApp);

            Debug.WriteLine(string.Format("Application '{0}' {1}\r\n", _appName, (b ? "installed" : "not installed")));

        }



        /// <summary>

        /// Unregister or uninstall BusinessSystem APP from Noah.

        /// </summary>

        public static void Uninstall()

        {

            bool b = BusinessAPI.UnregisterNoahApp(_companyName, _appName);

            Debug.WriteLine(string.Format("Application '{0}' {1}\r\n", _appName, (b ? "uninstalled" : "not installed")));

        }



    }



The second step in order to use the Business API is to declare a variable of the type BusinessAPI and then initiate the object declared. The properties available are then initiated when the method Initialize();  on the Business API object is called. During this initialize a connection is made to the Noah Client service, by the use of .NET remoting.

The sample below shows the initialize sequence made for the sample business system.

public BusinessAPI businessApiObj = new BusinessApi();

public MainWindow()

        {

            InitializeComponent();          //Initializing visual components

            treeView1.Nodes.Clear();     // init Treeview used in component             

            loadTreeviewNodes();          // Load treeview nodes 

            try

            {

                businessApiObj.Initialize(“MyServer”, null, NoahAppType.BusinessSystem);  //Init The Business API

                InitializeBackgoundWorker();   // Setting up a bagground worker

                backgroundWorker1.RunWorkerAsync("StartUpClient");

                //Setting up the subscription for Noah events to be received from the Business API

     businessApiObj.BusinessApiEvent += businessApiObj_BusinessApiEvent;

               //Check if a patient already is set active in the running instance of the connected Noah Client   

                if (businessApiObj.CurrentPatient != null)

                {

toolStripStatusLabel1.Text = "Current Patient: " +

businessApiObj.CurrentPatient.FirstName + " " +                                                

businessApiObj.CurrentPatient.LastName;

                               toolStripStatusLabel1.Visible = true;

                }

                loadUserCtrl();

             }

            catch (Exception ex)

 {

     l.log.Debug("BusinessApi_TestApp.MainWindow::MainWindow: "+ex);

}

        }

The next step is to set the user of the Noah system and, perhaps, a patient. The user is set by calling the method SetCurrentUserID, where the argument is an integer with the id of the user.

The language id is set by writing a value to the property LangaugeID on the BusinessAPI object. If not set the language ID is taken from the installed culture of the operating system.

The code sample below shows how the user and the language can be set:

private void LogonUser_Click(object sender, EventArgs e)

{

            //Clear the text fields

            NameText.Clear();

            initialsText.Clear();

            // businessApiObj is the BusinessAPI object, SetCurrentID returns a bool::true in case of success

            bool logon = businessApiObj.SetCurrentUserID(Convert.ToInt32(UserIDText.Text,10));

           

            if (logon == true)

            {

                NameText.Text = businessApiObj.CurrentUser.Name;

                initialsText.Text = businessApiObj.CurrentUser.Initials;

                EventArgs arg = new EventArgs();

                //Send an event to the mainwindow to indicate that the logon of the user vent well

                if (HandlelanguageID != null)

                              HandlelanguageID(this, arg);

            }



 }

 private void Refresh_Click(object sender, EventArgs e)

 {

            businessApiObj.CurrentUser.Refresh();

 }

private void SetLangaugeId_Click(object sender, EventArgs e)

{

            // businessApiObj is the BusinessAPI object, LanguageID is a propertity on the businessApi

            businessApiObj.LanguageID =  Convert.ToInt32(languageID.Text,10);

            EventArgs arg = new EventArgs();

            if (HandlelanguageID != null)

                HandlelanguageID(this, arg);

}



The patient is set by calling the method SetCurrentPatientID. This method is located on the Business API object.

The patientId is an integer greater than 0. If the id is set to 0 or less, Noah Client will deactivate the current patient and no patient will be active in Noah. When the patient ID is set it will be possible to get the session data related to the given patient from the CurrentPatient property on the BusinessAPI object.