Ejemplo n.º 1
0
        private MshAuthenticationService.response CallAuthenticationApi()
        {
            // new instance of service client
            MshAuthenticationService.authenticatorServiceClient client = new MshAuthenticationService.authenticatorServiceClient();

            // send request
            MshAuthenticationService.response response = client.login(this.userName, this.password, this.workspaceId);

            // save session id for future calls
            Program.MshSessionId = response.result;

            return(response);
        }
Ejemplo n.º 2
0
        internal void SubmitTestToMsh(test test)
        {
            //only submit to msh if nigeria:
            if (!test.deployment.CountryId.HasValue || test.deployment.CountryId != 2)
            {
                return;
            }

            // very basic checks: do we have patientId, laboratoryId, is it int?
            if (string.IsNullOrWhiteSpace(test.PatientId))
            {
                Logger.Log("Patient ID is required.", LogLevel.Info);
                this.SaveAttemptToApiLog(test.TestId, "Patient ID is required.");
                return;
            }

            int patientId = 0;

            if (!int.TryParse(test.PatientId, out patientId))
            {
                Logger.Log("Patient ID must be an integer.", LogLevel.Info);
                this.SaveAttemptToApiLog(test.TestId, "Patient ID must be an integer");
                return;
            }

            if (!test.deployment.MshLaboratoryId.HasValue)
            {
                Logger.Log("The test was conducted in a deployment that has no Laboratory ID.", LogLevel.Info);
                this.SaveAttemptToApiLog(test.TestId, "The test was conducted in a deployment that has no Laboratory ID.");
                return;
            }

            // alrighty, let's mess with MSH now:
            // Try to send the test result if the MshSessionId is not null:
            var dataExchangeResponse   = new MshXpertService.response();
            var authenticationResponse = new MshAuthenticationService.response();

            if (Program.MshSessionId != null)
            {
                dataExchangeResponse = this.CallDataExchangeApi(test);
            }

            // if error=2 ->sessionID invalid -> authenticate again, then try call again
            if (dataExchangeResponse.errorno == 2 || Program.MshSessionId == null)
            {
                authenticationResponse = this.CallAuthenticationApi();
                if (authenticationResponse.errorno == 0)
                {
                    this.CallDataExchangeApi(test);
                }
            }

            switch (dataExchangeResponse.errorno)
            {
            case 0:
                // The call was successfully executed.
                Logger.Log("Successfully sent to eTB Manager", LogLevel.Info);
                break;

            case 1:
                // Authentication failed. User name, password or workspace are not valid. returned only by the authenticator service.
                Logger.Log("Authentication Failed", LogLevel.Warning);
                break;

            case 2:
                // The sessionID provided is not valid. You must authenticate again.
                Logger.Log("SessionID invalid", LogLevel.Warning);
                break;

            case 3:
                // Unexpected error. This is not common and it’s better to contact the system administrator when it happens.
                // Check the errormsg field for more information.
                Logger.Log("Unexpected Error: " + dataExchangeResponse.errormsg, LogLevel.Error);
                break;

            case 4:
                // Validation error. It is caused when the information didn’t pass the validation rules of the method call,
                // for example, a required field that is null. Check the errormsg field for more information.
                Logger.Log("Validation Failed: " + dataExchangeResponse.errormsg, LogLevel.Error);
                break;

            default:
                return;
            }
        }