From b90c612104d27417994110ddbe1d3b7848d44270 Mon Sep 17 00:00:00 2001
From: Guillaume Thomazon <gtn@kereval.com>
Date: Fri, 15 Feb 2013 14:40:38 +0000
Subject: [PATCH] Add selection by SOP Class UID (affected and requested) and
 command field.

git-svn-id: https://scm.gforge.inria.fr/authscm/ycadoret/svn/gazelle/Maven/gazelle-proxy/trunk@33601 356b4b1a-1d2b-0410-8bf1-ffa24008f01e
---
 .../proxy/model/message/DicomMessage.java     | 97 +++++++++++++++++--
 1 file changed, 91 insertions(+), 6 deletions(-)

diff --git a/gazelle-proxy-jar/src/main/java/net/ihe/gazelle/proxy/model/message/DicomMessage.java b/gazelle-proxy-jar/src/main/java/net/ihe/gazelle/proxy/model/message/DicomMessage.java
index 2e4bd9dc..22bd6ba2 100644
--- a/gazelle-proxy-jar/src/main/java/net/ihe/gazelle/proxy/model/message/DicomMessage.java
+++ b/gazelle-proxy-jar/src/main/java/net/ihe/gazelle/proxy/model/message/DicomMessage.java
@@ -33,7 +33,6 @@ import javax.persistence.Column;
 import javax.persistence.Entity;
 import javax.persistence.FetchType;
 import javax.persistence.Lob;
-import javax.persistence.Transient;
 
 import net.ihe.gazelle.proxy.dicom.TxtInputHandler;
 import net.ihe.gazelle.proxy.netty.ChannelType;
@@ -53,7 +52,7 @@ import com.pixelmed.dicom.DicomDictionary;
 import com.pixelmed.dicom.DicomException;
 import com.pixelmed.dicom.DicomInputStream;
 import com.pixelmed.dicom.SOPClassDescriptions;
-import com.pixelmed.network.MessageServiceElementCommand;
+import com.pixelmed.network.MessageServiceElementCommand_;
 
 @Entity
 @Name("dicomMessage")
@@ -75,18 +74,41 @@ public class DicomMessage extends AbstractMessage implements java.io.Serializabl
 	@Lob
 	private String fileDump;
 
-	public ChannelType getChannelType() {
-		return ChannelType.DICOM;
-	}
+	@Column(name = "dicom_affectedsopclassuid")
+	private String infoAffectedSOPClassUID;
+
+	@Column(name = "dicom_commandfield")
+	private String infoCommandField;
+
+	@Column(name = "dicom_requestedsopclassuid")
+	private String infoRequestedSOPClassUID;
+
 
 	// Constructors
 
+	public String getInfoAffectedSOPClassUID() {
+		return infoAffectedSOPClassUID;
+	}
+
+	public String getInfoCommandField() {
+		return infoCommandField;
+	}
+
+	public String getInfoRequestedSOPClassUID() {
+		return infoRequestedSOPClassUID;
+	}
+
+	public ChannelType getChannelType() {
+		return ChannelType.DICOM;
+	}
+	
 	public byte[] getFileCommandSet() {
 		return fileCommandSet;
 	}
 
 	public void setFileCommandSet(byte[] fileCommandSet) {
 		this.fileCommandSet = fileCommandSet;
+		dumpFileCommandSet();
 	}
 
 	public String getFileTransfertSyntax() {
@@ -157,7 +179,7 @@ public class DicomMessage extends AbstractMessage implements java.io.Serializabl
 							}
 							int[] integerValues = attributeValue.getIntegerValues();
 							for (Integer fieldValue : integerValues) {
-								String commandFieldTmp = MessageServiceElementCommand.toString(fieldValue);
+								String commandFieldTmp = MessageServiceElementCommand_.toString(fieldValue);
 								bw.append(StringEscapeUtils.escapeHtml(commandFieldTmp));
 								bw.append(" ");
 							}
@@ -212,6 +234,69 @@ public class DicomMessage extends AbstractMessage implements java.io.Serializabl
 		return "";
 	}
 
+	public void dumpFileCommandSet() {
+		if (getFileCommandSet() != null) {
+			AttributeList attributeList = new AttributeList();
+
+			try {
+				attributeList.read(new DicomInputStream(new ByteArrayInputStream(getFileCommandSet())));
+				Set<AttributeTag> keys = attributeList.keySet();
+				Iterator<AttributeTag> iterator = keys.iterator();
+
+				while (iterator.hasNext()) {
+					AttributeTag tag = iterator.next();
+					Attribute attributeValue = attributeList.get(tag);
+
+					// affected sop class
+					if (tag.equals(DICOM_DICTIONARY.getTagFromName("AffectedSOPClassUID"))) {
+						try {
+							String fieldValue = attributeValue.getDelimitedStringValuesOrEmptyString();
+							//See GazelleSOPClassDescriptions in DicomSCPScreener for more descriptions
+							String affectedSopClassUID = SOPClassDescriptions.getDescriptionFromUID(fieldValue);
+							if (affectedSopClassUID == null || affectedSopClassUID.equals("")) {
+								affectedSopClassUID = fieldValue;
+							}
+							infoAffectedSOPClassUID=affectedSopClassUID;
+
+						} catch (Exception e) {
+							e.printStackTrace();
+						}
+					}
+					// Command field
+					if (tag.equals(DICOM_DICTIONARY.getTagFromName("CommandField"))) {
+						try {
+							int[] integerValues = attributeValue.getIntegerValues();
+							for (Integer fieldValue : integerValues) {
+								String commandFieldTmp = MessageServiceElementCommand_.toString(fieldValue);
+								infoCommandField=commandFieldTmp;
+							}
+						} catch (Exception e) {
+							e.printStackTrace();
+						}
+					}
+					// requested sop class
+					if (tag.equals(DICOM_DICTIONARY.getTagFromName("RequestedSOPClassUID"))) {
+						try {
+							String fieldValue = attributeValue.getDelimitedStringValuesOrEmptyString();
+							//See GazelleSOPClassDescriptions in DicomSCPScreener for more descriptions
+							String requestedSopClassUID = SOPClassDescriptions.getDescriptionFromUID(fieldValue);
+							if (requestedSopClassUID == null || requestedSopClassUID.equals("")) {
+								requestedSopClassUID = fieldValue;
+							}
+							infoRequestedSOPClassUID=requestedSopClassUID;
+						} catch (Exception e) {
+							e.printStackTrace();
+						}
+					}
+				}
+			} catch (IOException e) {
+				e.printStackTrace();
+			} catch (DicomException e) {
+				e.printStackTrace();
+			}
+		}
+	}
+
 	public String getFileDump() {
 		return fileDump;
 	}
-- 
GitLab