예제 #1
0
        public List <PatientDetails> AddPatientTestResult(PatientTestSummary patientModel)
        {
            try
            {
                using (DiabeticSystemEntities context = new DiabeticSystemEntities())
                {
                    PatientTestResult testresult = new PatientTestResult()
                    {
                        PatientId          = patientModel.PatientId,
                        SugarBeforeFasting = patientModel.SugarLevelBeforeFasting,
                        SugarAfterFasting  = patientModel.SugarLevelAfterFasting,
                        TestDate           = patientModel.TestDate
                    };
                    context.PatientTestResults.Add(testresult);
                    context.SaveChanges();

                    PatientMembershipDetail membership = (from m in context.PatientMembershipDetails
                                                          where m.PatientId == patientModel.PatientId
                                                          select m).FirstOrDefault();
                    membership.TestRemaining        = membership.TestRemaining - 1;
                    context.Entry(membership).State = EntityState.Modified;
                    context.SaveChanges();
                }
            }
            catch (Exception err)
            {
                throw;
            }
            return(GetAllPatientDetails(string.Empty, string.Empty));
        }
예제 #2
0
        private void ParseAndSaveLines(List <string> matched)
        {
            _uom = _context.UnitOfMeasurements.Where(uom => uom.Name == "g/l").FirstOrDefault();

            var patient = _context.Patients.Where(p => p.RM2Number.Contains(_id))
                          .Include(p => p.PatientTestResults)
                          .ThenInclude(pt => pt.TestType)
                          .FirstOrDefault();

            var testType = _context.TestTypes
                           .Where(tt => tt.Name == "Albumin")
                           .FirstOrDefault();

            var existingDates = patient.PatientTestResults
                                .Where(ig => ig.TestTypeId == testType.ID)
                                .Select(pi => pi.DateTaken.Date)
                                .ToList();

            foreach (string line in matched)
            {
                var    dataArray  = line.Split(" ");
                string range      = "";
                string dateString = dataArray.Take(3).ToList().Join(" ");
                string testValue  = dataArray[5].Replace("*", String.Empty)
                                    .Replace("<", String.Empty)
                                    .Replace(">", String.Empty);
                string sampleId = dataArray[4];
                if (dataArray.Length > 6)
                {
                    range = dataArray[6] + dataArray[7] + dataArray[8];
                }
                else
                {
                    range = "(" + Regex.Match(_lines[12], @"\(([^)]*)\)").Groups[1].Value + ")";
                    Console.WriteLine(dataArray);
                }
                DateTime parsedDate;
                DateTime.TryParseExact(dateString, "dd MMM yyyy", null, System.Globalization.DateTimeStyles.None, out parsedDate);
                if (existingDates.FindAll(d => d.Date == parsedDate.Date).ToList().Count == 0)
                {
                    var crp = new PatientTestResult();
                    crp.TestTypeId        = testType.ID;
                    crp.SampleId          = sampleId;
                    crp.Range             = range;
                    crp.PatientId         = patient.ID;
                    crp.Value             = decimal.Parse(testValue);
                    crp.DateTaken         = parsedDate;
                    crp.UnitOfMeasurement = _uom;
                    _context.PatientTestResult.Add(crp);
                    Imported.Add(crp);
                }
            }
        }
예제 #3
0
        public async Task <PatientTestResult> CreateAndGetPatientTestResultRepositoryAsnyc(int doctorId, int patientId, int testId, int testResultInPoints, QuestionsAnswersViewModel questionsAnswers)
        {
            var testResult = await _context.ProcessingInterpretationOfResults.SingleOrDefaultAsync(tr => tr.TestId == testId &&
                                                                                                   tr.MinValue <= testResultInPoints &&
                                                                                                   tr.MaxValue >= testResultInPoints);

            if (testResult == null)
            {
                throw new Exception("Не предвиденная ошибка, не верное расчитаны количество баллов");
            }

            var questionsAnswersList = await CreateQuestionsAnswersRepositoryAsync(patientId, testId, questionsAnswers);

            var patientTestResult = new PatientTestResult(doctorId, patientId, testId, testResultInPoints, testResult.Id, DateTime.Now, questionsAnswersList);

            await _context.PatientTestResult.AddAsync(patientTestResult);

            await _context.SaveChangesAsync();

            return(patientTestResult);
        }
예제 #4
0
 public void InsertPatientTestResults(PatientTestResult model)
 {
     _PatientTestResultRepository.Insert(model);
 }
        public override Task ProcessInScope(IServiceProvider serviceProvider)
        {
            using (IServiceScope scope = _serviceProvider.CreateScope())
            {
                var context         = scope.ServiceProvider.GetRequiredService <AspergillosisContext>();
                var externalContext = scope.ServiceProvider.GetRequiredService <ExternalImportDbContext>();

                var allPatients = context.Patients
                                  .Include(p => p.PatientTestResults);

                foreach (var code in TestType.Codes().Keys)
                {
                    var testType = context.TestTypes
                                   .Where(it => it.Name == TestType.LabTestFromCode(code))
                                   .FirstOrDefault();

                    foreach (var patient in allPatients)
                    {
                        var results = externalContext.PathologyReports
                                      .Where(r => r.OrderItemCode.Equals(code) && r.RM2Number == "RM2" + patient.RM2Number);
                        if (!results.Any())
                        {
                            continue;
                        }
                        var existingDates = patient.PatientTestResults
                                            .Where(pi => pi.TestTypeId == testType.ID)
                                            .Select(pi => pi.DateTaken.Date)
                                            .ToList();

                        foreach (var result in results)
                        {
                            if (existingDates.FindAll(d => d.Date == result.DatePerformed.Date).ToList().Count == 0)
                            {
                                if (result.Result == null)
                                {
                                    continue;
                                }
                                var patientTestResult = new PatientTestResult();
                                patientTestResult.PatientId           = patient.ID;
                                patientTestResult.DateTaken           = result.DatePerformed;
                                patientTestResult.TestTypeId          = testType.ID;
                                patientTestResult.SourceSystemGUID    = result.ObservationGUID;
                                patientTestResult.UnitOfMeasurementId = testType.UnitOfMeasurementId;
                                patientTestResult.CreatedDate         = DateTime.Now;

                                try
                                {
                                    patientTestResult.Value = Decimal.Parse(result.Result
                                                                            .Replace("<", String.Empty)
                                                                            .Replace("*", String.Empty)
                                                                            .Replace(">", String.Empty));
                                }
                                catch (System.FormatException e)
                                {
                                    Console.WriteLine("TEST VALUE ERROR::::::::::::" + result.Result);
                                    continue;
                                }
                                patientTestResult.Range = result.NormalRange;
                                context.PatientTestResult.Add(patientTestResult);
                            }
                        }
                    }
                }
                context.SaveChanges();
            }
            return(Task.CompletedTask);
        }
        public async Task <IActionResult> LabTests()
        {
            var allPatients = _context.Patients
                              .Include(p => p.PatientTestResults);

            //var uom = _context.UnitOfMeasurements.Where(u => u.Name == "mg/L").FirstOrDefault();
            foreach (var code in TestType.Codes().Keys)
            {
                var testType = _context.TestTypes
                               .Where(it => it.Name == TestType.LabTestFromCode(code))
                               .FirstOrDefault();

                foreach (var patient in allPatients)
                {
                    var results = _externalImportDbContext.PathologyReports
                                  .Where(r => r.OrderItemCode.Equals(code) &&
                                         r.RM2Number == "RM2" + patient.RM2Number);
                    if (!results.Any())
                    {
                        continue;
                    }
                    var existingDates = patient.PatientTestResults
                                        .Where(pi => pi.TestTypeId == testType.ID)
                                        .Select(pi => pi.DateTaken.Date)
                                        .ToList();

                    foreach (var result in results)
                    {
                        if (existingDates.FindAll(d => d.Date == result.DatePerformed.Date).ToList().Count == 0)
                        {
                            if (result.Result == null)
                            {
                                continue;
                            }
                            var patientTestResult = new PatientTestResult();
                            patientTestResult.PatientId           = patient.ID;
                            patientTestResult.DateTaken           = result.DatePerformed;
                            patientTestResult.TestTypeId          = testType.ID;
                            patientTestResult.SourceSystemGUID    = result.ObservationGUID;
                            patientTestResult.UnitOfMeasurementId = testType.UnitOfMeasurementId;
                            patientTestResult.CreatedDate         = DateTime.Now;

                            try
                            {
                                patientTestResult.Value = Decimal.Parse(result.Result
                                                                        .Replace("<", String.Empty)
                                                                        .Replace("*", String.Empty)
                                                                        .Replace(">", String.Empty));
                            }
                            catch (System.FormatException e)
                            {
                                Console.WriteLine("VALUE::::::::::::" + result.Result);
                                continue;
                            }
                            patientTestResult.Range = result.NormalRange;

                            await _context.PatientTestResult.AddAsync(patientTestResult);
                        }
                    }
                }
            }
            await _context.SaveChangesAsync();

            return(Ok());
        }