public void Test_DiscontinueProcedure()
        {
            Order order = TestOrderFactory.CreateOrder(1, 3, true);

            // copy req procs to a list so we can access them by index
            List <Procedure> reqProcs = new List <Procedure>(
                new TypeSafeEnumerableWrapper <Procedure>(order.Procedures));
            Procedure rp1 = reqProcs[0];

            // put one mps in progress and the other completed, leaving the third scheduled
            rp1.ModalityProcedureSteps[0].Start(TestStaffFactory.CreateStaff(new StaffTypeEnum("STEC", null, null)));
            rp1.ModalityProcedureSteps[1].Complete(TestStaffFactory.CreateStaff(new StaffTypeEnum("STEC", null, null)));

            // discontinue rp1
            rp1.Discontinue();

            CheckStatus(ProcedureStatus.DC, rp1);
            Assert.IsNotNull(rp1.StartTime);
            Assert.IsNotNull(rp1.EndTime);

            // expect scheduled step was discontinued
            CheckStatus(ActivityStatus.DC, rp1.ModalityProcedureSteps[2]);
            Assert.IsNull(rp1.ModalityProcedureSteps[2].StartTime);
            Assert.IsNotNull(rp1.ModalityProcedureSteps[2].EndTime);

            // expect in-progress step was discontinued
            CheckStatus(ActivityStatus.DC, rp1.ModalityProcedureSteps[0]);
            Assert.IsNotNull(rp1.ModalityProcedureSteps[0].StartTime);
            Assert.IsNotNull(rp1.ModalityProcedureSteps[0].EndTime);

            // expect completed steps unchanged
            CheckStatus(ActivityStatus.CM, rp1.ModalityProcedureSteps[1]);
            Assert.IsNotNull(rp1.ModalityProcedureSteps[1].StartTime);
            Assert.IsNotNull(rp1.ModalityProcedureSteps[1].EndTime);
        }
        public void Test_AutoDiscontinueOrder()
        {
            Order order = TestOrderFactory.CreateOrder(2, 2, true);

            // copy req procs to a list so we can access them by index
            List <Procedure> reqProcs = new List <Procedure>(
                new TypeSafeEnumerableWrapper <Procedure>(order.Procedures));
            Procedure rp1 = reqProcs[0];
            Procedure rp2 = reqProcs[1];

            // start and discontinue rp1
            rp1.ModalityProcedureSteps[0].Start(TestStaffFactory.CreateStaff(new StaffTypeEnum("STEC", null, null)));
            rp1.Discontinue();
            Assert.IsNotNull(rp1.StartTime);
            Assert.IsNotNull(rp1.EndTime);

            // cancel rp2
            rp2.Cancel();
            Assert.IsNull(rp2.StartTime);
            Assert.IsNotNull(rp2.EndTime);

            // order should be discontinued
            CheckStatus(OrderStatus.DC, order);
            Assert.IsNotNull(order.StartTime);
            Assert.IsNotNull(order.EndTime);
        }
        public void Test_CompleteProcedureStepFromInProgress()
        {
            Order                 order = TestOrderFactory.CreateOrder(1, 1, true);
            Procedure             rp1   = CollectionUtils.FirstElement(order.Procedures);
            ModalityProcedureStep mps1  = rp1.ModalityProcedureSteps[0];

            CheckStatus(ActivityStatus.SC, mps1);

            mps1.Start(TestStaffFactory.CreateStaff(new StaffTypeEnum("STEC", null, null)));

            CheckStatus(ActivityStatus.IP, mps1);

            mps1.Complete();

            CheckStatus(ActivityStatus.CM, mps1);
            Assert.IsNotNull(mps1.StartTime);
            Assert.IsNotNull(mps1.EndTime);

            CheckStatus(ProcedureStatus.IP, rp1);
            Assert.IsNotNull(rp1.StartTime);
            Assert.IsNull(rp1.EndTime);

            CheckStatus(OrderStatus.IP, order);
            Assert.IsNotNull(order.StartTime);
            Assert.IsNull(order.EndTime);
        }
        public void Test_DiscontinueOrder()
        {
            Order order = TestOrderFactory.CreateOrder(2, 2, true);

            // copy req procs to a list so we can access them by index
            List <Procedure> reqProcs = new List <Procedure>(
                new TypeSafeEnumerableWrapper <Procedure>(order.Procedures));
            Procedure rp1 = reqProcs[0];
            Procedure rp2 = reqProcs[1];

            // start rp 1
            rp1.ModalityProcedureSteps[0].Start(TestStaffFactory.CreateStaff(new StaffTypeEnum("SCLR", null, null)));

            order.Discontinue(new OrderCancelInfo(_defaultCancelReason, TestStaffFactory.CreateStaff(new StaffTypeEnum("SCLR", null, null)), "", null));

            // rp 2 is canceled
            CheckStatus(ProcedureStatus.CA, rp2);
            Assert.IsNull(rp2.StartTime);   // rp2 was never started
            Assert.IsNotNull(rp2.EndTime);

            // rp 1 is discontinued
            CheckStatus(ProcedureStatus.DC, rp1);
            Assert.IsNotNull(rp1.StartTime);
            Assert.IsNotNull(rp1.EndTime);

            // order is discontinued
            CheckStatus(OrderStatus.DC, order);
            Assert.IsNotNull(order.StartTime);
            Assert.IsNotNull(order.EndTime);   // end-time is set because order is discontinued, even though rp1 is still in progress
        }
        public void Test_ReplaceOrderFromScheduled()
        {
            Order order = TestOrderFactory.CreateOrder(2, 2, true);

            CheckStatus(OrderStatus.SC, order);

            Order replacement = TestOrderFactory.CreateOrder(2, 2, true);

            order.Cancel(new OrderCancelInfo(_defaultCancelReason, TestStaffFactory.CreateStaff(new StaffTypeEnum("SCLR", null, null)), "", replacement));

            CheckStatus(OrderStatus.RP, order);
            Assert.IsNull(order.StartTime);
            Assert.IsNotNull(order.EndTime);

            foreach (Procedure rp in order.Procedures)
            {
                CheckStatus(ProcedureStatus.CA, rp);
                Assert.IsNull(rp.StartTime);
                Assert.IsNotNull(rp.EndTime);
                foreach (ProcedureStep step in rp.ProcedureSteps)
                {
                    CheckStatus(ActivityStatus.DC, step);
                }
            }
        }
        public void Test_CancelOrderWithCancelledProcedure()
        {
            Order order = TestOrderFactory.CreateOrder(2, 2, true);

            CheckStatus(OrderStatus.SC, order);

            // cancel one of the procedures - this will not cancel the order
            Procedure p1 = CollectionUtils.FirstElement(order.Procedures);

            p1.Cancel();

            // order is still scheduled
            CheckStatus(OrderStatus.SC, order);

            // now cancel order
            order.Cancel(new OrderCancelInfo(_defaultCancelReason, TestStaffFactory.CreateStaff(new StaffTypeEnum("SCLR", null, null)), "", null));

            CheckStatus(OrderStatus.CA, order);
            Assert.IsNull(order.StartTime);
            Assert.IsNotNull(order.EndTime);

            foreach (Procedure rp in order.Procedures)
            {
                CheckStatus(ProcedureStatus.CA, rp);
                Assert.IsNull(rp.StartTime);
                Assert.IsNotNull(rp.EndTime);
                foreach (ProcedureStep step in rp.ProcedureSteps)
                {
                    CheckStatus(ActivityStatus.DC, step);
                }
            }
        }
        public void Test_Test_AutoCompleteOrderProcedure()
        {
            Order order = TestOrderFactory.CreateOrder(2, 1, true);
            // copy req procs to a list so we can access them by index
            List <Procedure> reqProcs = new List <Procedure>(
                new TypeSafeEnumerableWrapper <Procedure>(order.Procedures));
            Procedure rp1 = reqProcs[0];
            Procedure rp2 = reqProcs[1];


            // cancel rp2
            rp2.Cancel();

            // complete rp1 and publish it
            rp1.ModalityProcedureSteps[0].Complete(TestStaffFactory.CreateStaff(new StaffTypeEnum("STEC", null, null)));

            PublicationStep pub1 = new PublicationStep();

            pub1.ReportPart = new ReportPart(new Report(), 0); // must have a report part or we get null-ref exception
            rp1.AddProcedureStep(pub1);

            pub1.Complete(TestStaffFactory.CreateStaff(new StaffTypeEnum("PRAD", null, null)));

            CheckStatus(ProcedureStatus.CA, rp2);
            Assert.IsNull(rp2.StartTime);
            Assert.IsNotNull(rp2.EndTime);

            CheckStatus(ProcedureStatus.CM, rp1);
            Assert.IsNotNull(rp1.StartTime);
            Assert.IsNotNull(rp1.EndTime);

            CheckStatus(OrderStatus.CM, order);
            Assert.IsNotNull(rp1.StartTime);
            Assert.IsNotNull(rp1.EndTime);
        }
Exemplo n.º 8
0
        public void Test_merge_order()
        {
            var patient  = TestPatientFactory.CreatePatient();
            var visit    = TestVisitFactory.CreateVisit(patient);
            var facility = TestFacilityFactory.CreateFacility();
            var order1   = TestOrderFactory.CreateOrder(patient, visit, facility, "101", 2, 1, true, true);
            var order2   = TestOrderFactory.CreateOrder(patient, visit, facility, "102", 2, 1, true, true);
            var staff    = TestStaffFactory.CreateStaff();

            // merge order1 into order2
            order1.Merge(new OrderMergeInfo(staff, DateTime.Now, order2));

            // order1 post conditions
            Assert.AreEqual(OrderStatus.MG, order1.Status);
            Assert.IsNotNull(order1.MergeInfo);
            Assert.AreEqual(order2, order1.MergeInfo.MergeDestinationOrder);
            Assert.AreEqual(staff, order1.MergeInfo.MergedBy);
            Assert.AreEqual(2, order1.Procedures.Count);
            Assert.IsTrue(CollectionUtils.TrueForAll(order1.Procedures, p => p.Status == ProcedureStatus.GH));

            // order2 post conditions
            Assert.AreEqual(OrderStatus.SC, order2.Status);
            Assert.IsNull(order2.MergeInfo);
            Assert.AreEqual(4, order2.Procedures.Count);
            Assert.IsTrue(CollectionUtils.TrueForAll(order1.Procedures, p => p.Status == ProcedureStatus.SC));
        }
        public void Test_AutoCancelOrder()
        {
            Order order = TestOrderFactory.CreateOrder(2, 2, true);

            foreach (Procedure rp in order.Procedures)
            {
                rp.Cancel();
                Assert.IsNull(rp.StartTime);
                Assert.IsNotNull(rp.EndTime);
            }

            CheckStatus(OrderStatus.CA, order);
            Assert.IsNull(order.StartTime);
            Assert.IsNotNull(order.EndTime);
        }
        public void Test_RescheduleLater()
        {
            Order order = TestOrderFactory.CreateOrder(2, 2, true, true);

            DateTime originalTime = (DateTime)order.ScheduledStartTime;
            DateTime newTime      = originalTime + TimeSpan.FromDays(1);

            Procedure     rp   = CollectionUtils.FirstElement(order.Procedures);
            ProcedureStep step = CollectionUtils.FirstElement(rp.ProcedureSteps);

            step.Schedule(newTime);

            Assert.AreEqual(newTime, step.Scheduling.StartTime);

            // verify order and rp scheduled time still reflect earliest time
            Assert.AreEqual(originalTime, rp.ScheduledStartTime);
            Assert.AreEqual(originalTime, order.ScheduledStartTime);
        }
        public void Test_AutoStartOrderProcedure()
        {
            Order order = TestOrderFactory.CreateOrder(2, 2, true);

            // put the order in progress
            Procedure     rp   = CollectionUtils.FirstElement(order.Procedures);
            ProcedureStep step = CollectionUtils.FirstElement(rp.ProcedureSteps);

            step.Start(TestStaffFactory.CreateStaff(new StaffTypeEnum("STEC", null, null)));

            // procedure is in progress
            CheckStatus(ProcedureStatus.IP, rp);
            Assert.IsNotNull(rp.StartTime);

            // order is in progress
            CheckStatus(OrderStatus.IP, order);
            Assert.IsNotNull(order.StartTime);
        }
        public void Test_ScheduleProcedureStep()
        {
            // create an unscheduled order
            Order order = TestOrderFactory.CreateOrder(1, 1, true);

            DateTime scheduleTime = DateTime.Now;

            Procedure     rp   = CollectionUtils.FirstElement(order.Procedures);
            ProcedureStep step = CollectionUtils.FirstElement(rp.ProcedureSteps);

            step.Schedule(scheduleTime);

            Assert.AreEqual(scheduleTime, step.Scheduling.StartTime);

            // verify order and rp scheduled time are updated to reflect earliest time
            Assert.AreEqual(scheduleTime, rp.ScheduledStartTime);
            Assert.AreEqual(scheduleTime, order.ScheduledStartTime);
        }
        public void Test_UnscheduleProcedureStep()
        {
            // create a scheduled order
            Order order = TestOrderFactory.CreateOrder(2, 2, true);

            // unschedule all steps
            foreach (Procedure rp in order.Procedures)
            {
                foreach (ProcedureStep step in rp.ProcedureSteps)
                {
                    step.Schedule(null);
                }
                // verify rp start time is null
                Assert.IsNull(rp.ScheduledStartTime);
            }

            // verify order start time is null
            Assert.IsNull(order.ScheduledStartTime);
        }
        public void Test_CancelProcedureFromInProgress()
        {
            try
            {
                Order order = TestOrderFactory.CreateOrder(1, 1, true);

                Procedure rp = CollectionUtils.FirstElement(order.Procedures);
                rp.ModalityProcedureSteps[0].Start(TestStaffFactory.CreateStaff(new StaffTypeEnum("STEC", null, null)));

                CheckStatus(ProcedureStatus.IP, rp);

                rp.Cancel();

                Assert.Fail("expected exception when trying to cancel in progress procedure");
            }
            catch (WorkflowException e)
            {
                Assert.IsInstanceOfType(typeof(WorkflowException), e);
            }
        }
        public void Test_CancelOrderFromInProgress()
        {
            Order order = TestOrderFactory.CreateOrder(2, 2, true);

            // put the order in progress
            Procedure     rp   = CollectionUtils.FirstElement(order.Procedures);
            ProcedureStep step = CollectionUtils.FirstElement(rp.ProcedureSteps);

            step.Start(TestStaffFactory.CreateStaff(new StaffTypeEnum("STEC", null, null)));

            try
            {
                order.Cancel(new OrderCancelInfo(_defaultCancelReason, TestStaffFactory.CreateStaff(new StaffTypeEnum("SCLR", null, null)), "", null));

                Assert.Fail("expected exception when trying to cancel non-scheduled order");
            }
            catch (Exception e)
            {
                Assert.IsInstanceOfType(typeof(WorkflowException), e);
            }
        }
        public void Test_AutoDiscontinueProcedure()
        {
            Order order = TestOrderFactory.CreateOrder(2, 2, true);

            CheckStatus(OrderStatus.SC, order);

            foreach (Procedure rp in order.Procedures)
            {
                foreach (ProcedureStep step in rp.ProcedureSteps)
                {
                    step.Discontinue();
                    CheckStatus(ActivityStatus.DC, step);
                }
                CheckStatus(ProcedureStatus.DC, rp);
                Assert.IsNull(rp.StartTime);
                Assert.IsNotNull(rp.EndTime);
            }

            CheckStatus(OrderStatus.DC, order);
            Assert.IsNull(order.StartTime);
            Assert.IsNotNull(order.EndTime);
        }
        public void Test_CancelProcedureFromScheduled()
        {
            Order order = TestOrderFactory.CreateOrder(1, 2, true);

            // copy req procs to a list so we can access them by index
            List <Procedure> reqProcs = new List <Procedure>(
                new TypeSafeEnumerableWrapper <Procedure>(order.Procedures));
            Procedure rp1 = reqProcs[0];

            rp1.Cancel();
            CheckStatus(ProcedureStatus.CA, rp1);
            Assert.IsNull(rp1.StartTime);
            Assert.IsNotNull(rp1.EndTime);

            foreach (ProcedureStep step in rp1.ProcedureSteps)
            {
                // all steps were scheduled, so they should all be discontinued
                CheckStatus(ActivityStatus.DC, step);
                Assert.IsNull(step.StartTime);
                Assert.IsNotNull(step.EndTime);
            }
        }
        public void Test_DiscontinueProcedureStep()
        {
            Order order = TestOrderFactory.CreateOrder(2, 2, true);

            CheckStatus(OrderStatus.SC, order);

            Procedure rp1 = CollectionUtils.FirstElement(order.Procedures);

            CheckStatus(ProcedureStatus.SC, rp1);

            rp1.ModalityProcedureSteps[0].Discontinue();
            CheckStatus(ActivityStatus.DC, rp1.ModalityProcedureSteps[0]);
            Assert.IsNull(rp1.ModalityProcedureSteps[0].StartTime);
            Assert.IsNotNull(rp1.ModalityProcedureSteps[0].EndTime);

            // rp and order status unchanged
            CheckStatus(ProcedureStatus.SC, rp1);
            Assert.IsNull(rp1.StartTime);
            Assert.IsNull(rp1.EndTime);

            CheckStatus(OrderStatus.SC, order);
            Assert.IsNull(order.StartTime);
            Assert.IsNull(order.EndTime);
        }
Exemplo n.º 19
0
        private Report CreateReport()
        {
            Order order = TestOrderFactory.CreateOrder(1, 1, true, true);

            return(new Report(CollectionUtils.FirstElement(order.Procedures)));
        }