예제 #1
0
 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()]);
 }
예제 #2
0
 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);
 }
예제 #3
0
 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));
   }
 }
예제 #4
0
 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);
   }
 }
예제 #5
0
 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);
     }
   }
 }
예제 #6
0
 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);
   }
 }
예제 #7
0
 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);
   }
 }
예제 #8
0
 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);
   }
 }
예제 #9
0
 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);
   }
 }
예제 #10
0
 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);
 }
예제 #11
0
 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);
   }
 }
 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);
   }
 }
예제 #13
0
  private boolean checkDataset(Dataset ds) {
    boolean ok = true;
    for (Iterator it = ds.iterator(); it.hasNext(); ) {
      DcmElement el = (DcmElement) it.next();
      int tag = 0;
      try {
        tag = el.tag();
      } catch (Exception useZero) {
      }
      String command = scriptTable.get(new Integer(tag));
      if (command != null) {
        if (el.vr() == VRs.SQ) {
          Matcher processMatcher = processPattern.matcher(command);
          if (processMatcher.find()) {
            int i = 0;
            Dataset child;
            while ((child = el.getItem(i++)) != null) {
              ok &= checkDataset(child);
            }
          }
        } else {
          Matcher lookupMatcher = lookupPattern.matcher(command);
          // logger.info("Parsing: "+command);
          while (lookupMatcher.find()) {

            int nGroups = lookupMatcher.groupCount();
            String element = lookupMatcher.group(1).trim();
            String keyType = lookupMatcher.group(2).trim() + "/";
            String action = (nGroups > 2) ? lookupMatcher.group(3).trim() : "";
            String regex = (nGroups > 3) ? lookupMatcher.group(4).trim() : "";

            // logger.info("...nGroups  = "+nGroups);
            // logger.info("...element: |"+element+"|");
            // logger.info("...keyType: |"+keyType+"|");
            // logger.info("...action : |"+action+"|");
            // logger.info("...regex:   |"+regex+"|");

            int targetTag = (element.equals("this") ? tag : DicomObject.getElementTag(element));
            String targetValue = handleNull(ds.getString(targetTag));

            if (!targetValue.equals("")) {
              String key = keyType + targetValue;
              if (lutProps.getProperty(key) == null) {
                boolean there = false;
                if (action.equals("keep")
                    || action.equals("skip")
                    || action.equals("remove")
                    || action.equals("empty")
                    || action.equals("default")) there = true;
                else if (action.equals("ignore")) {
                  regex = removeQuotes(regex);
                  there = targetValue.matches(regex);
                }
                try {
                  if (!there) {
                    index.insert(key, keyType, true);
                    ok = false;
                  }
                } catch (Exception ignore) {
                }
              }
            }
          }
        }
      }
    }
    return ok;
  }