Java Code Examples for org.dcm4che3.data.Attributes#getString()
The following examples show how to use
org.dcm4che3.data.Attributes#getString() .
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: DicomQueryConfiguration.java From weasis-pacs-connector with Eclipse Public License 2.0 | 6 votes |
private void fillSeries(Attributes studyDataSet) { String studyInstanceUID = studyDataSet.getString(Tag.StudyInstanceUID); if (StringUtil.hasText(studyInstanceUID)) { DicomParam[] keysSeries = { // Matching Keys new DicomParam(Tag.StudyInstanceUID, studyInstanceUID), // Return Keys CFind.SeriesInstanceUID, CFind.Modality, CFind.SeriesNumber, CFind.SeriesDescription }; DicomState state = CFind.process(advancedParams, callingNode, calledNode, 0, QueryRetrieveLevel.SERIES, keysSeries); LOGGER.debug("C-FIND with StudyInstanceUID {}", state.getMessage()); List<Attributes> series = state.getDicomRSP(); if (series != null && !series.isEmpty()) { // Get patient from each study in case IssuerOfPatientID is different Patient patient = getPatient(studyDataSet); Study study = getStudy(patient, studyDataSet); for (Attributes seriesDataset : series) { fillInstance(seriesDataset, study); } } } }
Example 2
Source File: DicomQueryConfiguration.java From weasis-pacs-connector with Eclipse Public License 2.0 | 6 votes |
private Patient getPatient(Attributes patientDataset) { if (patientDataset == null) { throw new IllegalArgumentException("patientDataset cannot be null"); } fillPatientAttributes(patientDataset); String id = patientDataset.getString(Tag.PatientID, "Unknown"); String ispid = patientDataset.getString(Tag.IssuerOfPatientID); Patient p = getPatient(id, ispid); if (p == null) { p = new Patient(id, ispid); p.setPatientName(patientDataset.getString(Tag.PatientName)); // Only set birth date, birth time is often not consistent (00:00) p.setPatientBirthDate(patientDataset.getString(Tag.PatientBirthDate)); p.setPatientSex(patientDataset.getString(Tag.PatientSex)); addPatient(p); } return p; }
Example 3
Source File: DicomQueryConfiguration.java From weasis-pacs-connector with Eclipse Public License 2.0 | 6 votes |
private static Study getStudy(Patient patient, final Attributes studyDataset) { if (studyDataset == null) { throw new IllegalArgumentException("studyDataset cannot be null"); } String uid = studyDataset.getString(Tag.StudyInstanceUID); Study s = patient.getStudy(uid); if (s == null) { s = new Study(uid); s.setStudyDescription(studyDataset.getString(Tag.StudyDescription)); s.setStudyDate(studyDataset.getString(Tag.StudyDate)); s.setStudyTime(studyDataset.getString(Tag.StudyTime)); s.setAccessionNumber(studyDataset.getString(Tag.AccessionNumber)); s.setStudyID(studyDataset.getString(Tag.StudyID)); s.setReferringPhysicianName(studyDataset.getString(Tag.ReferringPhysicianName)); patient.addStudy(s); } return s; }
Example 4
Source File: DicomQueryConfiguration.java From weasis-pacs-connector with Eclipse Public License 2.0 | 6 votes |
private static Series getSeries(Study study, final Attributes seriesDataset, Properties properties) { if (seriesDataset == null) { throw new IllegalArgumentException("seriesDataset cannot be null"); } String uid = seriesDataset.getString(Tag.SeriesInstanceUID); Series s = study.getSeries(uid); if (s == null) { s = new Series(uid); s.setModality(seriesDataset.getString(Tag.Modality)); s.setSeriesNumber(seriesDataset.getString(Tag.SeriesNumber)); s.setSeriesDescription(seriesDataset.getString(Tag.SeriesDescription)); String wadotTsuid = properties.getProperty("wado.request.tsuid"); if (StringUtil.hasText(wadotTsuid)) { String[] val = wadotTsuid.split(":"); if (val.length > 0) { s.setWadoTransferSyntaxUID(val[0]); } if (val.length > 1) { s.setWadoCompression(val[1]); } } study.addSeries(s); } return s; }
Example 5
Source File: DicomProgress.java From weasis-dicom-tools with Eclipse Public License 2.0 | 5 votes |
public String getErrorComment() { Attributes dcm = attributes; if (dcm == null) { return null; } return dcm.getString(Tag.ErrorComment); }
Example 6
Source File: DefaultAttributeEditor.java From weasis-dicom-tools with Eclipse Public License 2.0 | 5 votes |
@Override public boolean apply(Attributes data, AttributeEditorContext context) { if (data != null) { boolean update = false; if (generateUIDs) { if ("2.25".equals(UIDUtils.getRoot())) { UIDUtils.setRoot("2.25.35"); } // New Study UID String oldStudyUID = data.getString(Tag.StudyInstanceUID); String studyUID = uidMap.computeIfAbsent(oldStudyUID, k -> UIDUtils.createUID()); data.setString(Tag.StudyInstanceUID, VR.UI, studyUID); // New Series UID String oldSeriesUID = data.getString(Tag.SeriesInstanceUID); String seriesUID = uidMap.computeIfAbsent(oldSeriesUID, k -> UIDUtils.createUID()); data.setString(Tag.SeriesInstanceUID, VR.UI, seriesUID); // New Sop UID String iuid = UIDUtils.createUID(); data.setString(Tag.SOPInstanceUID, VR.UI, iuid); update = true; } if (tagToOverride != null && !tagToOverride.isEmpty()) { data.update(Attributes.UpdatePolicy.OVERWRITE, tagToOverride, null); update = true; } return update; } return false; }
Example 7
Source File: StoreScpForward.java From weasis-dicom-tools with Eclipse Public License 2.0 | 5 votes |
@Override protected void store(Association as, PresentationContext pc, Attributes rq, PDVInputStream data, Attributes rsp) throws IOException { Optional<ForwardDicomNode> sourceNode = destinations.keySet().stream().filter(n -> n.getForwardAETitle().equals(as.getCalledAET())).findFirst(); if (!sourceNode.isPresent()) { throw new IllegalStateException("Cannot find the forward AeTitle " + as.getCalledAET()); } ForwardDicomNode fwdNode = sourceNode.get(); List<ForwardDestination> destList = destinations.get(fwdNode); if (destList == null || destList.isEmpty()) { throw new IllegalStateException("No DICOM destinations for " + fwdNode.toString()); } DicomNode callingNode = DicomNode.buildRemoteDicomNode(as); Set<DicomNode> srcNodes = fwdNode.getAcceptedSourceNodes(); boolean valid = srcNodes.isEmpty() || srcNodes.stream().anyMatch(n -> n.getAet().equals(callingNode.getAet()) && (!n.isValidateHostname() || n.equalsHostname(callingNode.getHostname()))); if (!valid) { rsp.setInt(Tag.Status, VR.US, Status.NotAuthorized); LOGGER.error("Refused: not authorized (124H). Source node: {}. SopUID: {}", callingNode, rq.getString(Tag.AffectedSOPInstanceUID)); return; } rsp.setInt(Tag.Status, VR.US, status); try { Params p = new Params(rq.getString(Tag.AffectedSOPInstanceUID), rq.getString(Tag.AffectedSOPClassUID), pc.getTransferSyntax(), priority, data, as); ForwardUtil.storeMulitpleDestination(fwdNode, destList, p); } catch (Exception e) { throw new DicomServiceException(Status.ProcessingFailure, e); } }
Example 8
Source File: StoreSCU.java From weasis-dicom-tools with Eclipse Public License 2.0 | 5 votes |
public boolean addFile(BufferedWriter fileInfos, File f, long endFmi, Attributes fmi, Attributes ds) throws IOException { String cuid = fmi.getString(Tag.MediaStorageSOPClassUID); String iuid = fmi.getString(Tag.MediaStorageSOPInstanceUID); String ts = fmi.getString(Tag.TransferSyntaxUID); if (cuid == null || iuid == null) { return false; } fileInfos.write(iuid); fileInfos.write('\t'); fileInfos.write(cuid); fileInfos.write('\t'); fileInfos.write(ts); fileInfos.write('\t'); fileInfos.write(Long.toString(endFmi)); fileInfos.write('\t'); fileInfos.write(f.getPath()); fileInfos.newLine(); if (rq.containsPresentationContextFor(cuid, ts)) { return true; } if (!rq.containsPresentationContextFor(cuid)) { if (relExtNeg) { rq.addCommonExtendedNegotiation(relSOPClasses.getCommonExtendedNegotiation(cuid)); } if (!ts.equals(UID.ExplicitVRLittleEndian)) { rq.addPresentationContext(new PresentationContext(rq.getNumberOfPresentationContexts() * 2 + 1, cuid, UID.ExplicitVRLittleEndian)); } if (!ts.equals(UID.ImplicitVRLittleEndian)) { rq.addPresentationContext(new PresentationContext(rq.getNumberOfPresentationContexts() * 2 + 1, cuid, UID.ImplicitVRLittleEndian)); } } rq.addPresentationContext(new PresentationContext(rq.getNumberOfPresentationContexts() * 2 + 1, cuid, ts)); return true; }
Example 9
Source File: DicomQueryConfiguration.java From weasis-pacs-connector with Eclipse Public License 2.0 | 5 votes |
private void fillInstance(Attributes seriesDataset, Study study) { String serieInstanceUID = seriesDataset.getString(Tag.SeriesInstanceUID); if (StringUtil.hasText(serieInstanceUID)) { DicomParam[] keysInstance = { // Matching Keys new DicomParam(Tag.StudyInstanceUID, study.getStudyInstanceUID()), new DicomParam(Tag.SeriesInstanceUID, serieInstanceUID), // Return Keys CFind.SOPInstanceUID, CFind.InstanceNumber }; DicomState state = CFind.process(advancedParams, callingNode, calledNode, 0, QueryRetrieveLevel.IMAGE, keysInstance); LOGGER.debug(C_FIND_WITH_SERIESUID, state.getMessage()); List<Attributes> instances = state.getDicomRSP(); if (instances != null && !instances.isEmpty()) { Series s = getSeries(study, seriesDataset, properties); for (Attributes instanceDataSet : instances) { Integer frame = ServletUtil.getIntegerFromDicomElement(instanceDataSet, Tag.InstanceNumber, null); String sopUID = instanceDataSet.getString(Tag.SOPInstanceUID); SopInstance sop = s.getSopInstance(sopUID, frame); if (sop == null) { s.addSopInstance(new SopInstance(sopUID, frame)); } } } } }
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(); }
Example 11
Source File: StoreSCP.java From weasis-dicom-tools with Eclipse Public License 2.0 | 4 votes |
@Override protected void store(Association as, PresentationContext pc, Attributes rq, PDVInputStream data, Attributes rsp) throws IOException { if (authorizedCallingNodes != null && !authorizedCallingNodes.isEmpty()) { DicomNode sourceNode = DicomNode.buildRemoteDicomNode(as); boolean valid = authorizedCallingNodes.stream().anyMatch(n -> n.getAet().equals(sourceNode.getAet()) && (!n.isValidateHostname() || n.equalsHostname(sourceNode.getHostname()))); if (!valid) { rsp.setInt(Tag.Status, VR.US, Status.NotAuthorized); LOGGER.error("Refused: not authorized (124H). Source node: {}. SopUID: {}", sourceNode, rq.getString(Tag.AffectedSOPInstanceUID)); return; } } rsp.setInt(Tag.Status, VR.US, status); String cuid = rq.getString(Tag.AffectedSOPClassUID); String iuid = rq.getString(Tag.AffectedSOPInstanceUID); String tsuid = pc.getTransferSyntax(); File file = new File(storageDir, TMP_DIR + File.separator + iuid); try { Attributes fmi = as.createFileMetaInformation(iuid, cuid, tsuid); storeTo(as, fmi, data, file); String filename; if (filePathFormat == null) { filename = iuid; } else { Attributes a = fmi; Matcher regexMatcher = regex.matcher(filePathFormat.toString()); while (regexMatcher.find()) { if (!regexMatcher.group(1).startsWith("0002")) { a = parse(file); a.addAll(fmi); break; } } filename = filePathFormat.format(a); } renameTo(as, file, new File(storageDir, filename)); } catch (Exception e) { deleteFile(as, file); throw new DicomServiceException(Status.ProcessingFailure, e); } }
Example 12
Source File: DicomQueryConfiguration.java From weasis-pacs-connector with Eclipse Public License 2.0 | 4 votes |
@Override public void buildFromSopInstanceUID(CommonQueryParams params, String... sopInstanceUIDs) { AdvancedParams advParams = advancedParams == null ? new AdvancedParams() : advancedParams; advParams.getQueryOptions().add(QueryOption.RELATIONAL); for (String sopInstanceUID : sopInstanceUIDs) { if (!StringUtil.hasText(sopInstanceUID)) { continue; } DicomParam[] keysInstance = { // Matching Keys new DicomParam(Tag.SOPInstanceUID, sopInstanceUID), // Return Keys CFind.PatientID, CFind.IssuerOfPatientID, CFind.PatientName, CFind.PatientBirthDate, CFind.PatientSex, CFind.ReferringPhysicianName, CFind.StudyDescription, CFind.StudyDate, CFind.StudyTime, CFind.AccessionNumber, CFind.StudyInstanceUID, CFind.StudyID, CFind.SeriesInstanceUID, CFind.Modality, CFind.SeriesNumber, CFind.SeriesDescription }; try { DicomState state = CFind.process(advParams, callingNode, calledNode, 0, QueryRetrieveLevel.IMAGE, keysInstance); LOGGER.debug("C-FIND with sopInstanceUID {}", state.getMessage()); List<Attributes> instances = state.getDicomRSP(); if (instances != null && !instances.isEmpty()) { Attributes dataset = instances.get(0); Patient patient = getPatient(dataset); Study study = getStudy(patient, dataset); Series s = getSeries(study, dataset, properties); for (Attributes instanceDataSet : instances) { Integer frame = ServletUtil.getIntegerFromDicomElement(instanceDataSet, Tag.InstanceNumber, null); String sopUID = instanceDataSet.getString(Tag.SOPInstanceUID); SopInstance sop = s.getSopInstance(sopUID, frame); if (sop == null) { s.addSopInstance(new SopInstance(sopUID, frame)); } } } } catch (Exception e) { String msg = DICOM_QUERY_ERROR + getArchiveConfigName(); LOGGER.error(msg, e); setViewerMessage(new ViewerMessage(msg, e.getMessage(), ViewerMessage.eLevel.ERROR)); } } }