Esempio n. 1
0
        protected static ExternalPractitioner ParseOrderingPhysicianFromVisit(Visit visit)
        {
            ExternalPractitioner attending = null;
            ExternalPractitioner admitting = null;
            ExternalPractitioner referring = null;

            foreach (var p in visit.Practitioners.Where(p => !p.EndTime.HasValue))
            {
                switch (p.Role)
                {
                case VisitPractitionerRole.RF:
                    referring = p.Practitioner;
                    break;

                case VisitPractitionerRole.AT:
                    attending = p.Practitioner;
                    break;

                case VisitPractitionerRole.AD:
                    admitting = p.Practitioner;
                    break;
                }
            }
            var orderingPhysician = attending ?? admitting ?? referring;

            if (orderingPhysician == null)
            {
                throw new Exception("Couldn't find ordering physician");
            }
            return(orderingPhysician);
        }
Esempio n. 2
0
        private static T QueryVisits <T>(ExternalPractitioner practitioner, Converter <VisitSearchCriteria, VisitPractitionerSearchCriteria, T> queryAction)
        {
            var visitsWhere = new VisitPractitionerSearchCriteria();

            visitsWhere.Practitioner.EqualTo(practitioner);
            return(queryAction(new VisitSearchCriteria(), visitsWhere));
        }
Esempio n. 3
0
		private static ExternalPractitionerSearchCriteria[] GetMergeCandidatesCriteria(ExternalPractitioner practitioner)
		{
			var criteria = new List<ExternalPractitionerSearchCriteria>();

			var baseCriteria = new ExternalPractitionerSearchCriteria();
			baseCriteria.NotEqualTo(practitioner);
			baseCriteria.Deactivated.EqualTo(false);

			var nameCriteria = (ExternalPractitionerSearchCriteria)baseCriteria.Clone();
			nameCriteria.Name.FamilyName.EqualTo(practitioner.Name.FamilyName);
			nameCriteria.Name.GivenName.EqualTo(practitioner.Name.GivenName);
			criteria.Add(nameCriteria);

			if (!string.IsNullOrEmpty(practitioner.LicenseNumber))
			{
				var licenseNumberCriteria = (ExternalPractitionerSearchCriteria)baseCriteria.Clone();
				licenseNumberCriteria.LicenseNumber.EqualTo(practitioner.LicenseNumber);
				criteria.Add(licenseNumberCriteria);
			}

			if (!string.IsNullOrEmpty(practitioner.BillingNumber))
			{
				var billingNumberCriteria = (ExternalPractitionerSearchCriteria)baseCriteria.Clone();
				billingNumberCriteria.BillingNumber.EqualTo(practitioner.BillingNumber);
				criteria.Add(billingNumberCriteria);
			}

			return criteria.ToArray();
		}
            public override AlertNotification Test(ExternalPractitioner entity, IPersistenceContext context)
            {
                var broker = context.GetBroker <IExternalPractitionerBroker>();
                var count  = broker.CountMergeCandidates(entity);

                return(count > 0 ? new AlertNotification(this.Id, new string[] { }) : null);
            }
Esempio n. 5
0
        protected ExternalPractitioner AddPractitioner(string practitionerId, string givenName, string familyName)
        {
            var practitioner = GetPractitioner(practitionerId);

            if (practitioner != null)
            {
                return(practitioner);
            }
            if (practitionerId == null || givenName == null || familyName == null)
            {
                throw new Exception("Practitioner is not valid");
            }

            var addedPractitioner = new ExternalPractitioner
            {
                LicenseNumber = practitionerId,
                Name          = { FamilyName = familyName, GivenName = givenName }
            };

            addedPractitioner.ExtendedProperties.Add("Comment", "HL7");
            var contactPoint = new ExternalPractitionerContactPoint(addedPractitioner)
            {
                IsDefaultContactPoint = true,
                Name        = "Default",
                Description = "HL7"
            };

            PersistenceContext.Lock(addedPractitioner, DirtyState.New);
            PersistenceContext.Lock(contactPoint, DirtyState.New);
            return(addedPractitioner);
        }
        public void Test_Merged_Default_Contact_Point()
        {
            var pA    = TestHelper.CreatePractitioner("A", "1");
            var cpPA1 = ExternalPractitionerContactPointTests.TestHelper.AddContactPoint(pA, "cpPA1", "cpPA1");
            var cpPA2 = ExternalPractitionerContactPointTests.TestHelper.AddContactPoint(pA, "cpPA2", "cpPA2");

            Assert.IsTrue(cpPA1.IsDefaultContactPoint);             // oroginal default
            Assert.IsFalse(cpPA2.IsDefaultContactPoint);

            var pB    = TestHelper.CreatePractitioner("B", "2");
            var cpPB1 = ExternalPractitionerContactPointTests.TestHelper.AddContactPoint(pB, "cpPB1", "cpPB1");
            var cpPB2 = ExternalPractitionerContactPointTests.TestHelper.AddContactPoint(pB, "cpPB2", "cpPB2");

            Assert.IsTrue(cpPB1.IsDefaultContactPoint);
            Assert.IsFalse(cpPB2.IsDefaultContactPoint);

            var newDefault   = cpPB2;
            var deactivated  = new List <ExternalPractitionerContactPoint>();                                         // None
            var replacements = new Dictionary <ExternalPractitionerContactPoint, ExternalPractitionerContactPoint>(); // None
            var result       = ExternalPractitioner.MergePractitioners(pA, pB,
                                                                       pA.Name, pA.LicenseNumber, pA.BillingNumber, pA.ExtendedProperties,
                                                                       newDefault, deactivated, replacements);
            var result_cpPA1 = CollectionUtils.SelectFirst(result.ContactPoints, cp => cp.Name == newDefault.Name);

            Assert.AreEqual(result.ContactPoints.Count, 4);
            Assert.IsTrue(result_cpPA1.IsDefaultContactPoint);             // new default with the same content
        }
        public void Test_Merge_With_Merged_Default_ContactPoint()
        {
            var p1  = TestHelper.CreatePractitioner("A", "1");
            var cp1 = ExternalPractitionerContactPointTests.TestHelper.AddContactPoint(p1, "cp1", "cp1");
            var cp2 = ExternalPractitionerContactPointTests.TestHelper.AddContactPoint(p1, "cp2", "cp2");

            // Merge into cp12, change name and description for easy identification.
            var cp12 = ExternalPractitionerContactPointTests.TestHelper.SimpleMerge(cp1, cp2);

            cp12.Name        = "cp12";
            cp12.Description = "cp12";

            // This test does the following:
            // cp1 - a merged cp that is chosen as new default
            // cp2 - merged, deactivated
            // cp12 - previous default
            var newDefault   = cp1;
            var deactivated  = new List <ExternalPractitionerContactPoint>();
            var replacements = new Dictionary <ExternalPractitionerContactPoint, ExternalPractitionerContactPoint>();

            var p2 = TestHelper.CreatePractitioner("B", "2");

            ExternalPractitioner.MergePractitioners(p1, p2,
                                                    p2.Name, p2.LicenseNumber, p2.BillingNumber, p2.ExtendedProperties,
                                                    newDefault, deactivated, replacements);
        }
			/// <summary>
			/// Perform a simple merge of two practitioners.
			/// </summary>
			/// <remarks>
			/// Destination is the primary practitioner.  The result will have all info inherit from destination.
			/// No contact points are deactivated or replaced.
			/// </remarks>
			public static ExternalPractitioner SimpleMerge(ExternalPractitioner src, ExternalPractitioner dest)
			{
				var deactivatedContactPoints = new List<ExternalPractitionerContactPoint>();
				var contactPointReplacements = new Dictionary<ExternalPractitionerContactPoint, ExternalPractitionerContactPoint>();
				return ExternalPractitioner.MergePractitioners(src, dest,
					dest.Name, dest.LicenseNumber, dest.BillingNumber, 
					dest.ExtendedProperties, dest.DefaultContactPoint,
					deactivatedContactPoints, contactPointReplacements);
			}
        private void SetPhysician(PV1 pv1, string role, ExternalPractitioner practitioner)
        {
            XCN physician = ParseRole(role, pv1);

            if (physician == null)
            {
                return;
            }
            SetPhysician(physician, GetPhysicianDetails(practitioner));
        }
            /// <summary>
            /// Perform a simple merge of two practitioners.
            /// </summary>
            /// <remarks>
            /// Destination is the primary practitioner.  The result will have all info inherit from destination.
            /// No contact points are deactivated or replaced.
            /// </remarks>
            public static ExternalPractitioner SimpleMerge(ExternalPractitioner src, ExternalPractitioner dest)
            {
                var deactivatedContactPoints = new List <ExternalPractitionerContactPoint>();
                var contactPointReplacements = new Dictionary <ExternalPractitionerContactPoint, ExternalPractitionerContactPoint>();

                return(ExternalPractitioner.MergePractitioners(src, dest,
                                                               dest.Name, dest.LicenseNumber, dest.BillingNumber,
                                                               dest.ExtendedProperties, dest.DefaultContactPoint,
                                                               deactivatedContactPoints, contactPointReplacements));
            }
        public void Test_Deactivate_And_Replace_Contact_Point_2()
        {
            var pA    = TestHelper.CreatePractitioner("A", "1");
            var cpPA1 = ExternalPractitionerContactPointTests.TestHelper.AddContactPoint(pA, "cpPA1", "cpPA1");
            var cpPA2 = ExternalPractitionerContactPointTests.TestHelper.AddContactPoint(pA, "cpPA2", "cpPA2");

            var pB    = TestHelper.CreatePractitioner("B", "2");
            var cpPB1 = ExternalPractitionerContactPointTests.TestHelper.AddContactPoint(pB, "cpPB1", "cpPB1");
            var cpPB2 = ExternalPractitionerContactPointTests.TestHelper.AddContactPoint(pB, "cpPB2", "cpPB2");

            // This test does the following:
            // cpPA1 - no-op, simply migrated
            // cpPA2 - deactivated and replaced
            // cpPB1 - no-op, simply migrated
            // cpPB2 - new default and new replacement
            var newDefault  = cpPB2;
            var deactivated = new List <ExternalPractitionerContactPoint> {
                cpPA2
            };
            var replacements = new Dictionary <ExternalPractitionerContactPoint, ExternalPractitionerContactPoint>
            {
                { cpPA2, cpPB2 }
            };

            var result = ExternalPractitioner.MergePractitioners(pA, pB,
                                                                 pA.Name, pA.LicenseNumber, pA.BillingNumber, pA.ExtendedProperties,
                                                                 newDefault, deactivated, replacements);

            var result_cpPA1 = CollectionUtils.SelectFirst(result.ContactPoints, cp => cp.Name == cpPA1.Name);
            var result_cpPA2 = CollectionUtils.SelectFirst(result.ContactPoints, cp => cp.Name == cpPA2.Name);
            var result_cpPB1 = CollectionUtils.SelectFirst(result.ContactPoints, cp => cp.Name == cpPB1.Name);
            var result_cpPB2 = CollectionUtils.SelectFirst(result.ContactPoints, cp => cp.Name == cpPB2.Name);

            Assert.AreEqual(result.ContactPoints.Count, 3);
            Assert.IsNotNull(result_cpPA1);
            Assert.IsNull(result_cpPA2);             // replaced
            Assert.IsNotNull(result_cpPB1);
            Assert.IsNotNull(result_cpPB2);

            // Check default
            Assert.IsTrue(result_cpPB2.IsDefaultContactPoint);

            // Check deactivated status.  All are active, because the only deactivated cp is replaced.
            Assert.IsFalse(result_cpPA1.Deactivated);
            Assert.IsFalse(result_cpPB1.Deactivated);
            Assert.IsFalse(result_cpPB2.Deactivated);

            // Check MergedInto
            Assert.AreEqual(cpPA1.MergedInto, result_cpPA1);
            Assert.AreEqual(cpPA2.MergedInto, result_cpPB2);             // Replaced
            Assert.AreEqual(cpPB1.MergedInto, result_cpPB1);
            Assert.AreEqual(cpPB2.MergedInto, result_cpPB2);
        }
			public override AlertNotification Test(ExternalPractitioner entity, IPersistenceContext context)
			{
				var reasons = new List<string>();

				TestName(entity.Name, ref reasons);

				if (string.IsNullOrEmpty(entity.LicenseNumber))
					reasons.Add(SR.AlertExternalPractitionerLicenseNumberMissing);

				if (string.IsNullOrEmpty(entity.BillingNumber))
					reasons.Add(SR.AlertExternalPractitionerBillingNumberMissing);

				return reasons.Count > 0 ? new AlertNotification(this.Id, reasons) : null;
			}
Esempio n. 13
0
            /// <summary>
            /// Add a contact point to a practitioner with the specified name and description.
            /// </summary>
            /// <remarks>
            /// No telephone/address/emails are added to the new contact point
            /// </remarks>
            public static ExternalPractitionerContactPoint AddContactPoint(ExternalPractitioner p, string name, string description)
            {
                var isDefault = p.ContactPoints.Count == 0;
                var cp        = new ExternalPractitionerContactPoint(p,
                                                                     name, description,
                                                                     ResultCommunicationMode.ANY, null, isDefault,
                                                                     new List <TelephoneNumber>(),
                                                                     new List <Address>(),
                                                                     new List <EmailAddress>(), null);

                p.ContactPoints.Add(cp);

                return(cp);
            }
Esempio n. 14
0
        private long EstimateAffectedRecords(ExternalPractitioner right, ExternalPractitioner left)
        {
            var rightOrderCount = QueryOrders <long>(right.ContactPoints, PersistenceContext.GetBroker <IOrderBroker>().CountByResultRecipient);
            var rightVisitCount = QueryVisits <long>(right, PersistenceContext.GetBroker <IVisitBroker>().CountByVisitPractitioner);
            var leftOrderCount  = QueryOrders <long>(left.ContactPoints, PersistenceContext.GetBroker <IOrderBroker>().CountByResultRecipient);
            var leftVisitCount  = QueryVisits <long>(left, PersistenceContext.GetBroker <IVisitBroker>().CountByVisitPractitioner);

            // total number of references
            var r = rightOrderCount + rightVisitCount;
            var l = leftOrderCount + leftVisitCount;

            // the cost is measured in terms of the total number of references that must be updated
            return(r + l);
        }
Esempio n. 15
0
        private string[] GetPhysicianDetails(ExternalPractitioner practitioner)
        {
            if (practitioner == null)
            {
                return(null);
            }
            var details = new[]
            {
                practitioner.LicenseNumber, practitioner.Name.FamilyName, practitioner.Name.GivenName,
                practitioner.Name.MiddleName
            };

            return(details);
        }
			/// <summary>
			/// Add a contact point to a practitioner with the specified name and description.
			/// </summary>
			/// <remarks>
			/// No telephone/address/emails are added to the new contact point
			/// </remarks>
			public static ExternalPractitionerContactPoint AddContactPoint(ExternalPractitioner p, string name, string description)
			{
				var isDefault = p.ContactPoints.Count == 0;
				var cp = new ExternalPractitionerContactPoint(p,
					name, description, 
					ResultCommunicationMode.ANY, null, isDefault,
					new List<TelephoneNumber>(),
					new List<Address>(),
					new List<EmailAddress>(), null);

				p.ContactPoints.Add(cp);

				return cp;
			}
        public ExternalPractitionerSummary CreateExternalPractitionerSummary(ExternalPractitioner prac, IPersistenceContext context)
        {
            var summary = new ExternalPractitionerSummary(
                prac.GetRef(),
                new PersonNameAssembler().CreatePersonNameDetail(prac.Name),
                prac.LicenseNumber,
                prac.BillingNumber,
                prac.IsVerified,
                prac.LastVerifiedTime,
                prac.LastEditedTime,
                prac.IsMerged,
                prac.Deactivated);

            return(summary);
        }
Esempio n. 18
0
            public override AlertNotification Test(ExternalPractitioner entity, IPersistenceContext context)
            {
                var reasons = new List <string>();

                if (entity.ContactPoints == null || entity.ContactPoints.Count == 0)
                {
                    reasons.Add(SR.AlertContactPointsMissing);
                }
                else
                {
                    TestContactPoints(entity.ContactPoints, ref reasons);
                }

                return(reasons.Count > 0 ? new AlertNotification(this.Id, reasons) : null);
            }
			public override AlertNotification Test(ExternalPractitioner entity, IPersistenceContext context)
			{
				var reasons = new List<string>();

				if (entity.ContactPoints == null || entity.ContactPoints.Count == 0)
				{
					reasons.Add(SR.AlertContactPointsMissing);
				}
				else
				{
					TestContactPoints(entity.ContactPoints, ref reasons);
				}

				return reasons.Count > 0 ? new AlertNotification(this.Id, reasons) : null;
			}
Esempio n. 20
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);
                }
            }
        }
Esempio n. 22
0
            public override AlertNotification Test(ExternalPractitioner entity, IPersistenceContext context)
            {
                var reasons = new List <string>();

                TestName(entity.Name, ref reasons);

                if (string.IsNullOrEmpty(entity.LicenseNumber))
                {
                    reasons.Add(SR.AlertExternalPractitionerLicenseNumberMissing);
                }

                if (string.IsNullOrEmpty(entity.BillingNumber))
                {
                    reasons.Add(SR.AlertExternalPractitionerBillingNumberMissing);
                }

                return(reasons.Count > 0 ? new AlertNotification(this.Id, reasons) : null);
            }
        public ExternalPractitionerDetail CreateExternalPractitionerDetail(ExternalPractitioner prac, IPersistenceContext context)
        {
            var assembler = new PersonNameAssembler();

            var sortedContactPoints = CollectionUtils.Sort(prac.ContactPoints, (x, y) =>
            {
                if (ReferenceEquals(x, y))
                {
                    return(0);
                }
                if (x.IsDefaultContactPoint)
                {
                    return(-1);
                }
                if (y.IsDefaultContactPoint)
                {
                    return(1);
                }
                return(string.Compare(x.Name, y.Name));
            });

            var contactPointDetails = CollectionUtils.Map(
                sortedContactPoints,
                (ExternalPractitionerContactPoint cp) => CreateExternalPractitionerContactPointDetail(cp, context));

            var detail = new ExternalPractitionerDetail(
                prac.GetRef(),
                assembler.CreatePersonNameDetail(prac.Name),
                prac.LicenseNumber,
                prac.BillingNumber,
                prac.IsVerified,
                prac.LastVerifiedTime,
                prac.LastEditedTime,
                contactPointDetails,
                ExtendedPropertyUtils.Copy(prac.ExtendedProperties),
                CreateExternalPractitionerSummary(prac.GetUltimateMergeDestination(), context),
                prac.IsMerged,
                prac.Deactivated);

            return(detail);
        }
        public void Test_Merge_With_No_Default_Contact_Point()
        {
            var p1  = TestHelper.CreatePractitioner("A", "1");
            var cp1 = ExternalPractitionerContactPointTests.TestHelper.AddContactPoint(p1, "cp1", "cp1");

            Assert.AreEqual(p1.DefaultContactPoint, cp1);

            var p2 = TestHelper.CreatePractitioner("B", "2");

            Assert.IsNull(p2.DefaultContactPoint);

            var deactivatedContactPoints = new List <ExternalPractitionerContactPoint>();
            var contactPointReplacements = new Dictionary <ExternalPractitionerContactPoint, ExternalPractitionerContactPoint>();
            var result = ExternalPractitioner.MergePractitioners(p1, p2,
                                                                 p2.Name, p2.LicenseNumber, p2.BillingNumber,
                                                                 p2.ExtendedProperties, p2.DefaultContactPoint,
                                                                 deactivatedContactPoints, contactPointReplacements);

            Assert.AreEqual(result.ContactPoints.Count, 1);
            Assert.IsNull(result.DefaultContactPoint);
        }
Esempio n. 25
0
        protected ExternalPractitioner GetPractitioner(string practitionerId)
        {
            if (practitionerId == null)
            {
                return(null);
            }
            ExternalPractitioner externalPractitioner = null;
            var searchCriteria = new ExternalPractitionerSearchCriteria();

            searchCriteria.LicenseNumber.EqualTo(practitionerId);
            searchCriteria.Deactivated.EqualTo(false);
            try
            {
                externalPractitioner = PersistenceContext.GetBroker <IExternalPractitionerBroker>().FindOne(searchCriteria);
            }
            catch (EntityNotFoundException)
            {
            }

            return(externalPractitioner);
        }
        public void UpdateExternalPractitioner(ExternalPractitionerDetail detail, ExternalPractitioner prac, IPersistenceContext context)
        {
            // validate that only one contact point is specified as default
            var defaultPoints = CollectionUtils.Select(detail.ContactPoints, cp => cp.IsDefaultContactPoint);

            if (defaultPoints.Count > 1)
            {
                throw new RequestValidationException(SR.ExceptionOneDefaultContactPoint);
            }

            var assembler = new PersonNameAssembler();

            assembler.UpdatePersonName(detail.Name, prac.Name);

            prac.LicenseNumber = detail.LicenseNumber;
            prac.BillingNumber = detail.BillingNumber;
            prac.MarkDeactivated(detail.Deactivated);

            // update contact points collection
            var syncHelper = new CollectionSynchronizeHelper <ExternalPractitionerContactPoint, ExternalPractitionerContactPointDetail>(
                delegate(ExternalPractitionerContactPoint cp, ExternalPractitionerContactPointDetail cpDetail)
            {
                // ignore version in this comparison - deal with this issue in the update delegate
                return(cp.GetRef().Equals(cpDetail.ContactPointRef, true));
            },
                delegate(ExternalPractitionerContactPointDetail cpDetail, ICollection <ExternalPractitionerContactPoint> cps)
            {
                // create a new contact point
                var cp = new ExternalPractitionerContactPoint(prac);
                UpdateExternalPractitionerContactPoint(cpDetail, cp, context);
                cps.Add(cp);
            },
                (cp, cpDetail, cps) => UpdateExternalPractitionerContactPoint(cpDetail, cp, context),
                (cp, cps) => cps.Remove(cp));

            syncHelper.Synchronize(prac.ContactPoints, detail.ContactPoints);

            ExtendedPropertyUtils.Update(prac.ExtendedProperties, detail.ExtendedProperties);
        }
Esempio n. 27
0
        public AddExternalPractitionerResponse AddExternalPractitioner(AddExternalPractitionerRequest request)
        {
            var prac = new ExternalPractitioner();

            var assembler = new ExternalPractitionerAssembler();

            assembler.UpdateExternalPractitioner(request.PractitionerDetail, prac, PersistenceContext);

            prac.MarkEdited();
            var userCanVerify = Thread.CurrentPrincipal.IsInRole(AuthorityTokens.Admin.Data.ExternalPractitionerVerification);

            if (request.MarkVerified && userCanVerify)
            {
                prac.MarkVerified();
            }

            PersistenceContext.Lock(prac, DirtyState.New);

            // ensure the new prac is assigned an OID before using it in the return value
            PersistenceContext.SynchState();

            return(new AddExternalPractitionerResponse(assembler.CreateExternalPractitionerSummary(prac, PersistenceContext)));
        }
Esempio n. 28
0
 private void SetPhysician(XCN physician, ExternalPractitioner practitioner)
 {
     SetPhysician(physician, GetPhysicianDetails(practitioner));
 }
Esempio n. 29
0
        /// <summary>
        /// Import external practitioner from CSV format.
        /// </summary>
        /// <param name="rows">
        /// Each string in the list must contain 25 CSV fields, as follows:
        ///     0 - FamilyName
        ///     1 - GivenName
        ///     2 - MiddleName
        ///     3 - Prefix
        ///     4 - Suffix
        ///     5 - Degree
        ///     6 - LicenseNumber
        ///     7 - BillingNumber
        ///     8 - Street
        ///     9 - Unit
        ///     10 - City
        ///     11 - Province
        ///     12 - PostalCode
        ///     13 - Country
        ///     14 - ValidFrom
        ///     15 - ValidUntil
        ///     16 - Phone CountryCode
        ///     17 - Phone AreaCode
        ///     18 - Phone Number
        ///     19 - Phone Extension
        ///     20 - ValidFrom
        ///     21 - ValidUntil
        ///     22 - Fax CountryCode
        ///     23 - Fax AreaCode
        ///     24 - Fax Number
        ///     25 - Fax Extension
        ///     26 - ValidFrom
        ///     27 - ValidUntil
        /// </param>
        /// <param name="context"></param>
        public override void Import(List <string> rows, IUpdateContext context)
        {
            _context = context;

            var importedEPs = new List <ExternalPractitioner>();
            var validator   = new DomainObjectValidator();

            foreach (var row in rows)
            {
                var fields = ParseCsv(row, _numFields);

                var epFamilyName = fields[0];
                var epGivenName  = fields[1];
                var epMiddlename = fields[2];
                var epPrefix     = fields[3];
                var epSuffix     = fields[4];
                var epDegree     = fields[5];

                var epLicense       = fields[6];
                var epBillingNumber = fields[7];

                var addressStreet     = fields[8];
                var addressUnit       = fields[9];
                var addressCity       = fields[10];
                var addressProvince   = fields[11];
                var addressPostalCode = fields[12];
                var addressCountry    = fields[13];

                var addressValidFrom  = ParseDateTime(fields[14]);
                var addressValidUntil = ParseDateTime(fields[15]);

                var phoneCountryCode = fields[16];
                var phoneAreaCode    = fields[17];
                var phoneNumber      = fields[18];
                var phoneExtension   = fields[19];
                var phoneValidFrom   = ParseDateTime(fields[20]);
                var phoneValidUntil  = ParseDateTime(fields[21]);

                var faxCountryCode = fields[22];
                var faxAreaCode    = fields[23];
                var faxNumber      = fields[24];
                var faxExtension   = fields[25];
                var faxValidFrom   = ParseDateTime(fields[26]);
                var faxValidUntil  = ParseDateTime(fields[27]);


                ExternalPractitioner ep = GetExternalPracitioner(epLicense, importedEPs);

                if (ep != null)
                {
                    continue;
                }

                ep = new ExternalPractitioner {
                    LicenseNumber = epLicense, BillingNumber = epBillingNumber
                };
                ep.Name = new PersonName(epFamilyName, epGivenName, epMiddlename, epPrefix, epSuffix, epDegree);

                // create a single default contact point
                var contactPoint = new ExternalPractitionerContactPoint(ep)
                {
                    Name = "Default", IsDefaultContactPoint = true
                };

                try
                {
                    var epAddress = new Address(
                        addressStreet,
                        addressUnit,
                        addressCity,
                        addressProvince,
                        addressPostalCode,
                        addressCountry,
                        AddressType.B,
                        new DateTimeRange(addressValidFrom, addressValidUntil));
                    validator.Validate(epAddress);
                    contactPoint.Addresses.Add(epAddress);
                }
                catch (EntityValidationException)
                {
                    /* invalid address - ignore */
                }

                try
                {
                    var epTelephone = new TelephoneNumber(
                        phoneCountryCode,
                        phoneAreaCode,
                        phoneNumber,
                        phoneExtension,
                        TelephoneUse.WPN,
                        TelephoneEquipment.PH,
                        new DateTimeRange(phoneValidFrom, phoneValidUntil));

                    validator.Validate(epTelephone);
                    contactPoint.TelephoneNumbers.Add(epTelephone);
                }
                catch (EntityValidationException)
                {
                    /* invalid phone - ignore */
                }

                try
                {
                    var epFax = new TelephoneNumber(
                        faxCountryCode,
                        faxAreaCode,
                        faxNumber,
                        faxExtension,
                        TelephoneUse.WPN,
                        TelephoneEquipment.FX,
                        new DateTimeRange(faxValidFrom, faxValidUntil));

                    validator.Validate(epFax);
                    contactPoint.TelephoneNumbers.Add(epFax);
                }
                catch (EntityValidationException)
                {
                    /* invalid fax - ignore */
                }

                _context.Lock(ep, DirtyState.New);

                importedEPs.Add(ep);
            }
        }
Esempio n. 30
0
			internal PractitionerFacade(ExternalPractitioner practitioner, ExternalPractitionerContactPoint contactPoint)
			{
				_practitioner = practitioner;
				_contactPoint = contactPoint;
			}
Esempio n. 31
0
        public MergeExternalPractitionerResponse MergeExternalPractitioner(MergeExternalPractitionerRequest request)
        {
            Platform.CheckForNullReference(request, "request");
            Platform.CheckMemberIsSet(request.LeftPractitionerRef, "LeftPractitionerRef");
            Platform.CheckMemberIsSet(request.RightPractitionerRef, "RightPractitionerRef");

            var left  = PersistenceContext.Load <ExternalPractitioner>(request.LeftPractitionerRef, EntityLoadFlags.Proxy);
            var right = PersistenceContext.Load <ExternalPractitioner>(request.RightPractitionerRef, EntityLoadFlags.Proxy);

            // if we are only doing a cost estimate, exit here without modifying any data
            if (request.EstimateCostOnly)
            {
                var cost = EstimateAffectedRecords(right, left);
                return(new MergeExternalPractitionerResponse(cost));
            }

            // unpack the request, loading all required entities
            var nameAssembler = new PersonNameAssembler();
            var name          = new PersonName();

            nameAssembler.UpdatePersonName(request.Name, name);

            var defaultContactPoint = request.DefaultContactPointRef != null?
                                      PersistenceContext.Load <ExternalPractitionerContactPoint>(request.DefaultContactPointRef) : null;

            var deactivatedContactPoints = request.DeactivatedContactPointRefs == null ? new List <ExternalPractitionerContactPoint>() :
                                           CollectionUtils.Map(request.DeactivatedContactPointRefs,
                                                               (EntityRef cpRef) => PersistenceContext.Load <ExternalPractitionerContactPoint>(cpRef));

            var cpReplacements = CollectionUtils.Map(request.ContactPointReplacements ?? (new Dictionary <EntityRef, EntityRef>()),
                                                     kvp => new KeyValuePair <ExternalPractitionerContactPoint, ExternalPractitionerContactPoint>(
                                                         PersistenceContext.Load <ExternalPractitionerContactPoint>(kvp.Key, EntityLoadFlags.Proxy),
                                                         PersistenceContext.Load <ExternalPractitionerContactPoint>(kvp.Value, EntityLoadFlags.Proxy)));


            // merge the practitioners
            var result = ExternalPractitioner.MergePractitioners(left, right,
                                                                 name,
                                                                 request.LicenseNumber,
                                                                 request.BillingNumber,
                                                                 request.ExtendedProperties,
                                                                 defaultContactPoint,
                                                                 deactivatedContactPoints,
                                                                 cpReplacements
                                                                 );

            PersistenceContext.Lock(result, DirtyState.New);

            // if user has verify permission, verify the result
            if (Thread.CurrentPrincipal.IsInRole(AuthorityTokens.Admin.Data.ExternalPractitionerVerification))
            {
                result.MarkVerified();
            }

            // queue work items to migrate orders and visits
            foreach (var practitioner in new[] { right, left })
            {
                var queueItem = MergeWorkQueueItem.Create(practitioner.GetRef());
                PersistenceContext.Lock(queueItem, DirtyState.New);
            }

            PersistenceContext.SynchState();

            var assembler = new ExternalPractitionerAssembler();

            return(new MergeExternalPractitionerResponse(assembler.CreateExternalPractitionerSummary(result, this.PersistenceContext)));
        }
Esempio n. 32
0
		public IList<ExternalPractitioner> GetMergeCandidates(ExternalPractitioner practitioner)
		{
			var criteria = GetMergeCandidatesCriteria(practitioner);
			return Find(criteria);
		}
			public override AlertNotification Test(ExternalPractitioner entity, IPersistenceContext context)
			{
				var broker = context.GetBroker<IExternalPractitionerBroker>();
				var count = broker.CountMergeCandidates(entity);
				return count > 0 ? new AlertNotification(this.Id, new string[] { }) : null;
			}
 internal PractitionerFacade(ExternalPractitioner practitioner, ExternalPractitionerContactPoint contactPoint)
 {
     _practitioner = practitioner;
     _contactPoint = contactPoint;
 }
Esempio n. 35
0
		/// <summary>
		/// Import external practitioner from CSV format.
		/// </summary>
		/// <param name="rows">
		/// Each string in the list must contain 25 CSV fields, as follows:
		///     0 - FamilyName
		///     1 - GivenName
		///     2 - MiddleName
		///     3 - Prefix
		///     4 - Suffix
		///     5 - Degree
		///     6 - LicenseNumber
		///     7 - BillingNumber
		///     8 - Street
		///     9 - Unit
		///     10 - City
		///     11 - Province
		///     12 - PostalCode
		///     13 - Country
		///     14 - ValidFrom
		///     15 - ValidUntil
		///     16 - Phone CountryCode
		///     17 - Phone AreaCode
		///     18 - Phone Number
		///     19 - Phone Extension
		///     20 - ValidFrom
		///     21 - ValidUntil
		///     22 - Fax CountryCode
		///     23 - Fax AreaCode
		///     24 - Fax Number
		///     25 - Fax Extension
		///     26 - ValidFrom
		///     27 - ValidUntil
		/// </param>
		/// <param name="context"></param>
		public override void Import(List<string> rows, IUpdateContext context)
		{
			_context = context;

			var  importedEPs = new List<ExternalPractitioner>();
			var validator = new DomainObjectValidator();

			foreach (var row in rows)
			{
				var fields = ParseCsv(row, _numFields);

				var epFamilyName = fields[0];
				var epGivenName = fields[1];
				var epMiddlename = fields[2];
				var epPrefix = fields[3];
				var epSuffix = fields[4];
				var epDegree = fields[5];

				var epLicense = fields[6];
				var epBillingNumber = fields[7];

				var addressStreet = fields[8];
				var addressUnit = fields[9];
				var addressCity = fields[10];
				var addressProvince = fields[11];
				var addressPostalCode = fields[12];
				var addressCountry = fields[13];

				var addressValidFrom = ParseDateTime(fields[14]);
				var addressValidUntil = ParseDateTime(fields[15]);

				var phoneCountryCode = fields[16];
				var phoneAreaCode = fields[17];
				var phoneNumber = fields[18];
				var phoneExtension = fields[19];
				var phoneValidFrom = ParseDateTime(fields[20]);
				var phoneValidUntil = ParseDateTime(fields[21]);

				var faxCountryCode = fields[22];
				var faxAreaCode = fields[23];
				var faxNumber = fields[24];
				var faxExtension = fields[25];
				var faxValidFrom = ParseDateTime(fields[26]);
				var faxValidUntil = ParseDateTime(fields[27]);


				ExternalPractitioner ep = GetExternalPracitioner(epLicense, importedEPs);

				if (ep != null)
					continue;

				ep = new ExternalPractitioner {LicenseNumber = epLicense, BillingNumber = epBillingNumber};
				ep.Name = new PersonName(epFamilyName, epGivenName, epMiddlename, epPrefix, epSuffix, epDegree);

				// create a single default contact point
				var contactPoint = new ExternalPractitionerContactPoint(ep) {Name = "Default", IsDefaultContactPoint = true};

				try
				{
					var epAddress = new Address(
						addressStreet,
						addressUnit,
						addressCity,
						addressProvince,
						addressPostalCode,
						addressCountry,
						AddressType.B,
						new DateTimeRange(addressValidFrom, addressValidUntil));
					validator.Validate(epAddress);
					contactPoint.Addresses.Add(epAddress);
				}
				catch(EntityValidationException)
				{
					/* invalid address - ignore */
				}

				try
				{
					var epTelephone = new TelephoneNumber(
						phoneCountryCode,
						phoneAreaCode,
						phoneNumber,
						phoneExtension,
						TelephoneUse.WPN,
						TelephoneEquipment.PH,
						new DateTimeRange(phoneValidFrom, phoneValidUntil));

					validator.Validate(epTelephone);
					contactPoint.TelephoneNumbers.Add(epTelephone);
				}
				catch (EntityValidationException)
				{
					/* invalid phone - ignore */
				}

				try
				{
					var epFax = new TelephoneNumber(
						faxCountryCode,
						faxAreaCode,
						faxNumber,
						faxExtension,
						TelephoneUse.WPN,
						TelephoneEquipment.FX,
						new DateTimeRange(faxValidFrom, faxValidUntil));

					validator.Validate(epFax);
					contactPoint.TelephoneNumbers.Add(epFax);
				}
				catch (EntityValidationException)
				{
					/* invalid fax - ignore */
				}

				_context.Lock(ep, DirtyState.New);

				importedEPs.Add(ep);
			}
		}
Esempio n. 36
0
        public int CountMergeCandidates(ExternalPractitioner practitioner)
        {
            var criteria = GetMergeCandidatesCriteria(practitioner);

            return((int)Count(criteria));
        }
Esempio n. 37
0
        private static ExternalPractitionerSearchCriteria[] GetMergeCandidatesCriteria(ExternalPractitioner practitioner)
        {
            var criteria = new List <ExternalPractitionerSearchCriteria>();

            var baseCriteria = new ExternalPractitionerSearchCriteria();

            baseCriteria.NotEqualTo(practitioner);
            baseCriteria.Deactivated.EqualTo(false);

            var nameCriteria = (ExternalPractitionerSearchCriteria)baseCriteria.Clone();

            nameCriteria.Name.FamilyName.EqualTo(practitioner.Name.FamilyName);
            nameCriteria.Name.GivenName.EqualTo(practitioner.Name.GivenName);
            criteria.Add(nameCriteria);

            if (!string.IsNullOrEmpty(practitioner.LicenseNumber))
            {
                var licenseNumberCriteria = (ExternalPractitionerSearchCriteria)baseCriteria.Clone();
                licenseNumberCriteria.LicenseNumber.EqualTo(practitioner.LicenseNumber);
                criteria.Add(licenseNumberCriteria);
            }

            if (!string.IsNullOrEmpty(practitioner.BillingNumber))
            {
                var billingNumberCriteria = (ExternalPractitionerSearchCriteria)baseCriteria.Clone();
                billingNumberCriteria.BillingNumber.EqualTo(practitioner.BillingNumber);
                criteria.Add(billingNumberCriteria);
            }

            return(criteria.ToArray());
        }
Esempio n. 38
0
        public IList <ExternalPractitioner> GetMergeCandidates(ExternalPractitioner practitioner)
        {
            var criteria = GetMergeCandidatesCriteria(practitioner);

            return(Find(criteria));
        }
Esempio n. 39
0
		public int CountMergeCandidates(ExternalPractitioner practitioner)
		{
			var criteria = GetMergeCandidatesCriteria(practitioner);
			return (int) Count(criteria);
		}