public IActionResult get(int id) { /*TblBiodata biodata = _context.TblBiodata * .FirstOrDefault(x => x.EpidNo == epidno); * if (biodata == null) * { * return NotFound($"No Candidate exists with EPID-NO: {epidno}"); * }*/ TblLabTests test = _context.TblLabTests .Include(x => x.BiodataNavigation) .Include(x => x.TblLabTestsIndicatorsValues) .Include(x => x.TblLabTestsSpecimen) //.OrderByDescending(x => x.TestingDate) //.OrderByDescending(x=> x.TestingTime) .FirstOrDefault(x => x.Id == id); //TblBiodata biodata = _context.TblBiodata // .in // .FirstOrDefault(x => x.EpidNo == epidno); if (test != null) { return(Ok(test)); } return(NotFound($"No Covid19 test result found.")); }
public LabTestDetailsViewModel(TblLabTests test) {//perfect BioData = test.BiodataNavigation; LabTest = test; //Method = test.MethodNavigation; Indicators = test.TblLabTestsIndicatorsValues.ToList(); Specimen = test.TblLabTestsSpecimen.ToList(); }
public void Update(LabTestDetailsViewModel obj) { //throw new NotImplementedException(); //LabTestDetailsViewModel test = new LabTestDetailsViewModel(obj);//GetById(obj.LabTest.Id); TblLabTests test = Context.TblLabTests .Include(t => t.TblLabTestsIndicatorsValues) .Include(t => t.TblLabTestsSpecimen) .FirstOrDefault(t => t.Id == obj.LabTest.Id); if (test != null) { test.Interpretation = obj.LabTest.Interpretation; test.TestingDate = obj.LabTest.TestingDate; test.TestingTime = obj.LabTest.TestingTime; test.ReportingDate = obj.LabTest.ReportingDate; test.ReportingTime = obj.LabTest.ReportingTime; test.UpdateBy = obj.LabTest.UpdateBy; test.Approved = obj.LabTest.Approved; if (test.Approved == null) { test.Approved = false; } //test.Update(obj); //do i really need it. for (int k = 0; k < test.TblLabTestsIndicatorsValues.Count; k++) { TblLabTestsIndicatorsValues i = test.TblLabTestsIndicatorsValues.ElementAt(k); i.IndicatorName = obj.Indicators.ElementAt(k).IndicatorName; i.IndicatorValue = obj.Indicators.ElementAt(k).IndicatorValue; } for (int k = 0; k < test.TblLabTestsSpecimen.Count; k++) { TblLabTestsSpecimen i = test.TblLabTestsSpecimen.ElementAt(k); i.SpecimenName = obj.Specimen.ElementAt(k).SpecimenName; i.Checked = obj.Specimen.ElementAt(k).Checked; i.SpecimenOther = obj.Specimen.ElementAt(k).SpecimenOther; } obj.LabTest = test; Save(obj); } else if (test != null && test.Method != obj.LabTest.Method) { throw new Exception("Method already set. Cannot be changed."); } }
public LabTestDetailsViewModel GetById(object id) { //throw new NotImplementedException(); TblLabTests test = Context.TblLabTests .Include(t => t.MethodNavigation) .Include(t => t.BiodataNavigation) .Include(t => t.BiodataNavigation.GenderNavigation) .Include(t => t.TblLabTestsIndicatorsValues) .Include(t => t.TblLabTestsSpecimen) .FirstOrDefault(t => t.Id == (int)id); if (test != null) { return(new LabTestDetailsViewModel(test)); } throw new NotImplementedException(); }
public void Create(LabTestDetailsViewModel obj) { //throw new NotImplementedException(); //LabTestDetailsViewModel tmp = new LabTestDetailsViewModel(obj); //not really needed TblLabTests test = obj.LabTest; if (test.Method == 0) { throw new Exception("Select Method."); } test.Approved = false; Context.TblLabTests.Add(test); obj.LabTest = test; Save(obj); }
private bool Ready4Approval(TblLabTests test) { if (test.Approved != null && test.Approved.Value) { return(true); } bool condition1 = (test.ReportingDate != null && test.ReportingTime != null); bool condition2 = false, condition3 = false; decimal sum = 0; foreach (var i in test.TblLabTestsIndicatorsValues) { if (i.IndicatorValue.HasValue) { sum += i.IndicatorValue.Value; } else { break; } } if (sum > 0) { condition2 = true; } foreach (var s in test.TblLabTestsSpecimen) { if (s.Checked) { condition3 = true; break; } } return(condition1 && condition2 && condition3); }
public LabTestDetailsViewModel(TblBiodata _BioData, IMethodRepos _methods, ISpecimenRepos _specimen) //main to create { //perfect BioData = _BioData; //Method = _method; methods = _methods; //Indicators = new List<TblLabTestsIndicatorsValues>(); Specimen = new List <TblLabTestsSpecimen>(); LabTest = new TblLabTests(); LabTest.Approved = false; LabTest.Biodata = _BioData.Id; //LabTest.Method = _method.Id; /*foreach(var i in _method.TlkpTestIndicators) * { * TblLabTestsIndicatorsValues v = new TblLabTestsIndicatorsValues(); * v.Indicator = i.Id; * v.Method = _method.Id; * LabTest.TblLabTestsIndicatorsValues.Add(v); * * Indicators.Add(v); * * * }*/ foreach (var t in _specimen.GetAll()) { TblLabTestsSpecimen s = new TblLabTestsSpecimen(); s.Specimen = t.Id; s.SpecimenName = t.Type; LabTest.TblLabTestsSpecimen.Add(s); Specimen.Add(s); } }
public IActionResult Add(TblLabTests test) { //test.MethodNavigation = null; //TblBiodata biodata = _context.TblBiodata.FirstOrDefault(b=>b.Id==test.Biodata); using (var transaction = _context.Database.BeginTransaction()) { //if (biodata != null) //{ // //test.BiodataNavigation = null; // //_context.TblBiodata.Add(test.BioData); // //_context.SaveChanges(); // //_context.Entry<TblBiodata>(test.BioData).State = EntityState.Detached; //} //else { // test.BiodataNavigation.GenderNavigation = null; //} if (_context.TblLabTests.FirstOrDefault(t => t.Id == test.Id) != null) { return(NotFound($"Covid19 test result already published on server.")); } test.BiodataNavigation.GenderNavigation = null; test.MethodNavigation = null; _context.TblLabTests.Add(test); _context.SaveChanges(); transaction.Commit(); string uri = string.Format("{0}://{1}{2}/{3}", HttpContext.Request.Scheme, HttpContext.Request.Host, HttpContext.Request.Path, test.Id); return(Created(uri, test)); } //return NotFound($"Covid19 test result not added on purpose."); }