text: go.OpenHIM = function() {
      var vumigo = require('vumigo_v02');
      var events = vumigo.events;
      var Eventable = events.Eventable;
      var Q = require('q');
      var SeedJsboxUtils = require('seed-jsbox-utils');
      var utils = SeedJsboxUtils.utils;
      var moment = require('moment');
      var url = require("url");
      var _ = require("lodash");
  
      var OpenHIM = Eventable.extend(function(self, http_api, base_url, username, password) {
          self.http_api = http_api;
          self.base_url = base_url;
          self.http_api.defaults.auth = {username: username, password: password};
          self.http_api.defaults.headers['Content-Type'] = ['application/json; charset=utf-8'];
  
          self.validate_clinic_code = function(clinic_code, endpoint) {
              /* Returns the clinic name if clinic code is valid, otherwise returns false */
              if (!utils.check_valid_number(clinic_code) || clinic_code.length !== 6) {
                  return Q(false);
              }
              else {
                  var api_url = url.resolve(self.base_url, endpoint);
                  var params = {
                      criteria: "value:" + clinic_code
                  };
                  return self.http_api.get(api_url, {params: params})
                  .then(function(result) {
                      result = JSON.parse(result.body);
                      var rows = result.rows;
                      if (rows.length === 0) {
                          return false;
                      } else {
                          return rows[0][_.findIndex(result.headers, ["name", "name"])];
                      }
                  });
              }
          };
  
          self.validate_nc_clinic_code = function(clinic_code) {
              return self.validate_clinic_code(clinic_code, "NCfacilityCheck");
          };
  
          self.validate_mc_clinic_code = function(clinic_code) {
              return self.validate_clinic_code(clinic_code, "facilityCheck");
          };
  
          self.uuidv4 = function(mock) {
              if(mock !== undefined) {
                  return mock;
              }
              // From https://stackoverflow.com/questions/105034/create-guid-uuid-in-javascript
              return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
                var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
                return v.toString(16);
              });
          };
  
          self.submit_nc_registration = function(contact, mock_eid) {
              var api_url = url.resolve(self.base_url, "nc/subscription");
              var msisdn = contact.urns.filter(function(urn) {
                  // Starts with tel:
                  return urn.search('tel:') == 0;
              })[0].replace("tel:", "");
              // We don't retry this HTTP request, so we can generate a random event ID
              var eid = self.uuidv4(mock_eid);
              return self.http_api.post(api_url, {data: JSON.stringify({
                  mha: 1,
                  swt: contact.fields.preferred_channel === "whatsapp" ? 7 : 1,
                  type: 7,
                  sid: contact.uuid,
                  eid: eid,
                  dmsisdn: contact.fields.registered_by,
                  cmsisdn: msisdn,
                  rmsisdn: null,
                  faccode: contact.fields.facility_code,
                  id: msisdn.replace("+", "") + "^^^ZAF^TEL",
                  dob: null,
                  persal: contact.fields.persal || null,
                  sanc: contact.fields.sanc || null,
                  encdate: moment(contact.fields.registration_date).utc().format('YYYYMMDDHHmmss')
              })});
          };
      });
  
      return OpenHIM;
  }();
  