Пример #1
0
        private void SaveAttemptToApiLog(int testId, MshXpertService.xpertData data, MshXpertService.response response)
        {
            apilog log = this.bpe.apilogs.Create();

            log.CaseId              = data.caseId.ToString();
            log.Comments            = data.comments;
            log.InitiatedBy         = "BigPicture Listener";
            log.InitiatedManually   = false;
            log.InitiatedOn         = DateTime.Now;
            log.ErrorCode           = response.errorno.ToString();
            log.ErrorMessage        = response.errormsg;
            log.IsError             = response.errorno != 0;
            log.LaboratoryId        = data.laboratoryId.ToString();
            log.ReleaseDate         = data.releaseDate;
            log.RifResult           = data.rifResult.ToString();
            log.SampleDateCollected = data.sampleDateCollected;
            log.SampleId            = data.sampleId;
            log.TbResult            = data.result.ToString();
            log.TestId              = testId;
            this.bpe.apilogs.Add(log);
            this.bpe.SaveChanges();
        }
Пример #2
0
        private MshXpertService.response CallDataExchangeApi(test test)
        {
            // new instance of service client
            MshXpertService.xpertServiceClient client = new MshXpertService.xpertServiceClient();

            // build result-object
            var    tbResult     = new MshXpertService.xpertResult();
            string tbResultText = test.testresults.First(r => r.ResultTestCodeId == 3).Result;

            #region Just a long-ish switch to match our and their result codes...
            switch (tbResultText)
            {
            case "ERROR":
                tbResult = MshXpertService.xpertResult.ERROR;
                break;

            case "INVALID":
                tbResult = MshXpertService.xpertResult.INVALID;
                break;

            case "MTB DETECTED HIGH":
                tbResult = MshXpertService.xpertResult.TB_DETECTED;
                break;

            case "MTB DETECTED LOW":
                tbResult = MshXpertService.xpertResult.TB_DETECTED;
                break;

            case "MTB DETECTED MEDIUM":
                tbResult = MshXpertService.xpertResult.TB_DETECTED;
                break;

            case "MTB DETECTED VERY LOW":
                tbResult = MshXpertService.xpertResult.TB_DETECTED;
                break;

            case "MTB NOT DETECTED":
                tbResult = MshXpertService.xpertResult.TB_NOT_DETECTED;
                break;

            default:
                tbResult = MshXpertService.xpertResult.NO_RESULT;
                break;
            }
            #endregion

            // build rif-result object
            // build result-object
            var    rifResult     = new MshXpertService.xpertRifResult();
            string rifResultText = test.testresults.First(r => r.ResultTestCodeId == 4).Result;
            #region Just a long-ish switch to match our and their result codes...
            switch (rifResultText)
            {
            case "ERROR":
                rifResult = MshXpertService.xpertRifResult.RIF_INDETERMINATE;
                break;

            case "INVALID":
                rifResult = MshXpertService.xpertRifResult.RIF_INDETERMINATE;
                break;

            case "Rif Resistance DETECTED":
                rifResult = MshXpertService.xpertRifResult.RIF_DETECTED;
                break;

            case "Rif Resistance NOT DETECTED":
            case "":
                rifResult = MshXpertService.xpertRifResult.RIF_NOT_DETECTED;
                break;

            default:
                rifResult = MshXpertService.xpertRifResult.RIF_INDETERMINATE;
                break;
            }
            #endregion

            // build test-object
            MshXpertService.xpertData data = new MshXpertService.xpertData();
            data.caseId          = Convert.ToInt32(test.PatientId);
            data.caseIdSpecified = true;

            // generate our own sampleId if need be
            if (string.IsNullOrWhiteSpace(test.SampleId))
            {
                test.SampleId = this.GetNewSampleId(test.TestId);
            }

            data.sampleId = test.SampleId;

            data.sampleDateCollected          = test.TestStartedOn;
            data.sampleDateCollectedSpecified = true;

            data.releaseDate          = test.UpdatedOn;
            data.releaseDateSpecified = true;

            data.laboratoryId          = test.deployment.MshLaboratoryId.Value;
            data.laboratoryIdSpecified = true;

            data.result          = tbResult;
            data.resultSpecified = true;

            data.rifResult          = rifResult;
            data.rifResultSpecified = true;

            data.comments = test.Notes;

            // send request
            MshXpertService.response response = client.postResult(Program.MshSessionId, data);

            // update test table:
            if (response.errorno == 0)
            {
                test.SendToMshSuccessOn = DateTime.Now;
            }

            // save attempt to apilog:
            this.SaveAttemptToApiLog(test.TestId, data, response);

            return(response);
        }