Пример #1
0
        public static App_PatientLabs_Labs MapperHm(this PatientLabs_Labs source)
        {
            var list = new List <AppLab_Parm_ForPatient>();

            foreach (var labMapping in source.Lab_Tests.Lab_Mapping)
            {
                var somethign = labMapping.Lab_Parms.PatientLabs_Labs_Parms.FirstOrDefault(m => m.TestId == source.TestId && m.PatientLabId == source.PatientLabId);
                var actualOb  = LabParmMapper_ForPatient.Mapper_LabParmMapper_ForPatient(somethign, source.TestId);
                list.Add(actualOb);
            }
            return(new App_PatientLabs_Labs
            {
                Id = source.Id,
                TestId = source.TestId,
                Lab_Test = source.Lab_Tests.Mapper(),
                TestName = source.Lab_Tests.Name,
                ParmForPatientLabs = list,
                PatientLabId = source.PatientLabId
            });
        }
Пример #2
0
        public static App_PatientLabs_Labs AddPatientLabs(List <AppLab_Parm_ForPatient> labs)
        {
            var lab = new PatientLabs_Labs
            {
                PatientLabId = labs.First().PatientLabId,
                TestId       = labs.First().TestId,
            };

            using (var dbContext = new HMSEntities())
            {
                try
                {
                    dbContext.PatientLabs_Labs.Add(lab);
                    dbContext.SaveChanges();
                    var patientLabId = long.MaxValue;
                    foreach (var lo in labs)
                    {
                        var parm = new PatientLabs_Labs_Parms
                        {
                            Id           = 0,
                            TestId       = lo.TestId,
                            ParmId       = lo.ParmId,
                            ParmValue    = lo.ActualVal ?? "",
                            PatientLabId = lo.PatientLabId
                        };
                        patientLabId = lo.PatientLabId;
                        dbContext.PatientLabs_Labs_Parms.Add(parm);
                    }

                    var dbtest = dbContext.PatientLabs.FirstOrDefault(t => t.Id == patientLabId);
                    if (dbtest != null)
                    {
                        if (labs.Any(l => !string.IsNullOrEmpty(l.ActualVal)))
                        {
                            dbtest.Reported = DateTime.Now;
                        }
                    }

                    dbContext.SaveChanges();
                }
                catch (Exception dd)
                {
                }

                var allTestDbs = dbContext.PatientLabs_Labs.Include("Lab_Tests").ToList();

                var totalFeeTillNow = allTestDbs.Where(o => o.PatientLabId == lab.PatientLabId).ToList().Sum(o => o.Lab_Tests.Fee);

                var thistest = allTestDbs.Where(o => o.PatientLabId == lab.PatientLabId && o.TestId == labs.First().TestId);
                var final    = thistest.FirstOrDefault().MapperHm();

                final.TotalFee = totalFeeTillNow;  // to show on the screen

                var rec = dbContext.PatientLabs.FirstOrDefault(p => p.Id == lab.PatientLabId);
                rec.Amount = totalFeeTillNow;
                dbContext.SaveChanges();


                return(final);
            }
        }