コード例 #1
0
            public void should_be_null_for_out_of_band_start_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(14);
                trigger1.EndsOn   = DateTime.UtcNow.AddDays(147);
                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().BeNull();
            }
コード例 #2
0
ファイル: ProtocolsController.cs プロジェクト: Resgrid/Core
        public async Task <IActionResult> New(NewProtocolModel model, IFormCollection form, ICollection <IFormFile> attachments)
        {
            if (attachments != null)
            {
                model.Protocol.Attachments = new Collection <DispatchProtocolAttachment>();
                foreach (var file in attachments)
                {
                    if (file != null && file.Length > 0)
                    {
                        var extenion = file.FileName.Substring(file.FileName.IndexOf(char.Parse(".")) + 1,
                                                               file.FileName.Length - file.FileName.IndexOf(char.Parse(".")) - 1);

                        if (!String.IsNullOrWhiteSpace(extenion))
                        {
                            extenion = extenion.ToLower();
                        }

                        if (extenion != "jpg" && extenion != "jpeg" && extenion != "png" && extenion != "gif" && extenion != "gif" &&
                            extenion != "pdf" && extenion != "doc" &&
                            extenion != "docx" && extenion != "ppt" && extenion != "pptx" && extenion != "pps" && extenion != "ppsx" &&
                            extenion != "odt" &&
                            extenion != "xls" && extenion != "xlsx" && extenion != "txt" && extenion != "mpg" && extenion != "avi" &&
                            extenion != "mpeg")
                        {
                            ModelState.AddModelError("fileToUpload", string.Format("File type ({0}) is not importable.", extenion));
                        }

                        if (file.Length > 30000000)
                        {
                            ModelState.AddModelError("fileToUpload", "Attachment is too large, must be smaller then 30MB.");
                        }

                        var attachment = new DispatchProtocolAttachment();
                        attachment.FileType = file.ContentType;
                        attachment.FileName = file.FileName;

                        var uploadedFile = new byte[file.OpenReadStream().Length];
                        file.OpenReadStream().Read(uploadedFile, 0, uploadedFile.Length);

                        attachment.Data = uploadedFile;
                        model.Protocol.Attachments.Add(attachment);
                    }
                }
            }

            model.Protocol.CreatedByUserId = UserId;
            model.Protocol.UpdatedByUserId = UserId;

            if (ModelState.IsValid)
            {
                List <int> triggers = (from object key in form.Keys
                                       where key.ToString().StartsWith("triggerType_")
                                       select int.Parse(key.ToString().Replace("triggerType_", ""))).ToList();

                if (triggers.Count > 0)
                {
                    model.Protocol.Triggers = new Collection <DispatchProtocolTrigger>();
                }

                model.Protocol.DepartmentId    = DepartmentId;
                model.Protocol.CreatedOn       = DateTime.UtcNow;
                model.Protocol.CreatedByUserId = UserId;
                model.Protocol.UpdatedOn       = DateTime.UtcNow;
                model.Protocol.UpdatedByUserId = UserId;
                model.Protocol.Code            = model.Protocol.Code.ToUpper();

                foreach (var i in triggers)
                {
                    if (form.ContainsKey("triggerType_" + i))
                    {
                        var triggerType         = int.Parse(form["triggerType_" + i]);
                        var triggerStartsOn     = form["triggerStartsOn_" + i];
                        var triggerEndsOn       = form["triggerEndsOn_" + i];
                        var triggerCallPriotity = int.Parse(form["triggerCallPriority_" + i]);
                        var triggerCallType     = form["triggerCallType_" + i];

                        var trigger = new DispatchProtocolTrigger();
                        trigger.Type = triggerType;

                        if (!String.IsNullOrWhiteSpace(triggerStartsOn))
                        {
                            trigger.StartsOn = DateTime.Parse(triggerStartsOn);
                        }

                        if (!String.IsNullOrWhiteSpace(triggerEndsOn))
                        {
                            trigger.EndsOn = DateTime.Parse(triggerEndsOn);
                        }

                        trigger.Priority = triggerType;
                        trigger.CallType = triggerCallType;

                        model.Protocol.Triggers.Add(trigger);
                    }
                }

                List <int> questions = (from object key in form.Keys where key.ToString().StartsWith("question_") select int.Parse(key.ToString().Replace("question_", ""))).ToList();

                if (questions.Count > 0)
                {
                    model.Protocol.Questions = new Collection <DispatchProtocolQuestion>();
                }

                foreach (var i in questions)
                {
                    if (form.ContainsKey("question_" + i))
                    {
                        var questionText = form["question_" + i];
                        var question     = new DispatchProtocolQuestion();
                        question.Question = questionText;

                        List <int> answers = (from object key in form.Keys where key.ToString().StartsWith("answerForQuestion_" + i + "_") select int.Parse(key.ToString().Replace("answerForQuestion_" + i + "_", ""))).ToList();

                        if (answers.Count > 0)
                        {
                            question.Answers = new Collection <DispatchProtocolQuestionAnswer>();
                        }

                        foreach (var answer in answers)
                        {
                            var trainingQuestionAnswer = new DispatchProtocolQuestionAnswer();
                            var answerForQuestion      = form["answerForQuestion_" + i + "_" + answer];

                            var weight = form["weightForAnswer_" + i + "_" + answer];
                            trainingQuestionAnswer.Answer = answerForQuestion;

                            if (!string.IsNullOrWhiteSpace(weight))
                            {
                                trainingQuestionAnswer.Weight = int.Parse(weight);
                            }

                            question.Answers.Add(trainingQuestionAnswer);
                        }

                        model.Protocol.Questions.Add(question);
                    }
                }


                await _protocolsService.SaveProtocolAsync(model.Protocol);

                return(RedirectToAction("Index"));
            }

            return(View(model));
        }