Beispiel #1
0
 private GetStudyCountResult GetStudyCount(GetStudyCountRequest request)
 {
     using (var context = new DataAccessContext())
     {
         var count = context.GetStudyStoreQuery().GetStudyCount(request.Criteria);                
         return new GetStudyCountResult { StudyCount = count };
     }
 }
Beispiel #2
0
        private GetImageEntriesResult GetImageEntries(GetImageEntriesRequest request)
        {
            using (var context = new DataAccessContext())
            {
                var entries = context.GetStudyStoreQuery().GetImageEntries(request.Criteria);

                var criteria = (request.Criteria ?? new ImageEntry()).Image ?? new ImageIdentifier();
                AuditHelper.LogQueryIssued(null, null, EventSource.CurrentUser, EventResult.Success,
                    SopClass.StudyRootQueryRetrieveInformationModelFindUid, criteria.ToDicomAttributeCollection());

                return new GetImageEntriesResult { ImageEntries = entries };
            }
        }
Beispiel #3
0
        private void OnReceiveMoveImageRequest(ClearCanvas.Dicom.Network.DicomServer server, byte presentationID, DicomMessage message, IDicomServiceNode remoteAEInfo)
		{
			string studyInstanceUid = message.DataSet[DicomTags.StudyInstanceUid].GetString(0, string.Empty);
			string seriesInstanceUid = message.DataSet[DicomTags.SeriesInstanceUid].GetString(0, string.Empty);
			var sopInstanceUids = (string[])message.DataSet[DicomTags.SopInstanceUid].Values;

            lock (_syncLock)
            {

                using (var context = new DataAccessContext())
                {
                    var s = context.GetStudyStoreQuery().StudyQuery(new StudyRootStudyIdentifier
                                                                    {StudyInstanceUid = studyInstanceUid});
                    var identifier = CollectionUtils.FirstElement(s);

                    var client = new DicomSendBridge();
                    client.SendSops(remoteAEInfo, identifier, seriesInstanceUid, sopInstanceUids, WorkItemPriorityEnum.High);
                    _sendOperations.Add(new SendOperationInfo(client.WorkItem, message.MessageId, presentationID, server)
                                            {
                                                SubOperations = sopInstanceUids.Length
                                            });
                }
            }
		}
Beispiel #4
0
        private void OnReceiveMoveSeriesRequest(ClearCanvas.Dicom.Network.DicomServer server, byte presentationID, DicomMessage message, IDicomServiceNode remoteAEInfo)
		{
			string studyInstanceUid = message.DataSet[DicomTags.StudyInstanceUid].GetString(0, "");
			var seriesUids = (string[])message.DataSet[DicomTags.SeriesInstanceUid].Values;

            lock (_syncLock)
            {

                int subOperations = 0;
                using (var context = new DataAccessContext())
                {
                    var results = context.GetStudyStoreQuery().SeriesQuery(new SeriesIdentifier
                                                                               {
                                                                                   StudyInstanceUid =
                                                                                       studyInstanceUid,
                                                                               });
                    foreach (SeriesIdentifier series in results)
                    {
                        foreach (string seriesUid in seriesUids)
                            if (series.SeriesInstanceUid.Equals(seriesUid) &&
                                series.NumberOfSeriesRelatedInstances.HasValue)
                            {
                                subOperations += series.NumberOfSeriesRelatedInstances.Value;
                                break;
                            }
                    }

                    var s =
                        context.GetStudyStoreQuery().StudyQuery(new StudyRootStudyIdentifier
                                                                    {StudyInstanceUid = studyInstanceUid});
                    var identifier = CollectionUtils.FirstElement(s);
                    var client = new DicomSendBridge();

                    client.SendSeries(remoteAEInfo, identifier, seriesUids, WorkItemPriorityEnum.High);
                    _sendOperations.Add(new SendOperationInfo(client.WorkItem, message.MessageId, presentationID,
                                                              server)
                                            {
                                                SubOperations = subOperations
                                            });
                }
            }
		}
Beispiel #5
0
	    private void OnReceiveMoveStudiesRequest(ClearCanvas.Dicom.Network.DicomServer server, byte presentationID, DicomMessage message, IDicomServiceNode remoteAEInfo)
		{
			IEnumerable<string> studyUids = (string[])message.DataSet[DicomTags.StudyInstanceUid].Values;

            foreach (string studyUid in studyUids)
            {
                lock (_syncLock)
                {
                    int subOperations = 0;
                    using (var context = new DataAccessContext())
                    {
                        var s =
                            context.GetStudyStoreQuery().StudyQuery(new StudyRootStudyIdentifier
                                                                        {StudyInstanceUid = studyUid});
                        var identifier = CollectionUtils.FirstElement(s);
                        if (identifier.NumberOfStudyRelatedInstances.HasValue)
                            subOperations = identifier.NumberOfStudyRelatedInstances.Value;

                        var client = new DicomSendBridge();
                        client.SendStudy(remoteAEInfo, identifier, WorkItemPriorityEnum.High);
                        _sendOperations.Add(new SendOperationInfo(client.WorkItem, message.MessageId,
                                                                  presentationID,
                                                                  server)
                                                {
                                                    SubOperations = subOperations
                                                });
                    }
                }
            }
		}
Beispiel #6
0
        public override bool OnReceiveRequest(ClearCanvas.Dicom.Network.DicomServer server, ServerAssociationParameters association, byte presentationID, DicomMessage message)
		{
			String level = message.DataSet[DicomTags.QueryRetrieveLevel].GetString(0, "").Trim();

            var extendedConfiguration = Common.DicomServer.DicomServer.GetExtendedConfiguration();
            var queryResponsesInUtf8 = extendedConfiguration.QueryResponsesInUtf8;

			if (message.AffectedSopClassUid.Equals(SopClass.StudyRootQueryRetrieveInformationModelFindUid))
			{
				try
				{
					using (var context = new DataAccessContext())
					{
						IEnumerable<DicomAttributeCollection> results = context.GetStudyStoreQuery().Query(message.DataSet);
						foreach (DicomAttributeCollection result in results)
						{
                            const string utf8 = "ISO_IR 192";
                            if (queryResponsesInUtf8)
                                ChangeCharacterSet(result, utf8);

                            var response = new DicomMessage(null, result);

						    //Add these to each response.
							message.DataSet[DicomTags.RetrieveAeTitle].SetStringValue(Context.AETitle);
							message.DataSet[DicomTags.InstanceAvailability].SetStringValue("ONLINE");

							response.DataSet[DicomTags.QueryRetrieveLevel].SetStringValue(level);
							server.SendCFindResponse(presentationID, message.MessageId, response,
													 DicomStatuses.Pending);
						}
					}
				}
				catch (Exception e)
				{
					Platform.Log(LogLevel.Error, e, "Unexpected exception when processing FIND request.");

					try
					{
						var errorResponse = new DicomMessage();
						server.SendCFindResponse(presentationID, message.MessageId, errorResponse,
						                         DicomStatuses.QueryRetrieveUnableToProcess);

						return true;
					}
					finally
					{
						AuditHelper.LogQueryReceived(association.CallingAE, GetRemoteHostName(association), EventResult.SeriousFailure,
						                             message.AffectedSopClassUid, message.DataSet);
					}
				}

				try
				{
					var finalResponse = new DicomMessage();
					server.SendCFindResponse(presentationID, message.MessageId, finalResponse, DicomStatuses.Success);

					AuditHelper.LogQueryReceived(association.CallingAE, GetRemoteHostName(association), EventResult.Success,
					                             message.AffectedSopClassUid, message.DataSet);
					return true;
				}
				catch
				{
					AuditHelper.LogQueryReceived(association.CallingAE, GetRemoteHostName(association), EventResult.SeriousFailure,
					                             message.AffectedSopClassUid, message.DataSet);
					throw;
				}
			}

			try
			{
				Platform.Log(LogLevel.Error, "Unexpected Study Root Query/Retrieve level: {0}", level);
				server.SendCFindResponse(presentationID, message.MessageId, new DicomMessage(),
										 DicomStatuses.QueryRetrieveIdentifierDoesNotMatchSOPClass);
				return true;
			}
			finally
			{
				AuditHelper.LogQueryReceived(association.CallingAE, GetRemoteHostName(association), EventResult.SeriousFailure,
				                             message.AffectedSopClassUid, message.DataSet);
			}
		}
        public override StudyItemList Query(QueryParameters queryParams, IApplicationEntity server)
        {
			Platform.CheckForNullReference(queryParams, "queryParams");

            //.NET strings are unicode, therefore, so is all the query data.
            const string utf8 = "ISO_IR 192";
            var collection = new DicomAttributeCollection {SpecificCharacterSet = utf8};
            collection[DicomTags.SpecificCharacterSet].SetStringValue(utf8);

            collection[DicomTags.QueryRetrieveLevel].SetStringValue("STUDY");
            collection[DicomTags.PatientId].SetStringValue(queryParams["PatientId"]);
            collection[DicomTags.AccessionNumber].SetStringValue(queryParams["AccessionNumber"]);
            collection[DicomTags.PatientsName].SetStringValue(queryParams["PatientsName"]);
			collection[DicomTags.ReferringPhysiciansName].SetStringValue(queryParams["ReferringPhysiciansName"]);
			collection[DicomTags.StudyDate].SetStringValue(queryParams["StudyDate"]);
			collection[DicomTags.StudyTime].SetStringValue("");
			collection[DicomTags.StudyDescription].SetStringValue(queryParams["StudyDescription"]);
        	collection[DicomTags.PatientsBirthDate].SetStringValue("");
            collection[DicomTags.ModalitiesInStudy].SetStringValue(queryParams["ModalitiesInStudy"]);
			collection[DicomTags.StudyInstanceUid].SetStringValue(queryParams["StudyInstanceUid"]);
			collection[DicomTags.NumberOfStudyRelatedInstances].SetStringValue("");
			collection[DicomTags.InstanceAvailability].SetEmptyValue(); // must not be included in request

			collection[DicomTags.PatientSpeciesDescription].SetStringValue(GetString(queryParams, "PatientSpeciesDescription"));
			var codeValue = GetString(queryParams, "PatientSpeciesCodeSequenceCodeValue");
			var codeMeaning = GetString(queryParams, "PatientSpeciesCodeSequenceCodeMeaning");
			if (codeValue != null || codeMeaning != null)
			{
				var codeSequenceMacro = new CodeSequenceMacro
					{
						CodingSchemeDesignator = "",
						CodeValue = codeValue,
						CodeMeaning = codeMeaning
					};
				collection[DicomTags.PatientSpeciesCodeSequence].AddSequenceItem(codeSequenceMacro.DicomSequenceItem);
            }

			collection[DicomTags.PatientBreedDescription].SetStringValue(GetString(queryParams, "PatientBreedDescription"));
			codeValue = GetString(queryParams, "PatientBreedCodeSequenceCodeValue");
			codeMeaning = GetString(queryParams, "PatientBreedCodeSequenceCodeMeaning");
			if (codeValue != null || codeMeaning != null)
			{
				var codeSequenceMacro = new CodeSequenceMacro
					{
						CodingSchemeDesignator = "",
						CodeValue = codeValue,
						CodeMeaning = codeMeaning
					};
				collection[DicomTags.PatientBreedCodeSequence].AddSequenceItem(codeSequenceMacro.DicomSequenceItem);
            }

			collection[DicomTags.ResponsiblePerson].SetStringValue(GetString(queryParams, "ResponsiblePerson"));
			collection[DicomTags.ResponsiblePersonRole].SetStringValue("");
			collection[DicomTags.ResponsibleOrganization].SetStringValue(GetString(queryParams, "ResponsibleOrganization"));

            var localServer = ServerDirectory.GetLocalServer();
            var studyItemList = new StudyItemList();
			using (var context = new DataAccessContext())
			{
				foreach (DicomAttributeCollection result in context.GetStudyStoreQuery().Query(collection))
				{
                    var item = new StudyItem(result[DicomTags.StudyInstanceUid].ToString(), localServer);
					item.SpecificCharacterSet = result.SpecificCharacterSet;
					item.PatientId = result[DicomTags.PatientId].ToString();
					item.PatientsName = new PersonName(result[DicomTags.PatientsName].ToString());
					item.ReferringPhysiciansName = new PersonName(result[DicomTags.ReferringPhysiciansName].GetString(0, ""));
					item.PatientsBirthDate = result[DicomTags.PatientsBirthDate].ToString();
					item.StudyDate = result[DicomTags.StudyDate].ToString();
					item.StudyTime = result[DicomTags.StudyTime].ToString();
					item.StudyDescription = result[DicomTags.StudyDescription].ToString();
					item.ModalitiesInStudy = DicomStringHelper.GetStringArray(result[DicomTags.ModalitiesInStudy].ToString());
					item.AccessionNumber = result[DicomTags.AccessionNumber].ToString();
					item.NumberOfStudyRelatedInstances = result[DicomTags.NumberOfStudyRelatedInstances].GetInt32(0, 0);
					item.InstanceAvailability = result[DicomTags.InstanceAvailability].GetString(0, "");
					if (String.IsNullOrEmpty(item.InstanceAvailability))
						item.InstanceAvailability = "ONLINE";

					item.PatientSpeciesDescription = result[DicomTags.PatientSpeciesDescription].GetString(0, "");
					var patientSpeciesCodeSequence = result[DicomTags.PatientSpeciesCodeSequence];
					if (!patientSpeciesCodeSequence.IsNull && patientSpeciesCodeSequence.Count > 0)
					{
						var codeSequenceMacro = new CodeSequenceMacro(((DicomSequenceItem[]) result[DicomTags.PatientSpeciesCodeSequence].Values)[0]);
						item.PatientSpeciesCodeSequenceCodingSchemeDesignator = codeSequenceMacro.CodingSchemeDesignator;
						item.PatientSpeciesCodeSequenceCodeValue = codeSequenceMacro.CodeValue;
						item.PatientSpeciesCodeSequenceCodeMeaning = codeSequenceMacro.CodeMeaning;
					}

					item.PatientBreedDescription = result[DicomTags.PatientBreedDescription].GetString(0, "");
					var patientBreedCodeSequence = result[DicomTags.PatientBreedCodeSequence];
					if (!patientBreedCodeSequence.IsNull && patientBreedCodeSequence.Count > 0)
					{
						var codeSequenceMacro = new CodeSequenceMacro(((DicomSequenceItem[])result[DicomTags.PatientBreedCodeSequence].Values)[0]);
                        item.PatientBreedCodeSequenceCodingSchemeDesignator = codeSequenceMacro.CodingSchemeDesignator;
						item.PatientBreedCodeSequenceCodeValue = codeSequenceMacro.CodeValue;
						item.PatientBreedCodeSequenceCodeMeaning = codeSequenceMacro.CodeMeaning;
					}

					item.ResponsiblePerson = new PersonName(result[DicomTags.ResponsiblePerson].GetString(0, ""));
					item.ResponsiblePersonRole = result[DicomTags.ResponsiblePersonRole].GetString(0, "");
					item.ResponsibleOrganization = result[DicomTags.ResponsibleOrganization].GetString(0, "");

					studyItemList.Add(item);
				}
			}

			AuditHelper.LogQueryIssued(null, null, EventSource.CurrentUser, EventResult.Success,
									   SopClass.StudyRootQueryRetrieveInformationModelFindUid, collection);

			return studyItemList;
		}