org.dcm4che3.util.TagUtils Java Examples
The following examples show how to use
org.dcm4che3.util.TagUtils.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AttributesUtil.java From healthcare-dicom-dicomweb-adapter with Apache License 2.0 | 6 votes |
/** * Converts QIDO_RS json reply to dcm4che Attributes */ public static Attributes jsonToAttributes(JSONObject jsonDataset) throws DicomServiceException { Attributes attributes = new Attributes(); for (String tag : jsonDataset.keySet()) { JSONObject element = jsonDataset.getJSONObject(tag); int tagInt = TagUtils.forName(tag); VR vr = VR.valueOf(element.getString("vr")); if (isBinaryVr(vr)) { throw new DicomServiceException(Status.ProcessingFailure, "Binary VR not supported: " + vr.toString()); } else if (element.has("Value")) { setAttributeValue(attributes, tagInt, vr, (JSONArray) element.get("Value")); } else { attributes.setValue(tagInt, vr, null); } } return attributes; }
Example #2
Source File: AttributesUtilTest.java From healthcare-dicom-dicomweb-adapter with Apache License 2.0 | 6 votes |
@Test public void testAttributesToQidoPathArray_manyModalitiesSet() throws Exception { Attributes attrs = new Attributes(); attrs.setString(Tag.QueryRetrieveLevel, VR.CS, "IMAGE"); attrs.setString(Tag.ModalitiesInStudy, VR.CS, "MG", "CS", "CR"); String[] results = AttributesUtil.attributesToQidoPathArray(attrs); assertThat(results.length).isEqualTo(3); assertThat(results[0]).isEqualTo( "instances?limit=50000&" + TagUtils.toHexString(Tag.ModalitiesInStudy) + "=MG&"); assertThat(results[1]).isEqualTo( "instances?limit=50000&" + TagUtils.toHexString(Tag.ModalitiesInStudy) + "=CS&"); assertThat(results[2]).isEqualTo( "instances?limit=50000&" + TagUtils.toHexString(Tag.ModalitiesInStudy) + "=CR&"); }
Example #3
Source File: AttributesUtilTest.java From healthcare-dicom-dicomweb-adapter with Apache License 2.0 | 6 votes |
@Test public void testJsonToAttributes_integerString() throws Exception { // can be parsed as either string or int. JSONObject jsonObj = new JSONObject("{\"" + TagUtils.toHexString(Tag.InstanceNumber) + "\": {\"vr\": \"IS\",\"Value\": [" + Integer.MAX_VALUE + "]}}"); Attributes attrs = AttributesUtil.jsonToAttributes(jsonObj); Attributes expectedAsInt = new Attributes(); expectedAsInt.setInt(Tag.InstanceNumber, VR.IS, Integer.MAX_VALUE); assertThat(attrs).isEqualTo(expectedAsInt); Attributes expectedAsString = new Attributes(); expectedAsString.setString(Tag.InstanceNumber, VR.IS, String.valueOf(Integer.MAX_VALUE)); assertThat(attrs).isEqualTo(expectedAsString); }
Example #4
Source File: AttributesUtilTest.java From healthcare-dicom-dicomweb-adapter with Apache License 2.0 | 6 votes |
@Test public void testJsonToAttributes_sequence() throws Exception { JSONObject jsonObj = new JSONObject("{\"" + TagUtils.toHexString(Tag.FrameContentSequence) + "\": {\"vr\": \"SQ\", \"Value\": " + " [{ \"" + TagUtils.toHexString(Tag.DimensionIndexValues) + "\": {\"vr\": \"UL\", \"Value\": [1,1]} }] }}"); Attributes attrs = AttributesUtil.jsonToAttributes(jsonObj); Attributes expected = new Attributes(); Sequence sequence = expected.newSequence(Tag.FrameContentSequence, 1); Attributes sequenceElement = new Attributes(); sequenceElement.setInt(Tag.DimensionIndexValues, VR.UL, 1, 1); sequence.add(sequenceElement); assertThat(attrs).isEqualTo(expected); }
Example #5
Source File: AttributesUtilTest.java From healthcare-dicom-dicomweb-adapter with Apache License 2.0 | 6 votes |
@Test public void testJsonToAttributes_patientName() throws Exception { JSONObject jsonObj = new JSONObject("{\"" + TagUtils.toHexString(Tag.PatientName) + "\": {\"vr\": \"PN\",\"Value\": [{" + "\"Alphabetic\": \"Yamada^Tarou\", " + "\"Ideographic\": \"山田^太郎\", " + "\"Phonetic\": \"やまだ^たろう\", " + "}]}}"); Attributes attrs = AttributesUtil.jsonToAttributes(jsonObj); Attributes expected = new Attributes(); expected.setString(Tag.PatientName, VR.PN, "Yamada^Tarou=山田^太郎=やまだ^たろう"); assertThat(attrs).isEqualTo(expected); }
Example #6
Source File: ServletUtil.java From weasis-pacs-connector with Eclipse Public License 2.0 | 5 votes |
public static Integer getIntegerFromDicomElement(Attributes dicom, int tag, String privateCreatorID, Integer defaultValue) { if (dicom == null || !dicom.containsValue(tag)) { return defaultValue; } try { return dicom.getInt(privateCreatorID, tag, defaultValue == null ? 0 : defaultValue); } catch (NumberFormatException e) { LOGGER.error("Cannot parse Integer of {}: {} ", TagUtils.toString(tag), e.getMessage()); //$NON-NLS-1$ } return defaultValue; }
Example #7
Source File: CFindService.java From healthcare-dicom-dicomweb-adapter with Apache License 2.0 | 5 votes |
private static String getResultKey(JSONObject jsonObject) { return AttributesUtil.getTagValueOrNull(jsonObject, TagUtils.toHexString(Tag.StudyInstanceUID)) + "_" + AttributesUtil.getTagValueOrNull(jsonObject, TagUtils.toHexString(Tag.SeriesInstanceUID)) + "_" + AttributesUtil.getTagValueOrNull(jsonObject, TagUtils.toHexString(Tag.SOPInstanceUID)); }
Example #8
Source File: StoreSCU.java From weasis-dicom-tools with Eclipse Public License 2.0 | 5 votes |
private void onCStoreRSP(Attributes cmd, File f) { int status = cmd.getInt(Tag.Status, -1); state.setStatus(status); ProgressStatus ps; switch (status) { case Status.Success: totalSize += f.length(); ps = ProgressStatus.COMPLETED; break; case Status.CoercionOfDataElements: case Status.ElementsDiscarded: case Status.DataSetDoesNotMatchSOPClassWarning: totalSize += f.length(); ps = ProgressStatus.WARNING; System.err.println(MessageFormat.format("WARNING: Received C-STORE-RSP with Status {0}H for {1}", TagUtils.shortToHexString(status), f)); System.err.println(cmd); break; default: ps = ProgressStatus.FAILED; System.err.println(MessageFormat.format("ERROR: Received C-STORE-RSP with Status {0}H for {1}", TagUtils.shortToHexString(status), f)); System.err.println(cmd); } ServiceUtil.notifyProgession(state.getProgress(), cmd, ps, filesScanned); }
Example #9
Source File: Xml.java From weasis-dicom-tools with Eclipse Public License 2.0 | 5 votes |
static void addXmlAttribute(int tagID, String value, Writer result) throws IOException { if (StringUtil.hasText(value)) { String key = ElementDictionary.getStandardElementDictionary().keywordOf(tagID); if (key == null) { LOGGER.error("Cannot find keyword of tagID {}", TagUtils.toString(tagID)); } else { result.append(key); result.append("=\""); result.append(EscapeChars.forXML(value)); result.append("\" "); } } }
Example #10
Source File: DestinationFilter.java From healthcare-dicom-dicomweb-adapter with Apache License 2.0 | 5 votes |
public DestinationFilter(String filterString) { String aeTitle = null; this.filterAttrs = new Attributes(); if (filterString != null && filterString.length() > 0) { String[] params = filterString.split("&"); for (String param : params) { String[] keyValue = param.split("="); if (keyValue.length != 2) { throw new IllegalArgumentException( "Invalid filter parameter: " + param); } if (keyValue[0].equals(AE_TITLE)) { aeTitle = keyValue[1]; } else { int tag = TagUtils.forName(keyValue[0]); if (tag == -1) { throw new IllegalArgumentException( "Invalid tag in filter string: " + keyValue[0]); } this.filterAttrs.setString(tag, VR.LO, keyValue[1]); // VR just needs to be any string type for match() } } } this.aeTitle = aeTitle; }
Example #11
Source File: CStoreServiceTest.java From healthcare-dicom-dicomweb-adapter with Apache License 2.0 | 5 votes |
@Test public void testCStoreService_map_tagByHex() throws Exception { basicCStoreServiceTest( true, HttpStatusCodes.STATUS_CODE_SERVER_ERROR, Status.Success, new MockDestinationConfig[] { new MockDestinationConfig(TagUtils.toHexString(Tag.StudyDate) + "=19921012", false, HttpStatusCodes.STATUS_CODE_OK) }); }
Example #12
Source File: AttributesUtilTest.java From healthcare-dicom-dicomweb-adapter with Apache License 2.0 | 5 votes |
@Test public void testJsonToAttributes_float() throws Exception { JSONObject jsonObj = new JSONObject("{\"" + TagUtils.toHexString(Tag.DisplayedZValue) + "\": {\"vr\": \"FL\",\"Value\": [1.25]}}"); Attributes attrs = AttributesUtil.jsonToAttributes(jsonObj); Attributes expected = new Attributes(); expected.setFloat(Tag.DisplayedZValue, VR.FL, 1.25f); assertThat(attrs).isEqualTo(expected); }
Example #13
Source File: AttributesUtilTest.java From healthcare-dicom-dicomweb-adapter with Apache License 2.0 | 5 votes |
@Test public void testJsonToAttributes_double() throws Exception { JSONObject jsonObj = new JSONObject("{\"" + TagUtils.toHexString(Tag.EventTimeOffset) + "\": {\"vr\": \"FD\",\"Value\": [1.25]}}"); Attributes attrs = AttributesUtil.jsonToAttributes(jsonObj); Attributes expected = new Attributes(); expected.setDouble(Tag.EventTimeOffset, VR.FD, 1.25); assertThat(attrs).isEqualTo(expected); }
Example #14
Source File: AttributesUtilTest.java From healthcare-dicom-dicomweb-adapter with Apache License 2.0 | 5 votes |
@Test public void testJsonToAttributes_stringType() throws Exception { JSONObject jsonObj = new JSONObject("{\"" + TagUtils.toHexString(Tag.QueryRetrieveLevel) + "\": {\"vr\": \"CS\",\"Value\": [\"IMAGE\"]}}"); Attributes attrs = AttributesUtil.jsonToAttributes(jsonObj); Attributes expected = new Attributes(); expected.setString(Tag.QueryRetrieveLevel, VR.CS, "IMAGE"); assertThat(attrs).isEqualTo(expected); }
Example #15
Source File: AttributesUtilTest.java From healthcare-dicom-dicomweb-adapter with Apache License 2.0 | 5 votes |
@Test(expected = NumberFormatException.class) public void testJsonToAttributes_intType_notInt() throws Exception { JSONObject jsonObj = new JSONObject("{\"" + TagUtils.toHexString(Tag.ConcatenationFrameOffsetNumber) + "\": {\"vr\": \"UL\",\"Value\": [\"Gotcha\"]}}"); AttributesUtil.jsonToAttributes(jsonObj); }
Example #16
Source File: AttributesUtilTest.java From healthcare-dicom-dicomweb-adapter with Apache License 2.0 | 5 votes |
@Test public void testJsonToAttributes_intType() throws Exception { JSONObject jsonObj = new JSONObject("{\"" + TagUtils.toHexString(Tag.ConcatenationFrameOffsetNumber) + "\": {\"vr\": \"UL\",\"Value\": [1, 1]}}"); Attributes attrs = AttributesUtil.jsonToAttributes(jsonObj); Attributes expected = new Attributes(); expected.setInt(Tag.ConcatenationFrameOffsetNumber, VR.UL, 1, 1); assertThat(attrs).isEqualTo(expected); }
Example #17
Source File: AttributesUtilTest.java From healthcare-dicom-dicomweb-adapter with Apache License 2.0 | 5 votes |
@Test public void testJsonToAttributes_decimalString() throws Exception { String value = "12345678901234567890.1234567890"; JSONObject jsonObj = new JSONObject("{\"" + TagUtils.toHexString(Tag.DecimalVisualAcuity) + "\": {\"vr\": \"DS\",\"Value\": [" + value + "]}}"); Attributes attrs = AttributesUtil.jsonToAttributes(jsonObj); Attributes expected = new Attributes(); expected.setString(Tag.DecimalVisualAcuity, VR.DS, value); assertThat(attrs).isEqualTo(expected); }
Example #18
Source File: AttributesUtilTest.java From healthcare-dicom-dicomweb-adapter with Apache License 2.0 | 5 votes |
@Test public void testAttributesToQidoPathArray_oneModalitySet() throws Exception { Attributes attrs = new Attributes(); attrs.setString(Tag.QueryRetrieveLevel, VR.CS, "IMAGE"); attrs.setString(Tag.ModalitiesInStudy, VR.CS, "MG"); String[] results = AttributesUtil.attributesToQidoPathArray(attrs); assertThat(results.length).isEqualTo(1); assertThat(results[0]).isEqualTo( "instances?limit=50000&" + TagUtils.toHexString(Tag.ModalitiesInStudy) + "=MG&"); }
Example #19
Source File: AttributesUtilTest.java From healthcare-dicom-dicomweb-adapter with Apache License 2.0 | 5 votes |
@Test public void testAttributesToQidoPath_urlEncode() throws Exception { Attributes attrs = new Attributes(); attrs.setString(Tag.QueryRetrieveLevel, VR.CS, "IMAGE"); attrs.setString(Tag.PatientName, VR.CS, "%&#^ "); String result = AttributesUtil.attributesToQidoPath(attrs); assertThat(result).isEqualTo( "instances?limit=50000&" + TagUtils.toHexString(Tag.PatientName) + "=%25%26%23%5E&"); }
Example #20
Source File: AttributesUtilTest.java From healthcare-dicom-dicomweb-adapter with Apache License 2.0 | 5 votes |
@Test public void testAttributesToQidoPath_simple() throws Exception { Attributes attrs = new Attributes(); attrs.setString(Tag.QueryRetrieveLevel, VR.CS, "IMAGE"); attrs.setString(Tag.SOPInstanceUID, VR.UI, "123"); String result = AttributesUtil.attributesToQidoPath(attrs); assertThat(result).isEqualTo( "instances?limit=50000&" + TagUtils.toHexString(Tag.SOPInstanceUID) + "=123&"); }
Example #21
Source File: TestUtils.java From healthcare-dicom-dicomweb-adapter with Apache License 2.0 | 5 votes |
public static JSONObject dummyQidorsInstance() { JSONObject instance = new JSONObject(); instance.put(TagUtils.toHexString(Tag.StudyInstanceUID), dummyQidorsTag()); instance.put(TagUtils.toHexString(Tag.SeriesInstanceUID), dummyQidorsTag()); instance.put(TagUtils.toHexString(Tag.SOPInstanceUID), dummyQidorsTag()); instance.put(TagUtils.toHexString(Tag.SOPClassUID), dummyQidorsTag()); return instance; }
Example #22
Source File: AttributesUtil.java From healthcare-dicom-dicomweb-adapter with Apache License 2.0 | 4 votes |
/** * Returns corresponding QIDO-RS path * * @param attrs dcm4che Attributes to convert * @param includeFields additonal includeFields for QIDO-RS */ public static String attributesToQidoPath(Attributes attrs, String... includeFields) throws DicomServiceException { HashSet<Integer> nonEmptyKeys = new HashSet<>(); HashSet<String> includeFieldSet = new HashSet<>(Arrays.asList(includeFields)); // SpecificCharacterSet is not supported, and passing it as param or include would be wrong attrs.remove(Tag.SpecificCharacterSet); for (int tag : attrs.tags()) { if (attrs.containsValue(tag)) { nonEmptyKeys.add(tag); } else { includeFieldSet.add(TagUtils.toHexString(tag)); } } StringBuilder qidoPath = new StringBuilder(); if (nonEmptyKeys.contains(Tag.QueryRetrieveLevel)) { switch (attrs.getString(Tag.QueryRetrieveLevel)) { case "STUDY": qidoPath.append("studies?limit=" + STUDIES_SERIES_LIMIT + "&"); break; case "SERIES": qidoPath.append("series?limit=" + STUDIES_SERIES_LIMIT + "&"); break; case "IMAGE": qidoPath.append("instances?limit=" + INSTANCES_LIMIT + "&"); break; default: throw new DicomServiceException(Status.ProcessingFailure, "Invalid QueryRetrieveLevel specified"); } nonEmptyKeys.remove(Tag.QueryRetrieveLevel); } else { throw new DicomServiceException(Status.ProcessingFailure, "No QueryRetrieveLevel specified"); } if (includeFieldSet.size() > 0) { for (String includeField : includeFieldSet) { qidoPath.append("includefield=" + includeField + "&"); } } for (int keyTag : nonEmptyKeys) { // non-string type search keys don't seem to exist // multiple values are valid for UID lists, but unsupported by api. Invalid for other VRs. String[] values = attrs.getStrings(keyTag); if (values.length > 1) { throw new DicomServiceException(Status.ProcessingFailure, "Multiple values per tag not supported, tag: " + TagUtils.toHexString(keyTag)); } for (String value : values) { String encodedValue; encodedValue = URLEncoder.encode(value, StandardCharsets.UTF_8); qidoPath.append(TagUtils.toHexString(keyTag) + "=" + encodedValue + "&"); } } return qidoPath.toString(); }
Example #23
Source File: StoreFromStreamSCU.java From weasis-dicom-tools with Eclipse Public License 2.0 | 4 votes |
/** * @see <a * href="ERROR CODE STATUS">https://github.com/dcm4che/dcm4che/blob/master/dcm4che-net/src/main/java/org/dcm4che3/net/Status.java</a> */ private void onCStoreRSP(Attributes cmd) { int status = cmd.getInt(Tag.Status, -1); state.setStatus(status); ProgressStatus ps; switch (status) { case Status.Success: ps = ProgressStatus.COMPLETED; break; case Status.CoercionOfDataElements: case Status.ElementsDiscarded: case Status.DataSetDoesNotMatchSOPClassWarning: ps = ProgressStatus.WARNING; if (lastStatusCode != status && nbStatusLog < 3) { nbStatusLog++; lastStatusCode = status; if (LOGGER.isDebugEnabled()) { LOGGER.warn("Received C-STORE-RSP with Status {}H{}", TagUtils.shortToHexString(status), "\r\n" + cmd.toString()); } else { LOGGER.warn("Received C-STORE-RSP with Status {}H", TagUtils.shortToHexString(status)); } } break; default: ps = ProgressStatus.FAILED; if (lastStatusCode != status && nbStatusLog < 3) { nbStatusLog++; lastStatusCode = status; if (LOGGER.isDebugEnabled()) { LOGGER.error("Received C-STORE-RSP with Status {}H{}", TagUtils.shortToHexString(status), "\r\n" + cmd.toString()); } else { LOGGER.error("Received C-STORE-RSP with Status {}H", TagUtils.shortToHexString(status)); } } } ServiceUtil.notifyProgession(state.getProgress(), cmd, ps, numberOfSuboperations); }