private void HandleNewViralLoadResults(ApiInbox incomingMessage)
        {
            //save to inbox
            int Id = _apiInboxmanager.AddApiInbox(incomingMessage);

            incomingMessage.Id = Id;

            try
            {
                ViralLoadResultEntity entity       = new JavaScriptSerializer().Deserialize <ViralLoadResultEntity>(incomingMessage.Message);
                ViralLoadResultsDto   vlResultsDto = _dtoMapper.ViralLoadResults(entity);
                var processViralLoadResults        = new ProcessViralLoadResults();
                var msg = processViralLoadResults.Save(vlResultsDto);
                // var msg = "could not be processed";

                incomingMessage.LogMessage = msg;
                //update message that it has been processed
                incomingMessage.DateProcessed = DateTime.Now;
                incomingMessage.Processed     = true;
                incomingMessage.IsSuccess     = true;
                _apiInboxmanager.EditApiInbox(incomingMessage);
            }
            catch (Exception e)
            {
                incomingMessage.LogMessage = e.Message;
                incomingMessage.Processed  = true;
                incomingMessage.IsSuccess  = false;
                _apiInboxmanager.EditApiInbox(incomingMessage);
            }
        }
예제 #2
0
 public string Update(ViralLoadResultsDto viralLoadResults)
 {
     try
     {
         Msg = "Sucess";
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
         Msg = "error " + e.Message;
     }
     return(Msg);
 }
예제 #3
0
        //int _userId = Convert.ToInt32(HttpContext.Current.Session["AppUserId"]);
        //int _facilityId = Convert.ToInt32(HttpContext.Current.Session["AppLocationId"]);
        public string Save(ViralLoadResultsDto viralLoadResults)
        {
            LabOrderEntity          labOrder   = null;
            List <LabDetailsEntity> labDetails = null;
            var results = viralLoadResults.ViralLoadResult;

            if (results != null)
            {
                try
                {
                    var            patientLookup            = new PatientLookupManager();
                    var            labOrderManager          = new PatientLabOrderManager();
                    var            patientCcc               = viralLoadResults.PatientIdentification.INTERNAL_PATIENT_ID.FirstOrDefault(n => n.IdentifierType == "CCC_NUMBER").IdentifierValue;
                    var            patient                  = patientLookup.GetPatientByCccNumber(patientCcc);
                    string         receivingFacilityMFLCode = viralLoadResults.MesssageHeader.ReceivingFacility;
                    LookupLogic    flm           = new LookupLogic();
                    LookupFacility thisFacility  = flm.GetFacility(receivingFacilityMFLCode);
                    int            interopUserId = InteropUser.UserId;
                    if (thisFacility == null)
                    {
                        Msg = $"The facility {receivingFacilityMFLCode} does not exist";
                        throw new Exception(Msg);
                    }
                    if (patient == null)
                    {
                        Msg = $"Patient {patientCcc} does not exist ";
                        throw new Exception(Msg);
                    }
                    if (results.Count(r => string.IsNullOrWhiteSpace(r.VlResult.Trim())) > 0)
                    {
                        Msg = $"Viral load message has no results indicated ";
                        throw new Exception(Msg);
                    }
                    int invalidResult = 0;
                    foreach (var result in results)
                    {
                        if (result.VlResult.Contains("LDL"))
                        {
                        }
                        else if (Regex.Split(result.VlResult, @"[^0-9\.]+").Length > 0)
                        {
                        }
                        else
                        {
                            invalidResult++;
                        }
                    }

                    if (invalidResult > 0)
                    {
                        Msg = $"Viral load message has invalid results indicated ";
                        throw new Exception(Msg);
                    }
                    if (patient != null && thisFacility != null)
                    {
                        //todo brian check
                        labOrder = labOrderManager.GetPatientLabOrdersByDate((int)patient.ptn_pk, results.FirstOrDefault().DateSampleCollected).DefaultIfEmpty(null).FirstOrDefault();
                        DateTime sampleCollectionDate = results.FirstOrDefault().DateSampleCollected;
                        if (labOrder == null)
                        {
                            var patientMasterVisitManager = new PatientMasterVisitManager();

                            //var visitType = flm.GetItemIdByGroupAndItemName("VisitType", "Enrollment")[0]
                            //    .ItemId;
                            int patientMasterVisitId =
                                patientMasterVisitManager.AddPatientMasterVisit(patient.Id, interopUserId, 316);
                            var listOfTestsOrdered = new List <ListLabOrder>();
                            var order = new ListLabOrder()
                            {
                                FacilityId   = Convert.ToInt32(viralLoadResults.MesssageHeader.ReceivingFacility),
                                LabName      = "Viral Load",// results.FirstOrDefault().LabTestedIn,
                                LabNameId    = 3,
                                LabNotes     = results.FirstOrDefault().Regimen + " " + results.FirstOrDefault().SampleType,
                                LabOrderDate = sampleCollectionDate,
                                LabOrderId   = 0,
                                OrderReason  = "",
                                Results      = results.FirstOrDefault().VlResult,
                                VisitId      = patientMasterVisitId,
                                ResultDate   = viralLoadResults.MesssageHeader.MessageDatetime
                            };
                            listOfTestsOrdered.Add(order);
                            var    jss             = new JavaScriptSerializer();
                            string patientLabOrder = jss.Serialize(listOfTestsOrdered);
                            //include userid and facility ID
                            int orderId = labOrderManager.savePatientLabOrder(patient.Id, (int)patient.ptn_pk, interopUserId, thisFacility.FacilityID, 203, patientMasterVisitId, sampleCollectionDate.ToString(), "IL lab order", patientLabOrder, "Complete");

                            labOrder   = labOrderManager.GetLabOrdersById(orderId);
                            labDetails = labOrderManager.GetLabTestsOrderedById(labOrder.Id);
                        }
                        else
                        {
                            labDetails = labOrderManager.GetLabTestsOrderedById(labOrder.Id);
                        }

                        if (labOrder != null)
                        {
                            bool    isUndetectable = false;
                            string  resultText     = "";
                            decimal?resultValue    = null;
                            foreach (var result in results)
                            {
                                if (result.VlResult.Contains("LDL"))
                                {
                                    isUndetectable = true;
                                    resultText     = result.VlResult;
                                }
                                else
                                {
                                    var      resultString = result.VlResult.Replace("copies/ml", "");
                                    string[] numbers      = Regex.Split(resultString, @"[^0-9\.]+");
                                    //bool isSuccess = decimal.TryParse(resultString, out decimalValue);
                                    //if (isSuccess) resultValue = decimalValue;
                                    for (int i = 0; i < numbers.Length; i++)
                                    {
                                        if (Regex.IsMatch(numbers[i], @"^\d+$"))
                                        {
                                            resultValue = Convert.ToDecimal(numbers[i]);
                                            break;
                                        }
                                    }
                                }

                                if (labOrder != null)
                                {
                                    var labResults = new LabResultsEntity()
                                    {
                                        //todo remove hard coding
                                        LabOrderId     = labOrder.Id,
                                        LabOrderTestId = labDetails.FirstOrDefault().Id,
                                        ParameterId    = 3,
                                        LabTestId      = 3,
                                        ResultText     = resultText,
                                        ResultValue    = resultValue,
                                        ResultUnit     = "copies/ml",
                                        ResultUnitId   = 129,
                                        Undetectable   = isUndetectable,
                                        StatusDate     = result.DateSampleTested,
                                        HasResult      = true
                                    };
                                    labOrderManager.AddPatientLabResults(labResults);
                                    labOrder.OrderStatus = "Complete";
                                    labOrderManager.savePatientLabOrder(labOrder);
                                }
                            }
                            Msg = "Success";
                        }
                    }
                    else
                    {
                        Msg = "Patient does not exist";
                        return(Msg);
                    }
                }
                catch (Exception e)
                {
                    Msg = "error " + e.Message;
                    throw e;
                }
            }
            else
            {
                Msg = "Message does not contain results";
                throw new Exception(Msg);
            }
            return(Msg);
        }
예제 #4
0
        public ViralLoadResultsDto ViralLoadResults(ViralLoadResultEntity entity)
        {
            var internalIdentifiers = new List <DTOIdentifier>();
            var viralLoadResults    = new List <VLoadlResult>();

            foreach (var identifier in entity.PATIENT_IDENTIFICATION.INTERNAL_PATIENT_ID)
            {
                if (identifier.IDENTIFIER_TYPE == "CCC_NUMBER")
                {
                    var internalIdentifier = new DTOIdentifier()
                    {
                        IdentifierValue    = identifier.ID,
                        IdentifierType     = identifier.IDENTIFIER_TYPE,
                        AssigningAuthority = identifier.ASSIGNING_AUTHORITY
                    };
                    internalIdentifiers.Add(internalIdentifier);
                }
            }

            foreach (var result in entity.VIRAL_LOAD_RESULT)
            {
                DateTime dateSampleCollected = DateTime.Today;
                DateTime dateSampleTested    = DateTime.Today;

                if (result.DATE_SAMPLE_COLLECTED != "")
                {
                    dateSampleCollected = DateTime.ParseExact(result.DATE_SAMPLE_COLLECTED, "yyyyMMdd", null);
                }
                if (result.DATE_SAMPLE_TESTED != "")
                {
                    dateSampleTested = DateTime.ParseExact(result.DATE_SAMPLE_TESTED, "yyyyMMdd", null);
                }

                var vlLoadResult = new VLoadlResult()
                {
                    DateSampleCollected = dateSampleCollected,
                    DateSampleTested    = dateSampleTested,
                    VlResult            = result.VL_RESULT,
                    SampleRejection     = result.SAMPLE_REJECTION,
                    Justification       = result.JUSTIFICATION,
                    LabTestedIn         = result.LAB_TESTED_IN,
                    Regimen             = result.REGIMEN,
                    SampleType          = result.SAMPLE_TYPE
                };
                viralLoadResults.Add(vlLoadResult);
            }

            var vlResultsDto = new ViralLoadResultsDto()
            {
                MesssageHeader =
                {
                    SendingApplication   = entity.MESSAGE_HEADER.SENDING_APPLICATION,
                    SendingFacility      = entity.MESSAGE_HEADER.SENDING_FACILITY,
                    ReceivingApplication = entity.MESSAGE_HEADER.RECEIVING_APPLICATION,
                    ReceivingFacility    = entity.MESSAGE_HEADER.RECEIVING_FACILITY,
                    MessageDatetime      = DateTime.ParseExact(entity.MESSAGE_HEADER.MESSAGE_DATETIME, "yyyyMMddHHmmss", null),
                    Security             = entity.MESSAGE_HEADER.SECURITY,
                    MessageType          = entity.MESSAGE_HEADER.MESSAGE_TYPE,
                    ProcessingId         = entity.MESSAGE_HEADER.PROCESSING_ID
                },
                PatientIdentification =
                {
                    INTERNAL_PATIENT_ID = internalIdentifiers
                },
                ViralLoadResult = viralLoadResults
            };

            return(vlResultsDto);
        }