Example #1
0
 public PatientSelectCriteria(PatientSelectCriteria other)
 : base(other)
 {}
Example #2
0
        /// <summary>
        /// Method for processing Patient level queries.
        /// </summary>
        /// <param name="server"></param>
        /// <param name="presentationId"></param>
        /// <param name="message">The Patient level query message.</param>
        /// <returns></returns>
        private void OnReceivePatientQuery(DicomServer server, byte presentationId, DicomMessage message)
        {
            var tagList = new List<DicomTag>();

            using (IReadContext read = PersistentStoreRegistry.GetDefaultStore().OpenReadContext())
            {
                var find = read.GetBroker<IPatientEntityBroker>();

                var criteria = new PatientSelectCriteria();
                criteria.ServerPartitionKey.EqualTo(Partition.GetKey());

                DicomAttributeCollection data = message.DataSet;
            	var studySelect = new StudySelectCriteria();
            	bool studySubSelect = false;
                foreach (DicomAttribute attrib in message.DataSet)
                {
                    tagList.Add(attrib.Tag);
                    if (!attrib.IsNull)
                        switch (attrib.Tag.TagValue)
                        {
                            case DicomTags.PatientsName:
								QueryHelper.SetStringCondition(criteria.PatientsName, data[DicomTags.PatientsName].GetString(0, string.Empty));
                                break;
                            case DicomTags.PatientId:
								QueryHelper.SetStringCondition(criteria.PatientId, data[DicomTags.PatientId].GetString(0, string.Empty));
                                break;
                            case DicomTags.IssuerOfPatientId:
                                QueryHelper.SetStringCondition(criteria.IssuerOfPatientId,
												   data[DicomTags.IssuerOfPatientId].GetString(0, string.Empty));
                                break;
							case DicomTags.PatientsSex:
								// Specify a subselect on Patients Sex in Study
								QueryHelper.SetStringArrayCondition(studySelect.PatientsSex,
														(string[])data[DicomTags.PatientsSex].Values);
								if (!studySubSelect)
								{
									criteria.StudyRelatedEntityCondition.Exists(studySelect);
									studySubSelect = true;
								}
                        		break;

							case DicomTags.PatientsBirthDate:
								// Specify a subselect on Patients Birth Date in Study
								QueryHelper.SetStringArrayCondition(studySelect.PatientsBirthDate,
														(string[])data[DicomTags.PatientsBirthDate].Values);
								if (!studySubSelect)
								{
									criteria.StudyRelatedEntityCondition.Exists(studySelect);
									studySubSelect = true;
								}
								break;
                            default:
                                foreach (var q in _queryExtensions)
                                {
                                    bool extensionSubSelect;
                                    q.OnReceivePatientLevelQuery(message, attrib.Tag, criteria, studySelect, out extensionSubSelect);
                                    if (extensionSubSelect && !studySubSelect)
                                    {
                                        criteria.StudyRelatedEntityCondition.Exists(studySelect);
                                        studySubSelect = true;
                                    }
                                }
                                break;
                        }
                }

				int resultCount = 0;
                try
                {
                    find.Find(criteria, delegate(Patient row)
                                            {
												if (CancelReceived)
													throw new DicomException("DICOM C-Cancel Received");

                                            	resultCount++;
												if (DicomSettings.Default.MaxQueryResponses != -1
													&& DicomSettings.Default.MaxQueryResponses < resultCount)
												{
													SendBufferedResponses(server, presentationId, message);
													throw new DicomException("Maximum Configured Query Responses Exceeded: " + resultCount);
												}

                                            	var response = new DicomMessage();
												PopulatePatient(response, tagList, row);
                                            	_responseQueue.Enqueue(response);

												if (_responseQueue.Count >= DicomSettings.Default.BufferedQueryResponses)
													SendBufferedResponses(server, presentationId, message);
                                            });

                	SendBufferedResponses(server, presentationId, message);

                }
                catch (Exception e)
                {
					if (CancelReceived)
					{
						var errorResponse = new DicomMessage();
						server.SendCFindResponse(presentationId, message.MessageId, errorResponse,
												 DicomStatuses.Cancel);
					}
					else if (DicomSettings.Default.MaxQueryResponses != -1 
						  && DicomSettings.Default.MaxQueryResponses < resultCount)
					{
						Platform.Log(LogLevel.Warn, "Maximum Configured Query Responses Exceeded: {0} on query from {1}", resultCount, server.AssociationParams.CallingAE);
						var errorResponse = new DicomMessage();
						server.SendCFindResponse(presentationId, message.MessageId, errorResponse,
												 DicomStatuses.Success);
						AuditLog(server.AssociationParams,
								 EventIdentificationContentsEventOutcomeIndicator.Success, message);
					}
					else
					{
						Platform.Log(LogLevel.Error, e, "Unexpected exception when processing FIND request.");
						var errorResponse = new DicomMessage();
						server.SendCFindResponse(presentationId, message.MessageId, errorResponse,
						                         DicomStatuses.QueryRetrieveUnableToProcess);
						AuditLog(server.AssociationParams,
								 EventIdentificationContentsEventOutcomeIndicator.SeriousFailureActionTerminated, message);
					}
                	return;
                }
            }

            var finalResponse = new DicomMessage();
            server.SendCFindResponse(presentationId, message.MessageId, finalResponse, DicomStatuses.Success);
			AuditLog(server.AssociationParams, EventIdentificationContentsEventOutcomeIndicator.Success, message);
        	return;
        }
Example #3
0
 public PatientSelectCriteria(PatientSelectCriteria other)
     : base(other)
 {
 }
		private static Patient FindPatient(PatientInfo patientInfo, IPersistenceContext context)
		{
            IPatientEntityBroker patientFindBroker = context.GetBroker<IPatientEntityBroker>();
			PatientSelectCriteria criteria = new PatientSelectCriteria();

			if (!String.IsNullOrEmpty(patientInfo.PatientId))
				criteria.PatientId.EqualTo(patientInfo.PatientId);
			else
				criteria.PatientId.IsNull();

			if (!String.IsNullOrEmpty(patientInfo.Name))
                criteria.PatientsName.EqualTo(patientInfo.Name);
			else
				criteria.PatientsName.IsNull();

			return patientFindBroker.FindOne(criteria);
		}
		private Patient FindPatient(PatientInfo patientInfo, IPersistenceContext context)
		{
			var patientFindBroker = context.GetBroker<IPatientEntityBroker>();
			var criteria = new PatientSelectCriteria();
            criteria.ServerPartitionKey.EqualTo(_partition.Key);
			if (!String.IsNullOrEmpty(patientInfo.PatientId))
				criteria.PatientId.EqualTo(patientInfo.PatientId);
			else
				criteria.PatientId.IsNull();

			if (!String.IsNullOrEmpty(patientInfo.PatientsName))
				criteria.PatientsName.EqualTo(patientInfo.PatientsName);
			else
				criteria.PatientsName.IsNull();

			return patientFindBroker.FindOne(criteria);
		}