Exemplo n.º 1
0
 public async Task <Response> Post([FromBody] AnalysisRequestModel analysisRequest)
 {
     try
     {
         return(await _analysisRequestService.Save(analysisRequest));
     }
     catch (Exception)
     {
         throw;
     }
 }
Exemplo n.º 2
0
        public IHttpActionResult Post([FromBody] AnalysisRequestModel model)
        {
            if (model == null)
            {
                return(BadRequest("Analysis request model is missing"));
            }

            if (!Uri.IsWellFormedUriString(model.CallbackUrl, UriKind.Absolute))
            {
                return(BadRequest("Callback Uri is invalid. Provide a valid absolute Uri"));
            }

            //var context = HttpContext.Current;

            string from        = model.From;
            string to          = model.To;
            Uri    callbackUrl = new Uri(model.CallbackUrl, UriKind.Absolute);

            Task.Factory.StartNew(async() =>
            {
                using (var scope = ContainerProvider.BeginScope())
                {
                    //SetContextForThread(context, requestedBy, "ReserveThread");
                    var engine = (ICommitMapEngine)scope.GetService(typeof(ICommitMapEngine));

                    var client = (IAnalysisResultsApiClient)scope.GetService(typeof(IAnalysisResultsApiClient));

                    try
                    {
                        var result = await engine.Run(from, to);

                        await client.PostAsync(callbackUrl, result);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e);
                        throw;
                    }
                }
            });

            return(Ok());
        }
Exemplo n.º 3
0
        public async Task <Response> Save(AnalysisRequestModel request)
        {
            _logger.LogDebug($"Analysis Request received from Billing.\n{JsonConvert.SerializeObject(request, Formatting.Indented)}");

            //check for the presence of VALID userid of the user who accepted the sample
            if (request.Request.SampleReceivedBy == 0 || request.Request.SampleReceivedBy == 1 || request.Request.SampleReceivedBy == 2 || request.Request.SampleReceivedBy == 3)
            {
                return(new Response()
                {
                    Status = 304, Message = "Required parameter not provided or invalid. [SampleReceivedBy:int]"
                });
            }


            _logger.LogDebug("Building Analysis Request");
            var insertAR = new AnalysisRequestDataModel()
            {
                EpisodeNumber        = request.Request.MemoNumber,
                Cin                  = DeriveSampleNo(request.Patient),
                SiteId               = request.Request.SiteId,
                SampleCollectionDate = GetDatetimeFromTicks(request.Request.SampleCollectedAt),
                SampleReceivedDate   = GetDatetimeFromTicks(request.Request.SampleReceivedAt),
                NationalIdPassport   = request.Patient.NidPp,
                Fullname             = request.Patient.Fullname,
                Birthdate            = GetDatetimeFromTicks(request.Patient.Birthdate),
                Age                  = request.Patient.Age,
                AtollId              = request.Patient.AtollId,
                Address              = request.Patient.Address,
                GenderId             = request.Patient.GenderId,
                PhoneNumber          = request.Patient.PhoneNumber,
                CountryId            = request.Patient.NationalityId,
                Tests                = new List <TestsModel>(),
                ClinicalDetails      = new List <ClinicalDetailsSelectionModel>()
            };

            //try parsing patient Id
            var isPatientIdLong = long.TryParse(request.Patient.PatientId, out var longPatientId);

            if (isPatientIdLong)
            {
                insertAR.InstituteAssignedPatientId = longPatientId;
                _logger.LogInformation($"Patient Id successfully parsed as long. Patient Id: {longPatientId}");
            }
            if (!isPatientIdLong)
            {
                _logger.LogError($"Invalid patient Id. Expected to be numeric long. Actual: {request.Patient.PatientId}");
            }

            var UnmappedTestCodesExist = false;

            _logger.LogDebug("Mapping analyses");
            foreach (var item in request.Analyses.RequestedTests)
            {
                var cd4Tests = GetTestIdFromBillingCode(item);
                if (cd4Tests is null)
                {
                    _logger.LogWarning($"Billing TestCode: {item} not mapped to any CD4 TestCodes"); UnmappedTestCodesExist = true; continue;
                }
                if (cd4Tests.Count == 0)
                {
                    _logger.LogWarning($"Billing TestCode: {item} not mapped to any CD4 TestCodes"); UnmappedTestCodesExist = true; continue;
                }

                insertAR.Tests.AddRange(cd4Tests);
                _logger.LogDebug($"Billing TestCode: {item} mapped to test(s): {JsonConvert.SerializeObject(cd4Tests)}");
            }
            _logger.LogDebug("Mapping analyses completed");


            if (request.Analyses.RequestedTests.Count > 0 && insertAR.Tests.Count == 0)
            {
                _logger.LogInformation("Response code 500 with message None of the test codes are mapped. Analysis request not inserted to CD4");
                return(new Response()
                {
                    Status = 500, Message = "None of the test codes are mapped. Analysis request not inserted to CD4"
                });
            }



            try
            {
                _logger.LogDebug("Calling datalayer for inserting/updating analysis request");
                await _analysisRequestDataAccess.ConfirmRequestAsync(insertAR, 2);

                //ToDo: insert the person who received / accepted the sample
                await _ndaTrackingDataAccess.UpsertSampleReceivedUserIdAsync(insertAR.Cin, request.Request.SampleReceivedBy, 2);

                //insert the sample accepted date and time if required.
                if (DecideToMarkSampleAsAccepted(insertAR))
                {
                    _logger.LogInformation("Inserting sample accepted date and time");
                    await _statusDataAccess.SetSampleAcceptedTimeReceivedFromBilling
                        (insertAR.Cin, insertAR.SampleReceivedDate.Value.ToString("yyyy-MM-dd HH:mm:ss"));
                }

                if (UnmappedTestCodesExist)
                {
                    _logger.LogDebug("Response code 201 with message Some unmapped tests / profiles not inserted to CD4.");
                    return(new Response()
                    {
                        Status = 201, Message = "Some unmapped tests / profiles not inserted to CD4."
                    });
                }

                _logger.LogDebug("Response code 200 with message success.");
                return(new Response()
                {
                    Status = 200, Message = "Success"
                });
            }
            catch (Exception ex)
            {
                _logger.LogDebug($"Response code 500 with message {ex.Message}.");
                return(new Response()
                {
                    Status = 500, Message = ex.Message
                });
            }
        }
Exemplo n.º 4
0
        public override async Task <Response> Save(AnalysisRequestModel request, ServerCallContext context)
        {
            _logger.LogDebug($"Analysis Request received from Billing.\n{JsonConvert.SerializeObject(request, Formatting.Indented)}");

            _logger.LogDebug("Building Analysis Request");
            var insertAR = new AnalysisRequestDataModel()
            {
                EpisodeNumber        = request.Request.MemoNumber,
                Cin                  = request.Request.SampleId,
                SiteId               = request.Request.SiteId,
                SampleCollectionDate = GetDatetimeFromTicks(request.Request.SampleCollectedDateTime),
                SampleReceivedDate   = GetDatetimeFromTicks(request.Request.SampleReceivedDateTime),
                NationalIdPassport   = request.Patient.NidPp,
                Fullname             = request.Patient.Fullname,
                Birthdate            = GetDatetimeFromTicks(request.Patient.Birthdate),
                Age                  = request.Patient.Age,
                AtollId              = request.Patient.AtollId,
                Address              = request.Patient.Address,
                GenderId             = request.Patient.GenderId,
                PhoneNumber          = request.Patient.PhoneNumber,
                CountryId            = request.Patient.Nationality,
                Tests                = new List <TestsModel>(),
                ClinicalDetails      = new List <ClinicalDetailsSelectionModel>()
            };

            var UnmappedTestCodesExist = false;

            _logger.LogDebug("Mapping analyses");
            foreach (var item in request.Tests.AnalysisId)
            {
                var cd4Tests = GetTestIdFromBillingCode(item);
                if (cd4Tests is null)
                {
                    _logger.LogWarning($"Billing TestCode: {item} not mapped to any CD4 TestCodes"); UnmappedTestCodesExist = true; continue;
                }
                if (cd4Tests.Count == 0)
                {
                    _logger.LogWarning($"Billing TestCode: {item} not mapped to any CD4 TestCodes"); UnmappedTestCodesExist = true; continue;
                }

                insertAR.Tests.AddRange(cd4Tests);
                _logger.LogDebug($"Billing TestCode: {item} mapped to test(s): {JsonConvert.SerializeObject(cd4Tests)}");
            }
            _logger.LogDebug("Mapping analyses completed");


            if (request.Tests.AnalysisId.Count > 0 && insertAR.Tests.Count == 0)
            {
                _logger.LogInformation("Response code 500 with message None of the test codes are mapped. Analysis request not inserted to CD4");
                return(new Response()
                {
                    Status = 500, Message = "None of the test codes are mapped. Analysis request not inserted to CD4"
                });
            }



            try
            {
                _logger.LogDebug("Calling datalayer for inserting/updating analysis request");
                await _analysisRequestDataAccess.ConfirmRequestAsync(insertAR, 1);

                //insert the sample accepted date and time if required.
                if (DecideToMarkSampleAsAccepted(insertAR))
                {
                    _logger.LogInformation("Inserting sample accepted date and time");
                    await _statusDataAccess.SetSampleAcceptedTimeReceivedFromBilling
                        (insertAR.Cin, insertAR.SampleReceivedDate.Value.ToString("yyyy-MM-dd HH:mm:ss"));
                }

                if (UnmappedTestCodesExist)
                {
                    _logger.LogDebug("Response code 201 with message Some unmapped tests / profiles not inserted to CD4.");
                    return(new Response()
                    {
                        Status = 201, Message = "Some unmapped tests / profiles not inserted to CD4."
                    });
                }

                _logger.LogDebug("Response code 200 with message success.");
                return(new Response()
                {
                    Status = 200, Message = "Success"
                });
            }
            catch (Exception ex)
            {
                _logger.LogDebug($"Response code 500 with message {ex.Message}.");
                return(new Response()
                {
                    Status = 500, Message = ex.Message
                });
            }
        }