private GetPatientProfileDetailResponse GetPatientProfileDetail(GetPatientProfileDetailRequest request)
        {
            var profile = this.PersistenceContext.Load <PatientProfile>(request.PatientProfileRef);

            var patientProfileAssembler = new PatientProfileAssembler();
            var response = new GetPatientProfileDetailResponse();

            response.PatientProfile = patientProfileAssembler.CreatePatientProfileDetail(
                profile,
                this.PersistenceContext,
                request.IncludeAddresses,
                request.IncludeContactPersons,
                request.IncludeEmailAddresses,
                request.IncludeTelephoneNumbers,
                request.IncludeNotes,
                request.IncludeAttachments,
                request.IncludeAllergies);

            if (request.IncludeAlerts)
            {
                var alerts = new List <AlertNotification>();
                alerts.AddRange(AlertHelper.Instance.Test(profile.Patient, this.PersistenceContext));
                alerts.AddRange(AlertHelper.Instance.Test(profile, this.PersistenceContext));

                var alertAssembler = new AlertAssembler();
                response.PatientAlerts = CollectionUtils.Map <AlertNotification, AlertNotificationDetail>(alerts, alertAssembler.CreateAlertNotification);
            }

            return(response);
        }
Example #2
0
        public AddPatientResponse AddPatient(AddPatientRequest request)
        {
            var profile = new PatientProfile();

            // check if we should auto-generate the MRN
            var workflowConfig = new WorkflowConfigurationReader();

            if (workflowConfig.AutoGenerateMrn)
            {
                var authorities = PersistenceContext.GetBroker <IEnumBroker>().Load <InformationAuthorityEnum>(false);

                // just use the first Information Authority (there is typically only one in this case)
                profile.Mrn.AssigningAuthority = CollectionUtils.FirstElement(authorities);
                profile.Mrn.Id = PersistenceContext.GetBroker <IMrnBroker>().GetNext();
            }


            var patient = new Patient();

            patient.AddProfile(profile);

            UpdateHelper(profile, request.PatientDetail, true, true, !workflowConfig.AutoGenerateMrn);

            PersistenceContext.Lock(patient, DirtyState.New);

            LogicalHL7Event.PatientCreated.EnqueueEvents(profile);

            PersistenceContext.SynchState();

            var assembler = new PatientProfileAssembler();

            return(new AddPatientResponse(assembler.CreatePatientProfileSummary(profile, PersistenceContext)));
        }
Example #3
0
		private GetPatientProfileDetailResponse GetPatientProfileDetail(GetPatientProfileDetailRequest request)
		{
			var profile = this.PersistenceContext.Load<PatientProfile>(request.PatientProfileRef);

			var patientProfileAssembler = new PatientProfileAssembler();
			var response = new GetPatientProfileDetailResponse();

			response.PatientProfile = patientProfileAssembler.CreatePatientProfileDetail(
				profile,
				this.PersistenceContext,
				request.IncludeAddresses,
				request.IncludeContactPersons,
				request.IncludeEmailAddresses,
				request.IncludeTelephoneNumbers,
				request.IncludeNotes,
				request.IncludeAttachments,
				request.IncludeAllergies);

			if (request.IncludeAlerts)
			{
				var alerts = new List<AlertNotification>();
				alerts.AddRange(AlertHelper.Instance.Test(profile.Patient, this.PersistenceContext));
				alerts.AddRange(AlertHelper.Instance.Test(profile, this.PersistenceContext));

				var alertAssembler = new AlertAssembler();
				response.PatientAlerts = CollectionUtils.Map<AlertNotification, AlertNotificationDetail>(alerts, alertAssembler.CreateAlertNotification);
			}

			return response;
		}
Example #4
0
		public LoadPatientProfileForEditResponse LoadPatientProfileForEdit(LoadPatientProfileForEditRequest request)
		{
			var broker = PersistenceContext.GetBroker<IPatientProfileBroker>();

			var profile = broker.Load(request.PatientProfileRef);
			var assembler = new PatientProfileAssembler();
			return new LoadPatientProfileForEditResponse(profile.Patient.GetRef(), profile.GetRef(), assembler.CreatePatientProfileDetail(profile, PersistenceContext));
		}
Example #5
0
        public LoadPatientProfileForEditResponse LoadPatientProfileForEdit(LoadPatientProfileForEditRequest request)
        {
            var broker = PersistenceContext.GetBroker <IPatientProfileBroker>();

            var profile   = broker.Load(request.PatientProfileRef);
            var assembler = new PatientProfileAssembler();

            return(new LoadPatientProfileForEditResponse(profile.Patient.GetRef(), profile.GetRef(), assembler.CreatePatientProfileDetail(profile, PersistenceContext)));
        }
		private ListPatientProfilesResponse ListPatientProfiles(ListPatientProfilesRequest request)
		{
			var patient = this.PersistenceContext.Load<Patient>(request.PatientRef);

			var patientProfileAssembler = new PatientProfileAssembler();
			return new ListPatientProfilesResponse(
				CollectionUtils.Map<PatientProfile, PatientProfileSummary>(
					patient.Profiles,
					profile => patientProfileAssembler.CreatePatientProfileSummary(profile, this.PersistenceContext)));
		}
        private ListPatientProfilesResponse ListPatientProfiles(ListPatientProfilesRequest request)
        {
            var patient = this.PersistenceContext.Load <Patient>(request.PatientRef);

            var patientProfileAssembler = new PatientProfileAssembler();

            return(new ListPatientProfilesResponse(
                       CollectionUtils.Map <PatientProfile, PatientProfileSummary>(
                           patient.Profiles,
                           profile => patientProfileAssembler.CreatePatientProfileSummary(profile, this.PersistenceContext))));
        }
Example #8
0
        public ListProfilesForPatientsResponse ListProfilesForPatients(ListProfilesForPatientsRequest request)
        {
            var assembler = new PatientProfileAssembler();
            var summaries = new List <PatientProfileSummary>();

            foreach (var patientRef in request.PatientRefs)
            {
                var patient = this.PersistenceContext.Load <Patient>(patientRef);
                foreach (var profile in patient.Profiles)
                {
                    summaries.Add(assembler.CreatePatientProfileSummary(profile, this.PersistenceContext));
                }
            }

            return(new ListProfilesForPatientsResponse(summaries));
        }
Example #9
0
        public UpdatePatientProfileResponse UpdatePatientProfile(UpdatePatientProfileRequest request)
        {
            var profile = PersistenceContext.Load <PatientProfile>(request.PatientProfileRef, EntityLoadFlags.CheckVersion);

            var updatePatient = Thread.CurrentPrincipal.IsInRole(AuthorityTokens.Workflow.Patient.Update);
            var updateProfile = Thread.CurrentPrincipal.IsInRole(AuthorityTokens.Workflow.PatientProfile.Update);

            UpdateHelper(profile, request.PatientDetail, updatePatient, updateProfile, false);

            LogicalHL7Event.PatientProfileModified.EnqueueEvents(profile);

            this.PersistenceContext.SynchState();

            var assembler = new PatientProfileAssembler();

            return(new UpdatePatientProfileResponse(assembler.CreatePatientProfileSummary(profile, PersistenceContext)));
        }
		public OrderRequisition CreateOrderRequisition(Order order, IPersistenceContext context)
		{
			var patientProfileAssembler = new PatientProfileAssembler();
			var visitAssembler = new VisitAssembler();
			var pracAssembler = new ExternalPractitionerAssembler();
			var facilityAssembler = new FacilityAssembler();
			var dsAssembler = new DiagnosticServiceAssembler();
			var attachmentAssembler = new OrderAttachmentAssembler();
			var noteAssembler = new OrderNoteAssembler();
			var resultRecipientAssembler = new ResultRecipientAssembler();

			var requisition = new OrderRequisition
								{
									OrderRef = order.GetRef(),
									Patient =
										patientProfileAssembler.CreatePatientProfileSummary(
											CollectionUtils.FirstElement(order.Procedures).PatientProfile, context),
									Visit = visitAssembler.CreateVisitSummary(order.Visit, context),
									DiagnosticService = dsAssembler.CreateSummary(order.DiagnosticService),
									SchedulingRequestTime = order.SchedulingRequestTime,
									OrderingPractitioner =
										pracAssembler.CreateExternalPractitionerSummary(order.OrderingPractitioner, context),
									OrderingFacility = facilityAssembler.CreateFacilitySummary(order.OrderingFacility),
									ReasonForStudy = order.ReasonForStudy,
									Priority = EnumUtils.GetEnumValueInfo(order.Priority, context),
									ResultRecipients = CollectionUtils.Map<ResultRecipient, ResultRecipientDetail>(
										order.ResultRecipients,
										r => resultRecipientAssembler.CreateResultRecipientDetail(r, context)),
									Procedures = CollectionUtils.Map<Procedure, ProcedureRequisition>(
										order.Procedures,
										procedure => CreateProcedureRequisition(procedure, context)),
									Attachments = CollectionUtils.Map<OrderAttachment, AttachmentSummary>(
										order.Attachments,
										attachment => attachmentAssembler.CreateOrderAttachmentSummary(attachment, context)),
									Notes = CollectionUtils.Map<OrderNote, OrderNoteDetail>(
										OrderNote.GetNotesForOrder(order),
										note => noteAssembler.CreateOrderNoteDetail(note, context)),
									ExtendedProperties = ExtendedPropertyUtils.Copy(order.ExtendedProperties),
									CanModify = !order.IsTerminated
								};

			return requisition;
		}
Example #11
0
        public OrderRequisition CreateOrderRequisition(Order order, IPersistenceContext context)
        {
            var patientProfileAssembler  = new PatientProfileAssembler();
            var visitAssembler           = new VisitAssembler();
            var pracAssembler            = new ExternalPractitionerAssembler();
            var facilityAssembler        = new FacilityAssembler();
            var dsAssembler              = new DiagnosticServiceAssembler();
            var attachmentAssembler      = new OrderAttachmentAssembler();
            var noteAssembler            = new OrderNoteAssembler();
            var resultRecipientAssembler = new ResultRecipientAssembler();

            var requisition = new OrderRequisition
            {
                OrderRef = order.GetRef(),
                Patient  =
                    patientProfileAssembler.CreatePatientProfileSummary(
                        CollectionUtils.FirstElement(order.Procedures).PatientProfile, context),
                Visit                 = visitAssembler.CreateVisitSummary(order.Visit, context),
                DiagnosticService     = dsAssembler.CreateSummary(order.DiagnosticService),
                SchedulingRequestTime = order.SchedulingRequestTime,
                OrderingPractitioner  =
                    pracAssembler.CreateExternalPractitionerSummary(order.OrderingPractitioner, context),
                OrderingFacility = facilityAssembler.CreateFacilitySummary(order.OrderingFacility),
                ReasonForStudy   = order.ReasonForStudy,
                Priority         = EnumUtils.GetEnumValueInfo(order.Priority, context),
                ResultRecipients = CollectionUtils.Map <ResultRecipient, ResultRecipientDetail>(
                    order.ResultRecipients,
                    r => resultRecipientAssembler.CreateResultRecipientDetail(r, context)),
                Procedures = CollectionUtils.Map <Procedure, ProcedureRequisition>(
                    order.Procedures,
                    procedure => CreateProcedureRequisition(procedure, context)),
                Attachments = CollectionUtils.Map <OrderAttachment, AttachmentSummary>(
                    order.Attachments,
                    attachment => attachmentAssembler.CreateOrderAttachmentSummary(attachment, context)),
                Notes = CollectionUtils.Map <OrderNote, OrderNoteDetail>(
                    OrderNote.GetNotesForOrder(order),
                    note => noteAssembler.CreateOrderNoteDetail(note, context)),
                ExtendedProperties = ExtendedPropertyUtils.Copy(order.ExtendedProperties),
                CanModify          = !order.IsTerminated
            };

            return(requisition);
        }
Example #12
0
        private void UpdateHelper(PatientProfile profile, PatientProfileDetail detail, bool updatePatient, bool updateProfile, bool updateMrn)
        {
            if (updatePatient)
            {
                var patient = profile.Patient;

                var noteAssembler = new PatientNoteAssembler();
                noteAssembler.Synchronize(patient, detail.Notes, CurrentUserStaff, PersistenceContext);

                var attachmentAssembler = new PatientAttachmentAssembler();
                attachmentAssembler.Synchronize(patient.Attachments, detail.Attachments, this.CurrentUserStaff, PersistenceContext);

                var allergyAssembler = new PatientAllergyAssembler();
                allergyAssembler.Synchronize(patient.Allergies, detail.Allergies, PersistenceContext);
            }

            if (updateProfile)
            {
                var assembler = new PatientProfileAssembler();
                assembler.UpdatePatientProfile(profile, detail, updateMrn, PersistenceContext);
            }
        }
Example #13
0
        public ListPatientReconciliationMatchesResponse ListPatientReconciliationMatches(ListPatientReconciliationMatchesRequest request)
        {
            var targetProfile = this.PersistenceContext.GetBroker <IPatientProfileBroker>().Load(request.PatientProfileRef);

            var strategy = (IPatientReconciliationStrategy)(new PatientReconciliationStrategyExtensionPoint()).CreateExtension();
            var matches  = strategy.FindReconciliationMatches(targetProfile, this.PersistenceContext);

            var profileAssembler = new PatientProfileAssembler();
            var rcAssembler      = new ReconciliationCandidateAssembler();
            var response         = new ListPatientReconciliationMatchesResponse
            {
                ReconciledProfiles =
                    CollectionUtils.Map <PatientProfile, PatientProfileSummary, List <PatientProfileSummary> >(
                        targetProfile.Patient.Profiles,
                        profile => profileAssembler.CreatePatientProfileSummary(profile, this.PersistenceContext)),
                MatchCandidates =
                    CollectionUtils.Map <PatientProfileMatch, ReconciliationCandidate, List <ReconciliationCandidate> >(
                        matches,
                        match => rcAssembler.CreateReconciliationCandidate(match, this.PersistenceContext))
            };

            return(response);
        }
        public ReconciliationCandidate CreateReconciliationCandidate(PatientProfileMatch profileMatch, IPersistenceContext context)
        {
            var rc = new ReconciliationCandidate();

            var profileAssembler = new PatientProfileAssembler();

            rc.PatientProfile = profileAssembler.CreatePatientProfileSummary(profileMatch.PatientProfile, context);
            switch (profileMatch.Score)
            {
            case PatientProfileMatch.ScoreValue.High:
                rc.Score = ReconciliationCandidate.ProbabilityScore.High;
                break;

            case PatientProfileMatch.ScoreValue.Moderate:
                rc.Score = ReconciliationCandidate.ProbabilityScore.Moderate;
                break;

            case PatientProfileMatch.ScoreValue.Low:
                rc.Score = ReconciliationCandidate.ProbabilityScore.Low;
                break;
            }
            return(rc);
        }
Example #15
0
        public HttpResponseMessage ReadAll()
        {
            // CAD, CEN, EN, returnValue
            PatientProfileRESTCAD patientProfileRESTCAD = null;
            PatientProfileCEN     patientProfileCEN     = null;

            List <PatientProfileEN>   patientProfileEN = null;
            List <PatientProfileDTOA> returnValue      = null;

            try
            {
                SessionInitializeWithoutTransaction();


                patientProfileRESTCAD = new PatientProfileRESTCAD(session);
                patientProfileCEN     = new PatientProfileCEN(patientProfileRESTCAD);

                // Data
                // TODO: paginación

                patientProfileEN = patientProfileCEN.ReadAll(0, -1).ToList();

                // Convert return
                if (patientProfileEN != null)
                {
                    returnValue = new List <PatientProfileDTOA>();
                    foreach (PatientProfileEN entry in patientProfileEN)
                    {
                        returnValue.Add(PatientProfileAssembler.Convert(entry, session));
                    }
                }
            }

            catch (Exception e)
            {
                if (e.GetType() == typeof(HttpResponseException))
                {
                    throw e;
                }
                else if (e.GetType() == typeof(MoSIoTGenNHibernate.Exceptions.ModelException) && e.Message.Equals("El token es incorrecto"))
                {
                    throw new HttpResponseException(HttpStatusCode.Forbidden);
                }
                else if (e.GetType() == typeof(MoSIoTGenNHibernate.Exceptions.ModelException) || e.GetType() == typeof(MoSIoTGenNHibernate.Exceptions.DataLayerException))
                {
                    throw new HttpResponseException(HttpStatusCode.BadRequest);
                }
                else
                {
                    throw new HttpResponseException(HttpStatusCode.InternalServerError);
                }
            }
            finally
            {
                SessionClose();
            }

            // Return 204 - Empty
            if (returnValue == null || returnValue.Count == 0)
            {
                return(this.Request.CreateResponse(HttpStatusCode.NoContent));
            }
            // Return 200 - OK
            else
            {
                return(this.Request.CreateResponse(HttpStatusCode.OK, returnValue));
            }
        }
Example #16
0
        public HttpResponseMessage Modify(int idPatientProfile, [FromBody] PatientProfileDTO dto)
        {
            // CAD, CEN, returnValue
            PatientProfileRESTCAD patientProfileRESTCAD = null;
            PatientProfileCEN     patientProfileCEN     = null;
            PatientProfileDTOA    returnValue           = null;

            // HTTP response
            HttpResponseMessage response = null;
            string uri = null;

            try
            {
                SessionInitializeTransaction();


                patientProfileRESTCAD = new PatientProfileRESTCAD(session);
                patientProfileCEN     = new PatientProfileCEN(patientProfileRESTCAD);

                // Modify
                patientProfileCEN.Modify(idPatientProfile,
                                         dto.PreferredLanguage
                                         ,
                                         dto.Region
                                         ,
                                         dto.HazardAvoidance
                                         ,
                                         dto.Name
                                         ,
                                         dto.Description
                                         );

                // Return modified object
                returnValue = PatientProfileAssembler.Convert(patientProfileRESTCAD.ReadOIDDefault(idPatientProfile), session);

                SessionCommit();
            }

            catch (Exception e)
            {
                SessionRollBack();

                if (e.GetType() == typeof(HttpResponseException))
                {
                    throw e;
                }
                else if (e.GetType() == typeof(MoSIoTGenNHibernate.Exceptions.ModelException) && e.Message.Equals("El token es incorrecto"))
                {
                    throw new HttpResponseException(HttpStatusCode.Forbidden);
                }
                else if (e.GetType() == typeof(MoSIoTGenNHibernate.Exceptions.ModelException) || e.GetType() == typeof(MoSIoTGenNHibernate.Exceptions.DataLayerException))
                {
                    throw new HttpResponseException(HttpStatusCode.BadRequest);
                }
                else
                {
                    throw new HttpResponseException(HttpStatusCode.InternalServerError);
                }
            }
            finally
            {
                SessionClose();
            }

            // Return 404 - Not found
            if (returnValue == null)
            {
                return(this.Request.CreateResponse(HttpStatusCode.NotFound));
            }
            // Return 200 - OK
            else
            {
                response = this.Request.CreateResponse(HttpStatusCode.OK, returnValue);

                return(response);
            }
        }
Example #17
0
        public HttpResponseMessage New_([FromBody] PatientProfileDTO dto)
        {
            // CAD, CEN, returnValue, returnOID
            PatientProfileRESTCAD patientProfileRESTCAD = null;
            PatientProfileCEN     patientProfileCEN     = null;
            PatientProfileDTOA    returnValue           = null;
            int returnOID = -1;

            // HTTP response
            HttpResponseMessage response = null;
            string uri = null;

            try
            {
                SessionInitializeTransaction();


                patientProfileRESTCAD = new PatientProfileRESTCAD(session);
                patientProfileCEN     = new PatientProfileCEN(patientProfileRESTCAD);

                // Create
                returnOID = patientProfileCEN.New_(
                    dto.PreferredLanguage                                                                                //Atributo Primitivo: p_preferredLanguage
                    , dto.Region                                                                                         //Atributo Primitivo: p_region
                    , dto.HazardAvoidance                                                                                //Atributo Primitivo: p_hazardAvoidance
                    , dto.Name                                                                                           //Atributo Primitivo: p_name
                    , dto.Description                                                                                    //Atributo Primitivo: p_description
                    );
                SessionCommit();

                // Convert return
                returnValue = PatientProfileAssembler.Convert(patientProfileRESTCAD.ReadOIDDefault(returnOID), session);
            }

            catch (Exception e)
            {
                SessionRollBack();

                if (e.GetType() == typeof(HttpResponseException))
                {
                    throw e;
                }
                else if (e.GetType() == typeof(MoSIoTGenNHibernate.Exceptions.ModelException) && e.Message.Equals("El token es incorrecto"))
                {
                    throw new HttpResponseException(HttpStatusCode.Forbidden);
                }
                else if (e.GetType() == typeof(MoSIoTGenNHibernate.Exceptions.ModelException) || e.GetType() == typeof(MoSIoTGenNHibernate.Exceptions.DataLayerException))
                {
                    throw new HttpResponseException(HttpStatusCode.BadRequest);
                }
                else
                {
                    throw new HttpResponseException(HttpStatusCode.InternalServerError);
                }
            }
            finally
            {
                SessionClose();
            }

            // Return 201 - Created
            response = this.Request.CreateResponse(HttpStatusCode.Created, returnValue);

            // Location Header

            /*
             * Dictionary<string, object> routeValues = new Dictionary<string, object>();
             *
             * // TODO: y rolPaths
             * routeValues.Add("id", returnOID);
             *
             * uri = Url.Link("GetOIDPatientProfile", routeValues);
             * response.Headers.Location = new Uri(uri);
             */

            return(response);
        }
Example #18
0
        public HttpResponseMessage ReadOID(int idPatientProfile)
        {
            // CAD, CEN, EN, returnValue
            PatientProfileRESTCAD patientProfileRESTCAD = null;
            PatientProfileCEN     patientProfileCEN     = null;
            PatientProfileEN      patientProfileEN      = null;
            PatientProfileDTOA    returnValue           = null;

            try
            {
                SessionInitializeWithoutTransaction();


                patientProfileRESTCAD = new PatientProfileRESTCAD(session);
                patientProfileCEN     = new PatientProfileCEN(patientProfileRESTCAD);

                // Data
                patientProfileEN = patientProfileCEN.ReadOID(idPatientProfile);

                // Convert return
                if (patientProfileEN != null)
                {
                    returnValue = PatientProfileAssembler.Convert(patientProfileEN, session);
                }
            }

            catch (Exception e)
            {
                if (e.GetType() == typeof(HttpResponseException))
                {
                    throw e;
                }
                else if (e.GetType() == typeof(MoSIoTGenNHibernate.Exceptions.ModelException) && e.Message.Equals("El token es incorrecto"))
                {
                    throw new HttpResponseException(HttpStatusCode.Forbidden);
                }
                else if (e.GetType() == typeof(MoSIoTGenNHibernate.Exceptions.ModelException) || e.GetType() == typeof(MoSIoTGenNHibernate.Exceptions.DataLayerException))
                {
                    throw new HttpResponseException(HttpStatusCode.BadRequest);
                }
                else
                {
                    throw new HttpResponseException(HttpStatusCode.InternalServerError);
                }
            }
            finally
            {
                SessionClose();
            }

            // Return 404 - Not found
            if (returnValue == null)
            {
                return(this.Request.CreateResponse(HttpStatusCode.NotFound));
            }
            // Return 200 - OK
            else
            {
                return(this.Request.CreateResponse(HttpStatusCode.OK, returnValue));
            }
        }
Example #19
0
		public UpdatePatientProfileResponse UpdatePatientProfile(UpdatePatientProfileRequest request)
		{
			var profile = PersistenceContext.Load<PatientProfile>(request.PatientProfileRef, EntityLoadFlags.CheckVersion);

			var updatePatient = Thread.CurrentPrincipal.IsInRole(AuthorityTokens.Workflow.Patient.Update);
			var updateProfile = Thread.CurrentPrincipal.IsInRole(AuthorityTokens.Workflow.PatientProfile.Update);

			UpdateHelper(profile, request.PatientDetail, updatePatient, updateProfile, false);

			LogicalHL7Event.PatientProfileModified.EnqueueEvents(profile);

			this.PersistenceContext.SynchState();

			var assembler = new PatientProfileAssembler();
			return new UpdatePatientProfileResponse(assembler.CreatePatientProfileSummary(profile, PersistenceContext));
		}
Example #20
0
		private void UpdateHelper(PatientProfile profile, PatientProfileDetail detail, bool updatePatient, bool updateProfile, bool updateMrn)
		{
			if (updatePatient)
			{
				var patient = profile.Patient;

				var noteAssembler = new PatientNoteAssembler();
				noteAssembler.Synchronize(patient, detail.Notes, CurrentUserStaff, PersistenceContext);

				var attachmentAssembler = new PatientAttachmentAssembler();
				attachmentAssembler.Synchronize(patient.Attachments, detail.Attachments, this.CurrentUserStaff, PersistenceContext);

				var allergyAssembler = new PatientAllergyAssembler();
				allergyAssembler.Synchronize(patient.Allergies, detail.Allergies, PersistenceContext);
			}

			if (updateProfile)
			{
				var assembler = new PatientProfileAssembler();
				assembler.UpdatePatientProfile(profile, detail, updateMrn, PersistenceContext);
			}
		}
Example #21
0
		public AddPatientResponse AddPatient(AddPatientRequest request)
		{
			var profile = new PatientProfile();

			// check if we should auto-generate the MRN
			var workflowConfig = new WorkflowConfigurationReader();
			if (workflowConfig.AutoGenerateMrn)
			{
				var authorities = PersistenceContext.GetBroker<IEnumBroker>().Load<InformationAuthorityEnum>(false);

				// just use the first Information Authority (there is typically only one in this case)
				profile.Mrn.AssigningAuthority = CollectionUtils.FirstElement(authorities);
				profile.Mrn.Id = PersistenceContext.GetBroker<IMrnBroker>().GetNext();
			}


			var patient = new Patient();
			patient.AddProfile(profile);

			UpdateHelper(profile, request.PatientDetail, true, true, !workflowConfig.AutoGenerateMrn);

			PersistenceContext.Lock(patient, DirtyState.New);

			LogicalHL7Event.PatientCreated.EnqueueEvents(profile);

			PersistenceContext.SynchState();

			var assembler = new PatientProfileAssembler();
			return new AddPatientResponse(assembler.CreatePatientProfileSummary(profile, PersistenceContext));
		}