public async Task AcceptTransferAndDismissAlertAsync() { var transferDate = TransferRequest.LatestTransferDate?.Date == TransferRequest.TransferDate.Value.Date ? TransferRequest.LatestTransferDate.Value.AddMinutes(1) : TransferRequest.TransferDate.Value; var transferOutEvent = new TreatmentEvent { NotificationId = NotificationId, EventDate = transferDate, TreatmentEventType = TreatmentEventType.TransferOut, CaseManagerId = Notification.HospitalDetails.CaseManagerId, TbServiceCode = Notification.HospitalDetails.TBServiceCode, Note = TransferRequest.TransferAlert.TransferRequestNote }; var transferInEvent = new TreatmentEvent { NotificationId = NotificationId, EventDate = transferDate.AddSeconds(1), TreatmentEventType = TreatmentEventType.TransferIn, CaseManagerId = TransferRequest.TransferAlert.CaseManagerId, TbServiceCode = TransferRequest.TransferAlert.TbServiceCode, Note = TransferRequest.TransferAlert.TransferRequestNote }; var previousTbService = new PreviousTbService() { TransferDate = transferDate, TbServiceCode = Notification.HospitalDetails.TBServiceCode, PhecCode = Notification.HospitalDetails?.TBService?.PHECCode }; Notification.PreviousTbServices.Add(previousTbService); Notification.HospitalDetails.TBServiceCode = TransferRequest.TransferAlert.TbServiceCode; Notification.HospitalDetails.HospitalId = TransferRequest.TargetHospitalId; Notification.HospitalDetails.CaseManagerId = TransferRequest.TargetCaseManagerId; // Drop consultant and local patient ID because these are almost certainly going to be different at the new // TB service, as per NTBS-1559 Notification.HospitalDetails.Consultant = null; Notification.PatientDetails.LocalPatientId = null; // We want to save all these changes in the same transaction so that we make sure the time between the first // and last audit logs are within the timeframe for them to be grouped together on the changes page. We // experienced an issue where the audits from an acceptance were over this threshold and our app didn't // know how to handle the group. See NTBS-2457 Service.UpdatePatientDetailsWithoutSave(Notification, Notification.PatientDetails); Service.UpdateHospitalDetailsWithoutSave(Notification, Notification.HospitalDetails); _treatmentEventRepository.AddWithoutSave(transferOutEvent); _treatmentEventRepository.AddWithoutSave(transferInEvent); await _alertService.DismissAlertWithoutSaveAsync(TransferRequest.TransferAlert.AlertId, User.Username()); await _treatmentEventRepository.SaveChangesAsync(NotificationAuditType.Edited); }
public async Task AcceptTransferAndDismissAlertAsync() { var currentTime = DateTime.Now; var transferOutEvent = new TreatmentEvent { NotificationId = NotificationId, EventDate = currentTime, TreatmentEventType = TreatmentEventType.TransferOut, CaseManagerUsername = Notification.HospitalDetails.CaseManagerUsername, TbServiceCode = Notification.HospitalDetails.TBServiceCode, Note = TransferAlert.TransferRequestNote }; var transferInEvent = new TreatmentEvent { NotificationId = NotificationId, EventDate = currentTime.AddSeconds(1), TreatmentEventType = TreatmentEventType.TransferIn, CaseManagerUsername = TransferAlert.CaseManagerUsername, TbServiceCode = TransferAlert.TbServiceCode, Note = TransferAlert.TransferRequestNote }; var previousTbService = new PreviousTbService() { TransferDate = currentTime, TbServiceCode = Notification.HospitalDetails.TBServiceCode, PhecCode = Notification.HospitalDetails?.TBService?.PHECCode }; Notification.PreviousTbServices.Add(previousTbService); Notification.HospitalDetails.TBServiceCode = TransferAlert.TbServiceCode; Notification.HospitalDetails.HospitalId = TargetHospitalId; Notification.HospitalDetails.CaseManagerUsername = TargetCaseManagerUsername; await Service.UpdateHospitalDetailsAsync(Notification, Notification.HospitalDetails); await _treatmentEventRepository.AddAsync(transferOutEvent); await _treatmentEventRepository.AddAsync(transferInEvent); await _alertService.DismissAlertAsync(TransferAlert.AlertId, User.FindFirstValue(ClaimTypes.Upn)); }