public async Task <Unit> Handle(UpdatePatientCommand command, CancellationToken cancelToken) { var patient = await _dbContext.Patients .Where(p => p.Id == command.Id) .FirstOrNotFoundAsync(nameof(Patient), command.Id, cancelToken); if (patient == null) { throw new NotFoundException(nameof(Patient), command.Id); } patient.FirstName = command.FirstName; patient.LastName = command.LastName; patient.Honorific = command.Honorific; patient.DOB = command.DOB; patient.Email = command.Email; patient.CountryCode = command.CountryCode; patient.HomePhone = command.HomePhone; patient.MobilePhone = command.MobilePhone; patient.Gender = command.Gender; patient.Occupation = command.Occupation; _dbContext.Patients.Update(patient); await _dbContext.SaveChangesAsync(cancelToken); return(Unit.Value); }
public async Task <Unit> Handle(UpdateConsultationCommand command, CancellationToken cancelToken) { var consultation = await _dbContext.Consultations .Where(c => c.Id == command.Id) .FirstOrNotFoundAsync(nameof(Consultation), command.Id, cancelToken); consultation.Date = command.Date; consultation.PractitionerId = command.PractitionerId; consultation.CasefileId = command.CasefileId; if (command.SubjectiveAssessment != null) { consultation.SubjectiveAssessment = _mapper.Map <SubjectiveAssessment>(command.SubjectiveAssessment); } if (command.ObjectiveAssessment != null) { consultation.ObjectiveAssessment = _mapper.Map <ObjectiveAssessment>(command.ObjectiveAssessment); } // Objective changed here consultation.Treatments = command.Treatments; consultation.Plans = command.Plans; _dbContext.Consultations.Update(consultation); await _dbContext.SaveChangesAsync(cancelToken); return(Unit.Value); }
public async Task <int> Handle(CreateCasefileCommand command, CancellationToken cancelToken) { var casefile = new Casefile { PatientId = command.PatientId, Name = command.Name, Created = DateTime.UtcNow }; _dbContext.Casefiles.Add(casefile); await _dbContext.SaveChangesAsync(cancelToken); return(casefile.Id); }
public async Task <int> Handle(CreateConsultationCommand command, CancellationToken cancelToken) { // Create consult first to get an Id var consult = new Consultation { Date = command.Date, PractitionerId = command.PractitionerId, CasefileId = command.CasefileId, Treatments = command.Treatments, Plans = command.Plans }; _dbContext.Consultations.Add(consult); await _dbContext.SaveChangesAsync(cancelToken); // Pass consultId to subjective and objective to save and get their own IDs var subjective = _mapper.Map <SubjectiveAssessment>(command.SubjectiveAssessment); subjective.ConsultationId = consult.Id; var objective = _mapper.Map <ObjectiveAssessment>(command.ObjectiveAssessment); objective.ConsultationId = consult.Id; _dbContext.SubjectiveAssessments.Add(subjective); _dbContext.ObjectiveAssessments.Add(objective); await _dbContext.SaveChangesAsync(cancelToken); // Pass subjective and objective ids back into consult and update it consult.SubjectiveId = subjective.Id; consult.ObjectiveId = objective.Id; _dbContext.Consultations.Update(consult); await _dbContext.SaveChangesAsync(cancelToken); return(consult.Id); }
public async Task <Unit> Handle(DeletePatientCommand command, CancellationToken cancelToken) { var patient = await _dbContext.Patients .Where(p => p.Id == command.Id) .FirstOrNotFoundAsync(nameof(Patient), command.Id, cancelToken); if (patient == null) { throw new NotFoundException(nameof(Patient), command.Id); } _dbContext.Patients.Remove(patient); await _dbContext.SaveChangesAsync(cancelToken); return(Unit.Value); }
public async Task <Unit> Handle(UpdateCasefileCommand command, CancellationToken cancelToken) { var casefile = await _dbContext.Casefiles .Where(p => p.Id == command.Id) .FirstOrNotFoundAsync(nameof(Casefile), command.Id, cancelToken); if (casefile == null) { throw new NotFoundException(nameof(Casefile), command.Id); } casefile.PatientId = command.PatientId; casefile.Name = command.Name; _dbContext.Casefiles.Update(casefile); await _dbContext.SaveChangesAsync(cancelToken); return(Unit.Value); }
public async Task <int> Handle(CreatePatientCommand command, CancellationToken cancelToken) { var patient = new Patient { FirstName = command.FirstName, LastName = command.LastName, Honorific = command.Honorific, DOB = command.DOB, Email = command.Email, CountryCode = command.CountryCode, HomePhone = command.HomePhone, MobilePhone = command.MobilePhone, Gender = command.Gender, Occupation = command.Occupation }; _dbContext.Patients.Add(patient); await _dbContext.SaveChangesAsync(cancelToken); return(patient.Id); }