public ActionResult <TreatmentHistoryViewModel> GetTreatmentHistory(int medicalChartId, int treatmentHistoryId) { if (!_treatmentHistoryService.Exist(medicalChartId, treatmentHistoryId)) { return(NotFound()); } var treatmentHistoryDTO = _treatmentHistoryService.Get(medicalChartId, treatmentHistoryId); return(TreatmentHistoryMapper.DTOtoTreatmentHistoryVM(treatmentHistoryDTO)); }
public ActionResult <IEnumerable <TreatmentHistoryViewModel> > GetTreatmentHistories(int medicalChartId) { if (!_medicalChartService.Exist(medicalChartId)) { return(NotFound()); } return(_medicalChartService .GetTreatmentHistories(medicalChartId) .Select(th => TreatmentHistoryMapper.DTOtoTreatmentHistoryVM(th)) .ToList()); }
public ActionResult <IEnumerable <AllergyViewModel> > GetAllergies(int medicalChartId, int treatmentHistoryId, UpdateTreatmentHistoryViewModel updateTreatmentHistory) { if (!_treatmentHistoryService.Exist(medicalChartId, treatmentHistoryId)) { return(NotFound()); } var treatmentHistoryDTO = TreatmentHistoryMapper.UpdateTreatmentHistoryVMToDTO(updateTreatmentHistory); _treatmentHistoryService.Update(treatmentHistoryDTO); return(NoContent()); }
public List <TreatmentHistoryDTO> GetTreatmentHistories(int medicalChartId) { var treatmentHistoryDTOS = _context.TreatmentHistories .Include(th => th.User) .Include(th => th.Treatment) .Include(th => th.Tooth) .Include(th => th.Affiliate) .Where(f => f.MedicalChartId.Equals(medicalChartId)) .OrderByDescending(th => th.DateOfTreatment) .Select(th => TreatmentHistoryMapper.TreatmentHistoryToDTO(th)) .ToList(); return(treatmentHistoryDTOS); }
public TreatmentHistoryDTO Get(int medicalChartId, int treatmentHistoryId) { var treatmentHistory = _context.TreatmentHistories .Include(th => th.User) .Include(th => th.Treatment) .Include(th => th.Tooth) .Include(th => th.Affiliate) .Where(th => th.Id.Equals(treatmentHistoryId)) .Where(th => th.MedicalChartId.Equals(medicalChartId)) .SingleOrDefault(); if (treatmentHistory == null) { return(null); } return(TreatmentHistoryMapper.TreatmentHistoryToDTO(treatmentHistory)); }
public IActionResult CreateTreatmentHistory(int medicalChartId, [FromBody] CreateTreatmentHistoryViewModel createTreatmentHistory) { if (medicalChartId != createTreatmentHistory.MedicalChartId) { return(BadRequest()); } if ( !_medicalChartService.Exist(medicalChartId) || !_treatmentService.Exist(createTreatmentHistory.TreatmentId) || (createTreatmentHistory.UserId != null && !_dentistService.Exist(createTreatmentHistory.UserId)) ) { return(NotFound()); } var treatmentHistoryDTO = TreatmentHistoryMapper.CreateTreatmentHistoryVMToDTO(createTreatmentHistory); _treatmentHistoryService.Create(treatmentHistoryDTO); return(Ok(ModelState)); }
public void Create(TreatmentHistoryDTO treatmentHistoryDTO) { var treatmentHistory = TreatmentHistoryMapper.DTOtoTreatmentHistory(treatmentHistoryDTO); var medicalChart = _context.MedicalCharts.Find(treatmentHistoryDTO.MedicalChartId); var treatment = _context.Treatments.Find(treatmentHistoryDTO.TreatmentId); var tooth = _context.Teeth.Find(treatmentHistoryDTO.ToothId); string userId; if (treatmentHistoryDTO.UserId is null) { userId = _userProviderService.GetUserId(); } else { userId = treatmentHistoryDTO.UserId; } var user = _context.ApplicationUsers.Find(userId); var affiliateId = _context.ApplicationUsers .Where(u => u.Id.Equals(userId)) .Select(u => u.AffiliateId) .Single(); var affiliate = _context.Affiliates.Find(affiliateId); treatmentHistory.Price = treatment.Price; treatmentHistory.Treatment = treatment; treatmentHistory.Tooth = tooth; treatmentHistory.Affiliate = affiliate; treatmentHistory.MedicalChart = medicalChart; treatmentHistory.User = user; _context.TreatmentHistories.Add(treatmentHistory); _context.SaveChanges(); }