Example #1
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_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_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_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_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);
        }
        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_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);
                }
            }
        }
Example #9
0
        public void Test_RevertCheckIn()
        {
            DateTime?now       = DateTime.Now;
            var      procedure = new Procedure {
                ProcedureCheckIn = new ProcedureCheckIn()
            };
            var regStep = new RegistrationProcedureStep(procedure);
            var staff   = TestStaffFactory.CreateStaff();

            procedure.CheckIn(staff, now);

            Assert.IsFalse(procedure.IsPreCheckIn);
            Assert.IsTrue(procedure.IsCheckedIn);
            Assert.IsFalse(procedure.IsCheckedOut);
            Assert.AreEqual(ActivityStatus.IP, regStep.State);
            Assert.IsNull(regStep.EndTime);

            procedure.RevertCheckIn();

            Assert.IsTrue(procedure.IsPreCheckIn);
            Assert.IsFalse(procedure.IsCheckedIn);
            Assert.IsFalse(procedure.IsCheckedOut);
            Assert.IsNull(procedure.ProcedureCheckIn.CheckInTime);
            Assert.IsNull(procedure.ProcedureCheckIn.CheckOutTime);

            // the registration step is not reverted
            Assert.AreEqual(ActivityStatus.IP, regStep.State);
            Assert.AreEqual(staff, regStep.PerformingStaff);
        }
 internal static OrderAttachment CreateOrderAttachment()
 {
     return(new OrderAttachment(
                new OrderAttachmentCategoryEnum("PD", "Pending", null),
                TestStaffFactory.CreateStaff(new StaffTypeEnum("SCLR", null, null)),
                DateTime.Now,
                TestAttachedDocumentFactory.CreateAttachedDocument()));
 }
        internal static OrderNote CreateOrderNote(string comment)
        {
            //return new OrderNote(Platform.Time, TestStaffFactory.CreateStaff(StaffType.STEC), comment);
            OrderNote note = new OrderNote();

            note.CreationTime = Platform.Time;
            note.Author       = TestStaffFactory.CreateStaff(new StaffTypeEnum("STEC", null, null));
            note.Body         = comment;
            return(note);
        }
Example #12
0
        public static Order CreateOrder(Patient patient, Visit visit, Facility facility, string accession, int numProcedures, int numMpsPerProcedure, bool createProcedureSteps, bool schedule)
        {
            var      procedureNumberBroker = new TestProcedureNumberBroker();
            var      dicomUidBroker        = new TestDicomUidBroker();
            DateTime?scheduleTime          = DateTime.Now;

            DiagnosticService    ds             = TestDiagnosticServiceFactory.CreateDiagnosticService(numProcedures);
            string               reasonForStudy = "Test";
            ExternalPractitioner orderingPrac   = TestExternalPractitionerFactory.CreatePractitioner();

            Order order = Order.NewOrder(new OrderCreationArgs(
                                             Platform.Time,
                                             TestStaffFactory.CreateStaff(new StaffTypeEnum("SCLR", null, null)),
                                             null,
                                             accession,
                                             patient,
                                             visit,
                                             ds,
                                             reasonForStudy,
                                             OrderPriority.R,
                                             facility,
                                             facility,
                                             scheduleTime,
                                             orderingPrac,
                                             new List <ResultRecipient>()),
                                         procedureNumberBroker,
                                         dicomUidBroker);

            if (createProcedureSteps)
            {
                foreach (Procedure proc in order.Procedures)
                {
                    AddProcedureSteps(proc, numMpsPerProcedure);
                }
            }

            DateTime dt = DateTime.Now;

            if (schedule)
            {
                foreach (Procedure proc in order.Procedures)
                {
                    proc.Schedule(dt);
                }
            }

            return(order);
        }
        public void Test_CreateNewOrderScheduled()
        {
            DateTime scheduleTime = DateTime.Now;

            Patient              patient        = TestPatientFactory.CreatePatient();
            Visit                visit          = TestVisitFactory.CreateVisit(patient);
            DiagnosticService    ds             = TestDiagnosticServiceFactory.CreateDiagnosticService();
            string               accession      = "10000001";
            string               reasonForStudy = "Test";
            ExternalPractitioner orderingPrac   = TestExternalPractitionerFactory.CreatePractitioner();
            Facility             facility       = TestFacilityFactory.CreateFacility();

            Order order = Order.NewOrder(new OrderCreationArgs(Platform.Time, TestStaffFactory.CreateStaff(new StaffTypeEnum("SCLR", null, null)), null,
                                                               accession, patient, visit, ds, reasonForStudy, OrderPriority.R, facility, facility,
                                                               scheduleTime, orderingPrac, new List <ResultRecipient>()), new TestProcedureNumberBroker(), new TestDicomUidBroker());

            // check basics
            Assert.AreEqual(accession, order.AccessionNumber);
            Assert.AreEqual(reasonForStudy, order.ReasonForStudy);
            Assert.AreEqual(patient, order.Patient);
            Assert.AreEqual(visit, order.Visit);
            Assert.AreEqual(ds, order.DiagnosticService);
            Assert.AreEqual(scheduleTime, order.SchedulingRequestTime);
            Assert.AreEqual(null, order.ScheduledStartTime); // because the order has not been scheduled
            Assert.AreEqual(null, order.StartTime);          // because the order has not been started
            Assert.AreEqual(null, order.EndTime);            // because the order has not been completed
            Assert.AreEqual(orderingPrac, order.OrderingPractitioner);
            Assert.AreEqual(facility, order.OrderingFacility);
            Assert.AreEqual(OrderPriority.R, order.Priority);
            CheckStatus(OrderStatus.SC, order);

            // check that diagnostic service plan was copied properly
            Assert.AreEqual(ds.ProcedureTypes.Count, order.Procedures.Count);
            foreach (Procedure rp in order.Procedures)
            {
                CheckStatus(ProcedureStatus.SC, rp);

                ProcedureType rpType = CollectionUtils.SelectFirst(ds.ProcedureTypes,
                                                                   delegate(ProcedureType rpt) { return(rpt.Equals(rp.Type)); });

                Assert.IsNotNull(rpType, "diagnostic service plan not copied correctly");
                foreach (ModalityProcedureStep mps in rp.ModalityProcedureSteps)
                {
                    CheckStatus(ActivityStatus.SC, mps);
                }
            }
        }
        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_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);
            }
        }