public void should_have_value_for_prioritystartend_trigger() { DispatchProtocol procotol = new DispatchProtocol(); procotol.DepartmentId = 1; procotol.Name = ""; procotol.Code = ""; procotol.IsDisabled = false; procotol.Description = ""; procotol.ProtocolText = ""; procotol.CreatedOn = DateTime.UtcNow; procotol.CreatedByUserId = TestData.Users.TestUser1Id; procotol.UpdatedOn = DateTime.UtcNow; procotol.MinimumWeight = 10; procotol.UpdatedByUserId = TestData.Users.TestUser1Id; procotol.Triggers = new List <DispatchProtocolTrigger>(); DispatchProtocolTrigger trigger1 = new DispatchProtocolTrigger(); trigger1.Type = (int)ProtocolTriggerTypes.CallPriorty; trigger1.StartsOn = DateTime.UtcNow.AddDays(-1); trigger1.EndsOn = DateTime.UtcNow.AddDays(1); trigger1.Priority = (int)CallPriority.Emergency; procotol.Triggers.Add(trigger1); Call call = new Call(); call.DepartmentId = 1; call.Name = "Priority 1E Cardiac Arrest D12"; call.NatureOfCall = "RP reports a person lying on the street not breathing."; call.Notes = "RP doesn't know how to do CPR, can't roll over patient"; call.MapPage = "22T"; call.GeoLocationData = "39.27710789298309,-119.77201511943328"; call.Dispatches = new Collection <CallDispatch>(); call.LoggedOn = DateTime.Now; call.ReportingUserId = TestData.Users.TestUser1Id; call.Priority = (int)CallPriority.Emergency; CallDispatch cd = new CallDispatch(); cd.UserId = TestData.Users.TestUser2Id; call.Dispatches.Add(cd); CallDispatch cd1 = new CallDispatch(); cd1.UserId = TestData.Users.TestUser3Id; call.Dispatches.Add(cd1); var triggers = _protocolService.DetermineActiveTriggers(procotol, call); triggers.Should().NotBeNullOrEmpty(); triggers.Should().HaveCount(1); }
public void should_be_null_for_disabled_protocol() { DispatchProtocol procotol = new DispatchProtocol(); procotol.DepartmentId = 1; procotol.Name = ""; procotol.Code = ""; procotol.IsDisabled = true; procotol.Description = ""; procotol.ProtocolText = ""; procotol.CreatedOn = DateTime.UtcNow; procotol.CreatedByUserId = TestData.Users.TestUser1Id; procotol.UpdatedOn = DateTime.UtcNow; procotol.MinimumWeight = 10; procotol.UpdatedByUserId = TestData.Users.TestUser1Id; Call call = new Call(); call.DepartmentId = 1; call.Name = "Priority 1E Cardiac Arrest D12"; call.NatureOfCall = "RP reports a person lying on the street not breathing."; call.Notes = "RP doesn't know how to do CPR, can't roll over patient"; call.MapPage = "22T"; call.GeoLocationData = "39.27710789298309,-119.77201511943328"; call.Dispatches = new Collection <CallDispatch>(); call.LoggedOn = DateTime.Now; call.ReportingUserId = TestData.Users.TestUser1Id; CallDispatch cd = new CallDispatch(); cd.UserId = TestData.Users.TestUser2Id; call.Dispatches.Add(cd); CallDispatch cd1 = new CallDispatch(); cd1.UserId = TestData.Users.TestUser3Id; call.Dispatches.Add(cd1); var triggers = _protocolService.DetermineActiveTriggers(procotol, call); triggers.Should().BeNull(); }
public void should_be_null_for_no_call() { DispatchProtocol procotol = new DispatchProtocol(); procotol.DepartmentId = 1; procotol.Name = ""; procotol.Code = ""; procotol.IsDisabled = false; procotol.Description = ""; procotol.ProtocolText = ""; procotol.CreatedOn = DateTime.UtcNow; procotol.CreatedByUserId = TestData.Users.TestUser1Id; procotol.UpdatedOn = DateTime.UtcNow; procotol.MinimumWeight = 10; procotol.UpdatedByUserId = TestData.Users.TestUser1Id; var triggers = _protocolService.DetermineActiveTriggers(procotol, null); triggers.Should().BeNull(); }
public async Task <DispatchProtocol> SaveProtocolAsync(DispatchProtocol protocol, CancellationToken cancellationToken = default(CancellationToken)) { var saved = await _dispatchProtocolRepository.SaveOrUpdateAsync(protocol, cancellationToken); if (saved.Questions != null) { foreach (var q in saved.Questions) { if (q.Answers != null) { foreach (var a in q.Answers) { if (a.DispatchProtocolQuestionAnswerId <= 0) { a.DispatchProtocolQuestionId = q.DispatchProtocolQuestionId; await _dispatchProtocolQuestionAnswersRepository.SaveOrUpdateAsync(a, cancellationToken, true); } } } } } return(saved); }
public static ProtocolResult Convert(DispatchProtocol dp) { var protocol = new ProtocolResult(); protocol.Id = dp.DispatchProtocolId; protocol.DepartmentId = dp.DepartmentId; protocol.Name = dp.Name; protocol.Code = dp.Code; protocol.IsDisabled = dp.IsDisabled; protocol.Description = dp.Description; protocol.ProtocolText = dp.ProtocolText; protocol.CreatedOn = dp.CreatedOn; protocol.CreatedByUserId = dp.CreatedByUserId; protocol.UpdatedOn = dp.UpdatedOn; protocol.MinimumWeight = dp.MinimumWeight; protocol.UpdatedByUserId = dp.UpdatedByUserId; protocol.State = (int)dp.State; protocol.Triggers = new List <ProtocolTriggerResult>(); protocol.Attachments = new List <ProtocolTriggerAttachmentResult>(); protocol.Questions = new List <ProtocolTriggerQuestionResult>(); foreach (var t in dp.Triggers) { var trigger = new ProtocolTriggerResult(); trigger.Id = t.DispatchProtocolTriggerId; trigger.Type = t.Type; trigger.StartsOn = t.StartsOn; trigger.EndsOn = t.EndsOn; trigger.Priority = t.Priority; trigger.CallType = t.CallType; trigger.Geofence = t.Geofence; protocol.Triggers.Add(trigger); } foreach (var a in dp.Attachments) { var attachment = new ProtocolTriggerAttachmentResult(); attachment.Id = a.DispatchProtocolAttachmentId; attachment.FileName = a.FileName; attachment.FileType = a.FileType; protocol.Attachments.Add(attachment); } foreach (var q in dp.Questions) { var question = new ProtocolTriggerQuestionResult(); question.Id = q.DispatchProtocolQuestionId; question.Question = q.Question; question.Answers = new List <ProtocolQuestionAnswerResult>(); foreach (var a in q.Answers) { var answer = new ProtocolQuestionAnswerResult(); answer.Id = a.DispatchProtocolQuestionAnswerId; answer.Answer = a.Answer; answer.Weight = a.Weight; question.Answers.Add(answer); } protocol.Questions.Add(question); } return(protocol); }
public List <DispatchProtocolTrigger> DetermineActiveTriggers(DispatchProtocol protocol, Call call) { List <DispatchProtocolTrigger> triggers = new List <DispatchProtocolTrigger>(); if (protocol == null || protocol.Triggers == null || !protocol.Triggers.Any()) { return(null); } if (call == null) { return(null); } if (protocol.IsDisabled) { return(null); } // Getting all null start and end triggers var nullStartEndTimeTriggers = from trigger in protocol.Triggers where trigger.StartsOn == null && trigger.EndsOn == null select trigger; // Null Start, not null End and End date valid var nullStartValidEndTimeTriggers = from trigger in protocol.Triggers where trigger.StartsOn == null && trigger.EndsOn != null && trigger.EndsOn >= DateTime.UtcNow select trigger; // Null End, not null Start and Start date valid var nullEndValidStartTimeTriggers = from trigger in protocol.Triggers where trigger.EndsOn == null && trigger.StartsOn != null && trigger.StartsOn <= DateTime.UtcNow select trigger; // Start and End, valid dates var validStartEndTimeTriggers = from trigger in protocol.Triggers where trigger.StartsOn != null && trigger.EndsOn != null && (trigger.StartsOn <= DateTime.UtcNow && trigger.EndsOn >= DateTime.UtcNow) select trigger; var validTriggers = new List <DispatchProtocolTrigger>(); validTriggers.AddRange(nullStartEndTimeTriggers); validTriggers.AddRange(nullStartValidEndTimeTriggers); validTriggers.AddRange(nullEndValidStartTimeTriggers); validTriggers.AddRange(validStartEndTimeTriggers); if (validTriggers == null || !validTriggers.Any()) { return(null); } var priorityTriggers = validTriggers.Where(x => x.Type == (int)ProtocolTriggerTypes.CallPriorty && x.Priority == call.Priority); if (priorityTriggers != null && priorityTriggers.Any()) { triggers.AddRange(priorityTriggers); } var typeTriggers = validTriggers.Where(x => x.Type == (int)ProtocolTriggerTypes.CallType && x.CallType == call.Type); if (typeTriggers != null && typeTriggers.Any()) { triggers.AddRange(typeTriggers); } var typeAndPrioityTriggers = validTriggers.Where(x => x.Type == (int)ProtocolTriggerTypes.CallPriortyAndType && x.Priority == call.Priority && x.CallType == call.Type); if (typeAndPrioityTriggers != null && typeAndPrioityTriggers.Any()) { triggers.AddRange(typeAndPrioityTriggers); } return(triggers); }
public DispatchProtocol SaveProtocol(DispatchProtocol protocol) { _dispatchProtocolRepository.SaveOrUpdate(protocol); return(protocol); }
public async Task <DispatchProtocol> SaveProtocolAsync(DispatchProtocol protocol, CancellationToken cancellationToken = default(CancellationToken)) { return(await _dispatchProtocolRepository.SaveOrUpdateAsync(protocol, cancellationToken)); }