private String[] toIuids(Dataset ds, boolean seriesIuids) throws DcmServiceException { List iuids = new ArrayList(); DcmElement sersq = ds.get(Tags.RefSeriesSeq); if (sersq == null) { throw new DcmServiceException(Status.MissingAttribute, "Missing Referenced Series Seq."); } for (int i = 0, n = sersq.countItems(); i < n; ++i) { Dataset ser = sersq.getItem(i); String siuid = ser.getString(Tags.SeriesInstanceUID); if (siuid == null) { throw new DcmServiceException(Status.MissingAttribute, "Missing Series Instance UID"); } if (seriesIuids) { iuids.add(siuid); } else { DcmElement sops = ser.get(Tags.RefSOPSeq); if (sops == null) { throw new DcmServiceException(Status.MissingAttribute, "Missing Referenced SOP Seq."); } for (int j = 0, m = sops.countItems(); j < m; ++j) { Dataset sop = sops.getItem(i); String iuid = sop.getString(Tags.RefSOPInstanceUID); if (iuid == null) { throw new DcmServiceException( Status.MissingAttribute, "Missing Referenced SOP Instance UID"); } iuids.add(iuid); } } } return (String[]) iuids.toArray(new String[iuids.size()]); }
private void checkUPSPerformedProcedure(Dataset rqData) throws DcmServiceException { DcmElement sq = rqData.get(Tags.UPSPerformedProcedureSeq); if (sq == null || sq.isEmpty()) return; int n = sq.countItems(); if (n > 1) throw new DcmServiceException( Status.InvalidAttributeValue, errorMessage("More than 1 item of Attribute: ", Tags.UPSPerformedProcedureSeq)); Dataset item = sq.getItem(); checkActualHumanPerformers(item); checkCodeItem( item, ItemCount.MULTIPLE, Tags.PerformedStationNameCodeSeq, Tags.UPSPerformedProcedureSeq); checkCodeItem( item, ItemCount.MULTIPLE, Tags.PerformedStationClassCodeSeq, Tags.UPSPerformedProcedureSeq); checkCodeItem( item, ItemCount.MULTIPLE, Tags.PerformedStationGeographicLocationCodeSeq, Tags.UPSPerformedProcedureSeq); checkCodeItem( item, ItemCount.MULTIPLE, Tags.PerformedProcessingApplicationsCodeSeq, Tags.UPSPerformedProcedureSeq); checkCodeItem( item, ItemCount.SINGLE, Tags.PerformedWorkitemCodeSeq, Tags.UPSPerformedProcedureSeq); checkContentItem(item, Tags.PerformedProcessingParametersSeq, Tags.UPSPerformedProcedureSeq); checkImageSOPInstanceAndSourceReference( item, Tags.OutputInformationSeq, Tags.UPSPerformedProcedureSeq); }
private static void checkContentItem(Dataset rqData, int tag, int... sqTags) throws DcmServiceException { DcmElement sq = rqData.get(tag); if (sq == null || sq.isEmpty()) return; int[] sqTags1 = cat(sqTags, tag); for (int i = 0, n = sq.countItems(); i < n; i++) { Dataset item = sq.getItem(i); type1(item, Tags.ValueType, sqTags1); type1(item, Tags.ConceptNameCodeSeq, sqTags1); checkCodeItem(item, ItemCount.SINGLE, Tags.ConceptNameCodeSeq, sqTags1); String valueType = item.getString(Tags.ValueType); if (valueType.equals("DATETIME")) type1(item, Tags.DateTime, sqTags1); else if (valueType.equals("DATE")) type1(item, Tags.Date, sqTags1); else if (valueType.equals("TIME")) type1(item, Tags.Time, sqTags1); else if (valueType.equals("PNAME")) type1(item, Tags.PersonName, sqTags1); else if (valueType.equals("UIDREF")) type1(item, Tags.UID, sqTags1); else if (valueType.equals("TEXT")) type1(item, Tags.TextValue, sqTags1); else if (valueType.equals("CODE")) { type1(item, Tags.ConceptCodeSeq, sqTags1); checkCodeItem(item, ItemCount.SINGLE, Tags.ConceptCodeSeq, sqTags1); } else if (valueType.equals("NUMERIC")) { type1(item, Tags.NumericValue, sqTags1); type1(item, Tags.MeasurementUnitsCodeSeq, sqTags1); checkCodeItem(item, ItemCount.SINGLE, Tags.MeasurementUnitsCodeSeq, sqTags1); } else throw new DcmServiceException( Status.InvalidAttributeValue, errorMessage("Invalid Value Type: " + valueType + " ", Tags.ValueType, sqTags1)); } }
private void checkUPSCommunicationsURI(Dataset progressInfo) throws DcmServiceException { DcmElement sq = progressInfo.get(Tags.UPSCommunicationsURISeq); if (sq == null) return; for (int i = 0, n = sq.countItems(); i < n; i++) { Dataset item = sq.getItem(i); type1(item, Tags.ContactURI, Tags.UPSProgressInformationSeq, Tags.UPSCommunicationsURISeq); } }
private static void checkImageSOPInstanceAndSourceReference( Dataset rqData, int tag, int... sqTags) throws DcmServiceException { DcmElement sq = rqData.get(tag); if (sq == null) return; int[] sqTags1 = cat(sqTags, tag); int[] sqTags2 = cat(sqTags1, Tags.RefSOPSeq); for (int i = 0, n = sq.countItems(); i < n; i++) { Dataset item = sq.getItem(i); type1(item, Tags.RefSOPSeq, sqTags1); DcmElement refSOPSeq = item.get(Tags.RefSOPSeq); for (int j = 0, m = refSOPSeq.countItems(); j < m; j++) { Dataset refSOP = refSOPSeq.getItem(j); type1(refSOP, Tags.RefSOPClassUID, sqTags2); type1(refSOP, Tags.RefSOPInstanceUID, sqTags2); } } }
private static void checkScheduledHumanPerformers(Dataset rqData) throws DcmServiceException { DcmElement sq = rqData.get(Tags.ScheduledHumanPerformersSeq); if (sq == null) return; for (int i = 0, n = sq.countItems(); i < n; i++) { Dataset item = sq.getItem(i); type1(item, Tags.HumanPerformerCodeSeq, Tags.ScheduledHumanPerformersSeq); checkCodeItem( item, ItemCount.SINGLE, Tags.HumanPerformerCodeSeq, Tags.ScheduledHumanPerformersSeq); type1(item, Tags.HumanPerformerName, Tags.ScheduledHumanPerformersSeq); type1(item, Tags.HumanPerformerOrganization, Tags.ScheduledHumanPerformersSeq); } }
private static void checkRelatedProcedureSteps(Dataset rqData) throws DcmServiceException { DcmElement sq = rqData.get(Tags.RelatedProcedureStepSeq); if (sq == null) return; for (int i = 0, n = sq.countItems(); i < n; i++) { Dataset item = sq.getItem(i); type1(item, Tags.RefSOPClassUID, Tags.RelatedProcedureStepSeq); type1(item, Tags.RefSOPInstanceUID, Tags.RelatedProcedureStepSeq); type1(item, Tags.PurposeOfReferenceCodeSeq, Tags.RelatedProcedureStepSeq); checkCodeItem( item, ItemCount.SINGLE, Tags.PurposeOfReferenceCodeSeq, Tags.RelatedProcedureStepSeq); } }
private static void checkActualHumanPerformers(Dataset performedProcedure) throws DcmServiceException { DcmElement sq = performedProcedure.get(Tags.ActualHumanPerformersSeq); if (sq == null) return; for (int i = 0, n = sq.countItems(); i < n; i++) { Dataset item = sq.getItem(i); checkCodeItem( item, ItemCount.SINGLE, Tags.HumanPerformerCodeSeq, Tags.ActualHumanPerformersSeq, Tags.UPSPerformedProcedureSeq); } }
private static void checkReferencedRequests(Dataset rqData) throws DcmServiceException { DcmElement sq = rqData.get(Tags.RefRequestSeq); if (sq == null) return; for (int i = 0, n = sq.countItems(); i < n; i++) { Dataset item = sq.getItem(i); type1(item, Tags.StudyInstanceUID, Tags.RefRequestSeq); type2(item, Tags.AccessionNumber, Tags.RefRequestSeq); type2(item, Tags.RequestedProcedureID, Tags.RefRequestSeq); type2(item, Tags.RequestedProcedureDescription, Tags.RefRequestSeq); type2(item, Tags.RequestedProcedureCodeSeq, Tags.RefRequestSeq); checkCodeItem(item, ItemCount.SINGLE, Tags.RequestedProcedureCodeSeq, Tags.RefRequestSeq); checkCodeItem( item, ItemCount.MULTIPLE, Tags.ReasonforRequestedProcedureCodeSeq, Tags.RefRequestSeq); } }
private void checkUPSProgressInformation(Dataset rqData) throws DcmServiceException { DcmElement sq = rqData.get(Tags.UPSProgressInformationSeq); if (sq == null || sq.isEmpty()) return; int n = sq.countItems(); if (n > 1) throw new DcmServiceException( Status.InvalidAttributeValue, errorMessage("More than 1 item of Attribute: ", Tags.UPSProgressInformationSeq)); Dataset item = sq.getItem(); checkUPSCommunicationsURI(item); checkCodeItem( item, ItemCount.MULTIPLE, Tags.UPSDiscontinuationReasonCodeSeq, Tags.UPSProgressInformationSeq); }
private static void checkCodeItem(Dataset rqData, ItemCount itemCount, int tag, int... sqTags) throws DcmServiceException { DcmElement sq = rqData.get(tag); if (sq == null || sq.isEmpty()) return; int n = sq.countItems(); if (itemCount == ItemCount.SINGLE && n > 1) throw new DcmServiceException( Status.InvalidAttributeValue, errorMessage("More than 1 item of Attribute: ", tag, sqTags)); int[] sqTags1 = cat(sqTags, tag); for (int i = 0; i < n; i++) { Dataset item = sq.getItem(i); type1(item, Tags.CodeValue, sqTags1); type1(item, Tags.CodingSchemeDesignator, sqTags1); type1(item, Tags.CodeMeaning, sqTags1); } }
/** * @param cuid * @param elem * @return */ private WaveformGroup[] getWaveformGroups(DcmElement elem, String cuid) { float corr = ridSupport.getWaveformCorrection(); int nrOfWFGroups = elem.countItems(); if (nrOfWFGroups == 1) return new WaveformGroup[] {new WaveformGroup(cuid, elem, 0, corr)}; // dont // check // the // only // one ArrayList l = new ArrayList(nrOfWFGroups); for (int i = 0; i < nrOfWFGroups; i++) { try { l.add(new WaveformGroup(cuid, elem, i, corr)); } catch (Exception x) { log.warn("Item " + i + " in Waveform Sequence is not valid! Ignored!!"); } } return (WaveformGroup[]) l.toArray(new WaveformGroup[l.size()]); }
void logInstancesStored(Socket s, SeriesStored seriesStored) { try { if (auditLogger.isAuditLogIHEYr4()) { final AuditLoggerFactory alf = AuditLoggerFactory.getInstance(); Dataset ian = seriesStored.getIAN(); Dataset pps = ian.getItem(Tags.RefPPSSeq); String ppsiuid = pps != null ? pps.getString(Tags.RefSOPInstanceUID) : null; InstancesAction action = alf.newInstancesAction( "Create", ian.getString(Tags.StudyInstanceUID), alf.newPatient(seriesStored.getPatientID(), seriesStored.getPatientName())); action.setMPPSInstanceUID(ppsiuid); action.setAccessionNumber(seriesStored.getAccessionNumber()); DcmElement sq = ian.getItem(Tags.RefSeriesSeq).get(Tags.RefSOPSeq); int n = sq.countItems(); for (int i = 0; i < n; i++) { action.addSOPClassUID(sq.getItem(i).getString(Tags.RefSOPClassUID)); } action.setNumberOfInstances(n); RemoteNode remoteNode; if (s != null) { remoteNode = alf.newRemoteNode(s, seriesStored.getSourceAET()); } else { try { InetAddress iAddr = InetAddress.getLocalHost(); remoteNode = alf.newRemoteNode(iAddr.getHostAddress(), iAddr.getHostName(), "LOCAL"); } catch (UnknownHostException x) { remoteNode = alf.newRemoteNode("127.0.0.1", "localhost", "LOCAL"); } } server.invoke( auditLogger.getAuditLoggerName(), "logInstancesStored", new Object[] {remoteNode, action}, new String[] {RemoteNode.class.getName(), InstancesAction.class.getName()}); } else { InstanceSorter sorter = new InstanceSorter(); Dataset ian = seriesStored.getIAN(); String suid = ian.getString(Tags.StudyInstanceUID); Dataset series = ian.getItem(Tags.RefSeriesSeq); DcmElement refSops = series.get(Tags.RefSOPSeq); for (int i = 0, n = refSops.countItems(); i < n; i++) { final Dataset refSop = refSops.getItem(i); sorter.addInstance( suid, refSop.getString(Tags.RefSOPClassUID), refSop.getString(Tags.RefSOPInstanceUID), null); } InstancesTransferredMessage msg = new InstancesTransferredMessage(InstancesTransferredMessage.CREATE); String srcAET = seriesStored.getSourceAET(); String srcHost = s != null ? AuditMessage.hostNameOf(s.getInetAddress()) : null; String srcID = srcHost != null ? srcHost : srcAET; msg.addSourceProcess(srcID, new String[] {srcAET}, null, srcHost, true); msg.addDestinationProcess( AuditMessage.getProcessID(), calledAETs, AuditMessage.getProcessName(), AuditMessage.getLocalHostName(), false); msg.addPatient(seriesStored.getPatientID(), formatPN(seriesStored.getPatientName())); String accno = seriesStored.getAccessionNumber(); Dataset pps = ian.getItem(Tags.RefPPSSeq); ParticipantObjectDescription desc = new ParticipantObjectDescription(); if (accno != null) { desc.addAccession(accno); } if (pps != null) { desc.addMPPS(pps.getString(Tags.RefSOPInstanceUID)); } for (String cuid : sorter.getCUIDs(suid)) { ParticipantObjectDescription.SOPClass sopClass = new ParticipantObjectDescription.SOPClass(cuid); sopClass.setNumberOfInstances(sorter.countInstances(suid, cuid)); desc.addSOPClass(sopClass); } msg.addStudy(ian.getString(Tags.StudyInstanceUID), desc); msg.validate(); Logger.getLogger("auditlog").info(msg); } } catch (Exception e) { log.warn("Audit Log failed:", e); } }