Java Code Examples for org.dcm4che3.util.TagUtils#toHexString()
The following examples show how to use
org.dcm4che3.util.TagUtils#toHexString() .
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: 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 2
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 3
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 4
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 5
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 6
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 7
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 8
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 9
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 10
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(); }