Ejemplo n.º 1
0
        public long CountByVisitPractitioner(VisitSearchCriteria visitSearchCriteria, VisitPractitionerSearchCriteria practitionerSearchCriteria)
        {
            var query = GetBaseVisitPractitionerQuery(visitSearchCriteria, practitionerSearchCriteria);

            query.Selects.Add(new HqlSelect("count(*)"));
            return(ExecuteHqlUnique <long>(query));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// All pertinent data other than the Profiles gets copied from otherPatient to thisPatient
        /// </summary>
        /// <param name="thisPatient"></param>
        /// <param name="otherPatient"></param>
        /// <param name="context"></param>
        static private void ReconnectRelatedPatientInformation(Patient thisPatient, Patient otherPatient, IPersistenceContext context)
        {
            foreach (PatientNote note in otherPatient.Notes)
            {
                thisPatient.AddNote(note);
            }

            OrderSearchCriteria orderCriteria = new OrderSearchCriteria();

            orderCriteria.Patient.EqualTo(otherPatient);
            IList <Order> otherOrders = context.GetBroker <IOrderBroker>().Find(orderCriteria);

            foreach (Order order in otherOrders)
            {
                order.Patient = thisPatient;
            }

            VisitSearchCriteria visitCriteria = new VisitSearchCriteria();

            visitCriteria.Patient.EqualTo(otherPatient);
            IList <Visit> otherVisits = context.GetBroker <IVisitBroker>().Find(visitCriteria);

            foreach (Visit visit in otherVisits)
            {
                visit.Patient = thisPatient;
            }

            // TODO: delete the otherPatient
        }
Ejemplo n.º 3
0
        public IList <Visit> FindByVisitPractitioner(VisitSearchCriteria visitSearchCriteria, VisitPractitionerSearchCriteria practitionerSearchCriteria, SearchResultPage page)
        {
            var query = GetBaseVisitPractitionerQuery(visitSearchCriteria, practitionerSearchCriteria);

            query.Page = page;
            return(ExecuteHql <Visit>(query));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Applies this filter to the specified criteria object.
        /// </summary>
        /// <param name="criteria"></param>
        /// <param name="wqc"></param>
        public void Apply(VisitSearchCriteria criteria, IWorklistQueryContext wqc)
        {
            if (!this.IsEnabled)
            {
                return;
            }

            criteria.CurrentLocation.In(this.Values);
        }
Ejemplo n.º 5
0
		private static HqlProjectionQuery GetBaseVisitPractitionerQuery(VisitSearchCriteria visitSearchCriteria, VisitPractitionerSearchCriteria practitionerSearchCriteria)
		{
			var hqlFrom = new HqlFrom(typeof(Visit).Name, "v");
			hqlFrom.Joins.Add(new HqlJoin("v.Practitioners", "vp"));

			var query = new HqlProjectionQuery(hqlFrom);
			query.Conditions.AddRange(HqlCondition.FromSearchCriteria("vp", practitionerSearchCriteria));
			query.Conditions.AddRange(HqlCondition.FromSearchCriteria("v", visitSearchCriteria));
			return query;
		}
Ejemplo n.º 6
0
        private static IList <Visit> GetVisitBatch(ExternalPractitioner practitioner, Action <VisitSearchCriteria> priorityFilter, int batchSize, IPersistenceContext context)
        {
            var visitsWhere = new VisitSearchCriteria();

            priorityFilter(visitsWhere);

            var practitionersWhere = new VisitPractitionerSearchCriteria();

            practitionersWhere.Practitioner.EqualTo(practitioner);
            return(context.GetBroker <IVisitBroker>().FindByVisitPractitioner(new VisitSearchCriteria(), practitionersWhere, new SearchResultPage(0, batchSize)));
        }
Ejemplo n.º 7
0
        private static HqlProjectionQuery GetBaseVisitPractitionerQuery(VisitSearchCriteria visitSearchCriteria, VisitPractitionerSearchCriteria practitionerSearchCriteria)
        {
            var hqlFrom = new HqlFrom(typeof(Visit).Name, "v");

            hqlFrom.Joins.Add(new HqlJoin("v.Practitioners", "vp"));

            var query = new HqlProjectionQuery(hqlFrom);

            query.Conditions.AddRange(HqlCondition.FromSearchCriteria("vp", practitionerSearchCriteria));
            query.Conditions.AddRange(HqlCondition.FromSearchCriteria("v", visitSearchCriteria));
            return(query);
        }
Ejemplo n.º 8
0
			/// <summary>
			/// Reconciles the specified patient to this patient
			/// </summary>
			/// <param name="thisPatient"></param>
			/// <param name="otherPatient"></param>
			/// <param name="workflow"></param>
			private static void Reconcile(Patient thisPatient, Patient otherPatient, IWorkflow workflow)
			{
				if (PatientIdentifierConflictsFound(thisPatient, otherPatient))
					throw new PatientReconciliationException("assigning authority conflict - cannot reconcile");

				// copy the collection to iterate
				var otherProfiles = new List<PatientProfile>(otherPatient.Profiles);
				foreach (var profile in otherProfiles)
				{
					thisPatient.AddProfile(profile);
				}

				// copy the collection to iterate
				var otherNotes = new List<PatientNote>(otherPatient.Notes);
				foreach (var note in otherNotes)
				{
					thisPatient.AddNote(note);
				}

				// copy the collection to iterate
				var otherAttachments = new List<PatientAttachment>(otherPatient.Attachments);
				foreach (var attachment in otherAttachments)
				{
					otherPatient.Attachments.Remove(attachment);
					thisPatient.Attachments.Add(attachment);
				}

				// copy the collection to iterate
				var otherAllergies = new List<Allergy>(otherPatient.Allergies);
				foreach (var allergy in otherAllergies)
				{
					otherPatient.Allergies.Remove(allergy);
					thisPatient.Allergies.Add(allergy);
				}

				var visitCriteria = new VisitSearchCriteria();
				visitCriteria.Patient.EqualTo(otherPatient);
				var otherVisits = workflow.GetBroker<IVisitBroker>().Find(visitCriteria);
				foreach (var visit in otherVisits)
				{
					visit.Patient = thisPatient;
				}

				var orderCriteria = new OrderSearchCriteria();
				orderCriteria.Patient.EqualTo(otherPatient);
				var otherOrders = workflow.GetBroker<IOrderBroker>().Find(orderCriteria);
				foreach (var order in otherOrders)
				{
					order.Patient = thisPatient;
				}
			}
Ejemplo n.º 9
0
 private void ValidateVisitsExist(Order order)
 {
     try
     {
         var visitSearchCriteria = new VisitSearchCriteria();
         visitSearchCriteria.Patient.EqualTo(order.Patient);
         visitSearchCriteria.VisitNumber.AssigningAuthority.EqualTo(order.OrderingFacility.InformationAuthority);
         this.PersistenceContext.GetBroker <IVisitBroker>().FindOne(visitSearchCriteria);
     }
     catch (EntityNotFoundException)
     {
         throw new RequestValidationException(
                   string.Format(SR.InvalidRequest_CannotEnterOrderWithoutVisits,
                                 order.OrderingFacility.InformationAuthority.Value));
     }
 }
Ejemplo n.º 10
0
 private void ValidateVisitsExist(Order order)
 {
     try
     {
         var visitSearchCriteria = new VisitSearchCriteria();
         visitSearchCriteria.Patient.EqualTo(order.Patient);
         visitSearchCriteria.VisitNumber.AssigningAuthority.EqualTo(order.OrderingFacility.InformationAuthority);
         this.PersistenceContext.GetBroker <IVisitBroker>().FindOne(visitSearchCriteria);
     }
     catch (EntityNotFoundException)
     {
         throw new RequestValidationException(
                   string.Format("The order cannot be entered because the patient does not have any visits at {0}.",
                                 order.OrderingFacility.InformationAuthority.Value));
     }
 }
        protected Visit GetVisit(PatientProfile patientProfile, Order order)
        {
            //if order originated from this authority, then just use visit in order
            if (_authority == order.OrderingFacility.InformationAuthority.Code)
            {
                return(order.Visit);
            }

            //otherwise, find appropriate visit
            var criteria = new VisitSearchCriteria();

            criteria.Patient.EqualTo(order.Patient);
            criteria.AdmitTime.SortDesc(0);
            criteria.VisitNumber.AssigningAuthority.EqualTo(patientProfile.Mrn.AssigningAuthority);
            criteria.Status.In(new[] { VisitStatus.AA, VisitStatus.PD, VisitStatus.PA });
            return(PersistenceScope.CurrentContext.GetBroker <IVisitBroker>().FindOne(criteria));
        }
Ejemplo n.º 12
0
		public ListVisitsForPatientResponse ListVisitsForPatient(ListVisitsForPatientRequest request)
		{
			Platform.CheckForNullReference(request, "request");
			Platform.CheckMemberIsSet(request.PatientRef, "PatientRef");

			var patient = this.PersistenceContext.GetBroker<IPatientBroker>().Load(request.PatientRef, EntityLoadFlags.Proxy);

			var criteria = new VisitSearchCriteria();
			criteria.Patient.EqualTo(patient);
			criteria.AdmitTime.SortDesc(0);

			var assembler = new VisitAssembler();
			return new ListVisitsForPatientResponse(
				CollectionUtils.Map<Visit, VisitSummary, List<VisitSummary>>(
					this.PersistenceContext.GetBroker<IVisitBroker>().Find(criteria),
					v => assembler.CreateVisitSummary(v, this.PersistenceContext)));
		}
Ejemplo n.º 13
0
        public ListVisitsForPatientResponse ListVisitsForPatient(ListVisitsForPatientRequest request)
        {
            Patient patient = PersistenceContext.Load<Patient>(request.PatientRef);

            VisitSearchCriteria criteria = new VisitSearchCriteria();
            criteria.Patient.EqualTo(patient);

            IList<Visit> visits = PersistenceContext.GetBroker<IVisitBroker>().Find(criteria);

            VisitAssembler assembler = new VisitAssembler();
            ListVisitsForPatientResponse response = new ListVisitsForPatientResponse();
            response.Visits = new List<VisitSummary>();
            foreach (Visit v in visits)
            {
                response.Visits.Add(assembler.CreateVisitSummary(v, PersistenceContext));
            }

            return response;
        }
Ejemplo n.º 14
0
        public ListVisitsForPatientResponse ListVisitsForPatient(ListVisitsForPatientRequest request)
        {
            Platform.CheckForNullReference(request, "request");
            Platform.CheckMemberIsSet(request.PatientRef, "PatientRef");

            var patient = this.PersistenceContext.GetBroker <IPatientBroker>().Load(request.PatientRef, EntityLoadFlags.Proxy);

            var criteria = new VisitSearchCriteria();

            criteria.Patient.EqualTo(patient);
            criteria.AdmitTime.SortDesc(0);

            var assembler = new VisitAssembler();

            return(new ListVisitsForPatientResponse(
                       CollectionUtils.Map <Visit, VisitSummary, List <VisitSummary> >(
                           this.PersistenceContext.GetBroker <IVisitBroker>().Find(criteria),
                           v => assembler.CreateVisitSummary(v, this.PersistenceContext))));
        }
Ejemplo n.º 15
0
        public ListVisitsForPatientResponse ListVisitsForPatient(ListVisitsForPatientRequest request)
        {
            Patient patient = PersistenceContext.Load <Patient>(request.PatientRef);

            VisitSearchCriteria criteria = new VisitSearchCriteria();

            criteria.Patient.EqualTo(patient);

            IList <Visit> visits = PersistenceContext.GetBroker <IVisitBroker>().Find(criteria);

            VisitAssembler assembler = new VisitAssembler();
            ListVisitsForPatientResponse response = new ListVisitsForPatientResponse();

            response.Visits = new List <VisitSummary>();
            foreach (Visit v in visits)
            {
                response.Visits.Add(assembler.CreateVisitSummary(v, PersistenceContext));
            }

            return(response);
        }
        public Visit GetVisit(string visitNumber, string assigningAuthority, bool createIfNotExist,
                              out bool doneCreatedVisit)
        {
            doneCreatedVisit = false;
            Platform.CheckForEmptyString(visitNumber, "visitNumber");
            Platform.CheckForEmptyString(assigningAuthority, "assigningAuthority");
            var infoAuth =
                _persistenceContext.GetBroker <IEnumBroker>().TryFind <InformationAuthorityEnum>(assigningAuthority);
            Visit visit    = null;
            var   criteria = new VisitSearchCriteria();

            criteria.VisitNumber.Id.EqualTo(visitNumber);
            criteria.VisitNumber.AssigningAuthority.EqualTo(infoAuth);
            try
            {
                visit = _persistenceContext.GetBroker <IVisitBroker>().FindOne(criteria);
                _visits.Add(new LockableEntity <Visit>(visit, DirtyState.Dirty));
                //todo check that visit.Patient matches patient in _patients
            }
            catch (EntityNotFoundException)
            {
                if (createIfNotExist)
                {
                    visit = new Visit();
                    _visits.Add(new LockableEntity <Visit>(visit, DirtyState.New));
                    visit.VisitNumber.Id = visitNumber;
                    visit.VisitNumber.AssigningAuthority = infoAuth;
                    // facility will be handled by location handler, and yet we can't leave facility null.
                    //so, we simply pick any old facility for now
                    visit.Facility =
                        _persistenceContext.GetBroker <IFacilityBroker>().FindOne(new FacilitySearchCriteria());
                    doneCreatedVisit = true;
                }
            }
            return(visit);
        }
Ejemplo n.º 17
0
        private ListVisitsResponse ListVisits(ListVisitsRequest request)
        {
            // hide visits if "visit workflow" is disabled
            var workflowConfig = new WorkflowConfigurationReader();

            if (!workflowConfig.EnableVisitWorkflow)
            {
                return(null);
            }

            var browsePatientDataAssembler = new BrowsePatientDataAssembler();

            var patient = this.PersistenceContext.Load <Patient>(request.PatientRef, EntityLoadFlags.Proxy);

            var where = new VisitSearchCriteria();
            where.Patient.EqualTo(patient);

            var visits = this.PersistenceContext.GetBroker <IVisitBroker>().Find(where);

            return(new ListVisitsResponse(
                       CollectionUtils.Map <Visit, VisitListItem>(
                           visits,
                           v => browsePatientDataAssembler.CreateVisitListItem(v, this.PersistenceContext))));
        }
Ejemplo n.º 18
0
		/// <summary>
		/// All pertinent data other than the Profiles gets copied from otherPatient to thisPatient
		/// </summary>
		/// <param name="thisPatient"></param>
		/// <param name="otherPatient"></param>
		/// <param name="context"></param>
		static private void ReconnectRelatedPatientInformation(Patient thisPatient, Patient otherPatient, IPersistenceContext context)
		{
			foreach (PatientNote note in otherPatient.Notes)
			{
				thisPatient.AddNote(note);
			}

			OrderSearchCriteria orderCriteria = new OrderSearchCriteria();
			orderCriteria.Patient.EqualTo(otherPatient);
			IList<Order> otherOrders = context.GetBroker<IOrderBroker>().Find(orderCriteria);
			foreach (Order order in otherOrders)
			{
				order.Patient = thisPatient;
			}

			VisitSearchCriteria visitCriteria = new VisitSearchCriteria();
			visitCriteria.Patient.EqualTo(otherPatient);
			IList<Visit> otherVisits = context.GetBroker<IVisitBroker>().Find(visitCriteria);
			foreach (Visit visit in otherVisits)
			{
				visit.Patient = thisPatient;
			}

			// TODO: delete the otherPatient
		}
Ejemplo n.º 19
0
		private void ValidateVisitsExist(Order order)
		{
			try
			{
				var visitSearchCriteria = new VisitSearchCriteria();
				visitSearchCriteria.Patient.EqualTo(order.Patient);
				visitSearchCriteria.VisitNumber.AssigningAuthority.EqualTo(order.OrderingFacility.InformationAuthority);
				this.PersistenceContext.GetBroker<IVisitBroker>().FindOne(visitSearchCriteria);
			}
			catch (EntityNotFoundException)
			{
				throw new RequestValidationException(
					string.Format(SR.InvalidRequest_CannotEnterOrderWithoutVisits,
					order.OrderingFacility.InformationAuthority.Value));
			}
		}
Ejemplo n.º 20
0
		private void ValidateVisitsExist(Order order)
		{
			try
			{
				var visitSearchCriteria = new VisitSearchCriteria();
				visitSearchCriteria.Patient.EqualTo(order.Patient);
				visitSearchCriteria.VisitNumber.AssigningAuthority.EqualTo(order.OrderingFacility.InformationAuthority);
				this.PersistenceContext.GetBroker<IVisitBroker>().FindOne(visitSearchCriteria);
			}
			catch (EntityNotFoundException)
			{
				throw new RequestValidationException(
					string.Format("The order cannot be entered because the patient does not have any visits at {0}.",
					order.OrderingFacility.InformationAuthority.Value));
			}
		}
		private ListVisitsResponse ListVisits(ListVisitsRequest request)
		{
			// hide visits if "visit workflow" is disabled
			var workflowConfig = new WorkflowConfigurationReader();
			if(!workflowConfig.EnableVisitWorkflow)
				return null;

			var browsePatientDataAssembler = new BrowsePatientDataAssembler();

			var patient = this.PersistenceContext.Load<Patient>(request.PatientRef, EntityLoadFlags.Proxy);

			var where = new VisitSearchCriteria();
			where.Patient.EqualTo(patient);

			var visits = this.PersistenceContext.GetBroker<IVisitBroker>().Find(where);
			return new ListVisitsResponse(
				CollectionUtils.Map<Visit, VisitListItem>(
					visits,
					v => browsePatientDataAssembler.CreateVisitListItem(v, this.PersistenceContext)));
		}
Ejemplo n.º 22
0
            /// <summary>
            /// Reconciles the specified patient to this patient
            /// </summary>
            /// <param name="thisPatient"></param>
            /// <param name="otherPatient"></param>
            /// <param name="workflow"></param>
            private static void Reconcile(Patient thisPatient, Patient otherPatient, IWorkflow workflow)
            {
                if (PatientIdentifierConflictsFound(thisPatient, otherPatient))
                {
                    throw new PatientReconciliationException("assigning authority conflict - cannot reconcile");
                }

                // copy the collection to iterate
                var otherProfiles = new List <PatientProfile>(otherPatient.Profiles);

                foreach (var profile in otherProfiles)
                {
                    thisPatient.AddProfile(profile);
                }

                // copy the collection to iterate
                var otherNotes = new List <PatientNote>(otherPatient.Notes);

                foreach (var note in otherNotes)
                {
                    thisPatient.AddNote(note);
                }

                // copy the collection to iterate
                var otherAttachments = new List <PatientAttachment>(otherPatient.Attachments);

                foreach (var attachment in otherAttachments)
                {
                    otherPatient.Attachments.Remove(attachment);
                    thisPatient.Attachments.Add(attachment);
                }

                // copy the collection to iterate
                var otherAllergies = new List <Allergy>(otherPatient.Allergies);

                foreach (var allergy in otherAllergies)
                {
                    otherPatient.Allergies.Remove(allergy);
                    thisPatient.Allergies.Add(allergy);
                }

                var visitCriteria = new VisitSearchCriteria();

                visitCriteria.Patient.EqualTo(otherPatient);
                var otherVisits = workflow.GetBroker <IVisitBroker>().Find(visitCriteria);

                foreach (var visit in otherVisits)
                {
                    visit.Patient = thisPatient;
                }

                var orderCriteria = new OrderSearchCriteria();

                orderCriteria.Patient.EqualTo(otherPatient);
                var otherOrders = workflow.GetBroker <IOrderBroker>().Find(orderCriteria);

                foreach (var order in otherOrders)
                {
                    order.Patient = thisPatient;
                }
            }
Ejemplo n.º 23
0
 public static void All(VisitSearchCriteria visitsWhere)
 {
     // no filters
 }
Ejemplo n.º 24
0
 public IList <Visit> FindByVisitPractitioner(VisitSearchCriteria visitSearchCriteria, VisitPractitionerSearchCriteria practitionerSearchCriteria)
 {
     return(FindByVisitPractitioner(visitSearchCriteria, practitionerSearchCriteria, new SearchResultPage()));
 }
Ejemplo n.º 25
0
		public IList<Visit> FindByVisitPractitioner(VisitSearchCriteria visitSearchCriteria, VisitPractitionerSearchCriteria practitionerSearchCriteria)
		{
			return FindByVisitPractitioner(visitSearchCriteria, practitionerSearchCriteria, new SearchResultPage());
		}
Ejemplo n.º 26
0
		public static void All(VisitSearchCriteria visitsWhere)
		{
			// no filters
		}
Ejemplo n.º 27
0
		public IList<Visit> FindByVisitPractitioner(VisitSearchCriteria visitSearchCriteria, VisitPractitionerSearchCriteria practitionerSearchCriteria, SearchResultPage page)
		{
			var query = GetBaseVisitPractitionerQuery(visitSearchCriteria, practitionerSearchCriteria);
			query.Page = page;
			return ExecuteHql<Visit>(query);
		}
Ejemplo n.º 28
0
		public long CountByVisitPractitioner(VisitSearchCriteria visitSearchCriteria, VisitPractitionerSearchCriteria practitionerSearchCriteria)
		{
			var query = GetBaseVisitPractitionerQuery(visitSearchCriteria, practitionerSearchCriteria);
			query.Selects.Add(new HqlSelect("count(*)"));
			return ExecuteHqlUnique<long>(query);
		}