Class JSONRepresentationOfStructuredReportObjectFactory

java.lang.Object
com.pixelmed.dicom.JSONRepresentationOfStructuredReportObjectFactory

public class JSONRepresentationOfStructuredReportObjectFactory extends Object

A class to encode a representation of a DICOM Structured Report object in a JSON form, suitable for analysis as human-readable text.

Note that JSON representations can either contain only the content tree, or also the additional top level DICOM attributes other than those that encode the content tree, as individual DICOM attributes, in the manner of JSONRepresentationOfDicomObjectFactory.

A typical example of usage to extract just the content tree would be:

try {
    AttributeList list = new AttributeList();
    list.read("dicomsrfile",null,true,true);
        StructuredReport sr = new StructuredReport(list);
    JsonArray document = new JSONRepresentationOfStructuredReportObjectFactory().getDocument(sr);
    JSONRepresentationOfStructuredReportObjectFactory.write(System.out,document);
} catch (Exception e) {
    slf4jlogger.error("",e);
 }
 

or to include the top level attributes as well as the content tree, supply the attribute list as well as the parsed SR content to the write() method:

try {
    AttributeList list = new AttributeList();
    list.read("dicomsrfile",null,true,true);
        StructuredReport sr = new StructuredReport(list);
    JsonArray document = new JSONRepresentationOfStructuredReportObjectFactory().getDocument(sr,list);
    JSONRepresentationOfStructuredReportObjectFactory.write(System.out,document);
} catch (Exception e) {
    slf4jlogger.error("",e);
 }
 

or even simpler, if there is no further use for the JSON document or the SR tree model:

try {
    AttributeList list = new AttributeList();
    list.read("dicomsrfile",null,true,true);
    JSONRepresentationOfStructuredReportObjectFactory.createDocumentAndWriteIt(list,System.out);
} catch (Exception e) {
    slf4jlogger.error("",e);
 }
 
See Also:
  • Field Details

    • elideSeparateContinuityOfContent

      protected static boolean elideSeparateContinuityOfContent
    • collapseAttributeValueArrays

      protected static boolean collapseAttributeValueArrays
    • collapseEmptyToNull

      protected static boolean collapseEmptyToNull
    • collapseContentTreeArrays

      protected static boolean collapseContentTreeArrays
    • substituteUIDKeywords

      protected static boolean substituteUIDKeywords
    • useNumberForNumericContentItemValue

      protected static boolean useNumberForNumericContentItemValue
    • symbolSignifyingReservedKeyword

      protected static String symbolSignifyingReservedKeyword
    • businessNameToUseForAnonymousContentItems

      protected static String businessNameToUseForAnonymousContentItems
    • reservedKeywordForCodeValueInBusinessNamesFile

      protected static String reservedKeywordForCodeValueInBusinessNamesFile
    • reservedKeywordForCodingSchemeDesignatorInBusinessNamesFile

      protected static String reservedKeywordForCodingSchemeDesignatorInBusinessNamesFile
    • reservedKeywordForCodeMeaningInBusinessNamesFile

      protected static String reservedKeywordForCodeMeaningInBusinessNamesFile
    • reservedKeywordForValueTypeInBusinessNamesFile

      protected static String reservedKeywordForValueTypeInBusinessNamesFile
    • reservedKeywordForRelationshipTypeInBusinessNamesFile

      protected static String reservedKeywordForRelationshipTypeInBusinessNamesFile
    • reservedKeywordForCodingSchemeVersionInBusinessNamesFile

      protected static String reservedKeywordForCodingSchemeVersionInBusinessNamesFile
    • reservedKeywordForLongCodeValueInBusinessNamesFile

      protected static String reservedKeywordForLongCodeValueInBusinessNamesFile
    • reservedKeywordForURNCodeValueInBusinessNamesFile

      protected static String reservedKeywordForURNCodeValueInBusinessNamesFile
    • reservedKeywordForContextIdentifierInBusinessNamesFile

      protected static String reservedKeywordForContextIdentifierInBusinessNamesFile
    • reservedKeywordForContextUIDInBusinessNamesFile

      protected static String reservedKeywordForContextUIDInBusinessNamesFile
    • reservedKeywordForMappingResourceInBusinessNamesFile

      protected static String reservedKeywordForMappingResourceInBusinessNamesFile
    • reservedKeywordForMappingResourceUIDInBusinessNamesFile

      protected static String reservedKeywordForMappingResourceUIDInBusinessNamesFile
    • reservedKeywordForMappingResourceNameInBusinessNamesFile

      protected static String reservedKeywordForMappingResourceNameInBusinessNamesFile
    • reservedKeywordForContextGroupVersionInBusinessNamesFile

      protected static String reservedKeywordForContextGroupVersionInBusinessNamesFile
    • reservedKeywordForContextGroupExtensionFlagInBusinessNamesFile

      protected static String reservedKeywordForContextGroupExtensionFlagInBusinessNamesFile
    • reservedKeywordForContextGroupLocalVersionInBusinessNamesFile

      protected static String reservedKeywordForContextGroupLocalVersionInBusinessNamesFile
    • reservedKeywordForContextGroupExtensionCreatorUIDInBusinessNamesFile

      protected static String reservedKeywordForContextGroupExtensionCreatorUIDInBusinessNamesFile
    • reservedKeywordForObservationDateTimeAttributeInSRFile

      protected static String reservedKeywordForObservationDateTimeAttributeInSRFile
    • reservedKeywordForObservationUIDAttributeInSRFile

      protected static String reservedKeywordForObservationUIDAttributeInSRFile
    • reservedKeywordForContinuityOfContentAttributeInSRFile

      protected static String reservedKeywordForContinuityOfContentAttributeInSRFile
    • reservedKeywordForTemplateMappingResourceAttributeInSRFile

      protected static String reservedKeywordForTemplateMappingResourceAttributeInSRFile
    • reservedKeywordForTemplateIdentifierAttributeInSRFile

      protected static String reservedKeywordForTemplateIdentifierAttributeInSRFile
    • reservedKeywordForSimplifiedLabelAttributeInSRFile

      protected static String reservedKeywordForSimplifiedLabelAttributeInSRFile
    • reservedKeywordForSimplifiedReferenceToLabelAttributeInSRFile

      protected static String reservedKeywordForSimplifiedReferenceToLabelAttributeInSRFile
    • reservedKeywordForReferencedSOPClassUIDAttributeInCompositeContentItem

      protected static String reservedKeywordForReferencedSOPClassUIDAttributeInCompositeContentItem
    • reservedKeywordForReferencedSOPInstanceUIDAttributeInCompositeContentItem

      protected static String reservedKeywordForReferencedSOPInstanceUIDAttributeInCompositeContentItem
    • reservedKeywordForReferencedFrameNumberAttributeInCompositeContentItem

      protected static String reservedKeywordForReferencedFrameNumberAttributeInCompositeContentItem
    • reservedKeywordForReferencedSegmentNumberAttributeInCompositeContentItem

      protected static String reservedKeywordForReferencedSegmentNumberAttributeInCompositeContentItem
    • reservedKeywordForPresentationStateSOPClassUIDAttributeInCompositeContentItem

      protected static String reservedKeywordForPresentationStateSOPClassUIDAttributeInCompositeContentItem
    • reservedKeywordForPresentationStateSOPInstanceUIDAttributeInCompositeContentItem

      protected static String reservedKeywordForPresentationStateSOPInstanceUIDAttributeInCompositeContentItem
    • reservedKeywordForRealWorldValueMappingSOPClassUIDAttributeInCompositeContentItem

      protected static String reservedKeywordForRealWorldValueMappingSOPClassUIDAttributeInCompositeContentItem
    • reservedKeywordForRealWorldValueMappingSOPInstanceUIDAttributeInCompositeContentItem

      protected static String reservedKeywordForRealWorldValueMappingSOPInstanceUIDAttributeInCompositeContentItem
    • reservedKeywordForGraphicTypeAttributeInCoordinatesContentItem

      protected static String reservedKeywordForGraphicTypeAttributeInCoordinatesContentItem
    • reservedKeywordFor2DCoordinatesAttributeInCoordinatesContentItem

      protected static String reservedKeywordFor2DCoordinatesAttributeInCoordinatesContentItem
    • reservedKeywordFor3DCoordinatesAttributeInCoordinatesContentItem

      protected static String reservedKeywordFor3DCoordinatesAttributeInCoordinatesContentItem
    • reservedKeywordForPixelOriginInterpretationAttributeInCoordinatesContentItem

      protected static String reservedKeywordForPixelOriginInterpretationAttributeInCoordinatesContentItem
    • reservedKeywordForFiducialUIDAttributeInCoordinatesContentItem

      protected static String reservedKeywordForFiducialUIDAttributeInCoordinatesContentItem
    • reservedKeywordForReferencedFrameOfReferenceUIDAttributeInCoordinatesContentItem

      protected static String reservedKeywordForReferencedFrameOfReferenceUIDAttributeInCoordinatesContentItem
    • reservedKeywordForMeasurementUnitsAttributeInNumericContentItem

      protected static String reservedKeywordForMeasurementUnitsAttributeInNumericContentItem
    • reservedKeywordForFloatingPointValueAttributeInNumericContentItem

      protected static String reservedKeywordForFloatingPointValueAttributeInNumericContentItem
    • reservedKeywordForRationalNumeratorAttributeInNumericContentItem

      protected static String reservedKeywordForRationalNumeratorAttributeInNumericContentItem
    • reservedKeywordForRationalDenominatorAttributeInNumericContentItem

      protected static String reservedKeywordForRationalDenominatorAttributeInNumericContentItem
    • reservedKeywordForNumericValueQualifierAttributeInNumericContentItem

      protected static String reservedKeywordForNumericValueQualifierAttributeInNumericContentItem
    • reservedKeywordForAlphabeticPropertyInPersonNameContentItem

      protected static String reservedKeywordForAlphabeticPropertyInPersonNameContentItem
    • reservedKeywordForIdeographicPropertyInPersonNameContentItem

      protected static String reservedKeywordForIdeographicPropertyInPersonNameContentItem
    • reservedKeywordForPhoneticPropertyInPersonNameContentItem

      protected static String reservedKeywordForPhoneticPropertyInPersonNameContentItem
    • simplifiedLabelPrefix

      protected static String simplifiedLabelPrefix
    • businessNames

      protected Map<String,CodedSequenceItem> businessNames
    • valueTypesByBusinessName

      protected Map<String,SortedSet<String>> valueTypesByBusinessName
    • relationshipTypesByBusinessName

      protected Map<String,SortedSet<String>> relationshipTypesByBusinessName
    • contentItemIdentifiersByContentItem

      protected Map<ContentItem,String> contentItemIdentifiersByContentItem
    • simplifiedLabelByReferencedContentItemIdentifiers

      protected Map<String,String> simplifiedLabelByReferencedContentItemIdentifiers
    • simplifiedLabelCounter

      protected int simplifiedLabelCounter
    • contentItemFactory

      protected ContentItemFactory contentItemFactory
    • referencedContentItemIdentifiersBySimplifiedLabel

      protected Map<String,String> referencedContentItemIdentifiersBySimplifiedLabel
  • Constructor Details

    • JSONRepresentationOfStructuredReportObjectFactory

      public JSONRepresentationOfStructuredReportObjectFactory()

      Construct a factory object, which can be used to get JSON documents from DICOM objects.

  • Method Details

    • isCommonAnnotationAttribute

      protected boolean isCommonAnnotationAttribute(String attributeName)
    • makeBusinessNameFromCodeMeaning

      public static String makeBusinessNameFromCodeMeaning(String codeMeaning, boolean upperCamelCase)
    • makeBusinessNameFromCodeMeaning

      public static String makeBusinessNameFromCodeMeaning(CodedSequenceItem conceptName)
    • getCodedSequenceItemForBusinessName

      public CodedSequenceItem getCodedSequenceItemForBusinessName(String businessName, String location, boolean roleIsAsConceptName)
    • getCodedSequenceItemForBusinessNameUsedAsConceptName

      public CodedSequenceItem getCodedSequenceItemForBusinessNameUsedAsConceptName(String businessName, String location)
    • getCodedSequenceItemForBusinessNameUsedAsValue

      public CodedSequenceItem getCodedSequenceItemForBusinessNameUsedAsValue(String businessName, String location)
    • getCodedSequenceItemForBusinessNameUsedAsUnits

      public CodedSequenceItem getCodedSequenceItemForBusinessNameUsedAsUnits(String businessName, String location)
    • getBusinessNamesDocument

      public javax.json.JsonArray getBusinessNamesDocument()
    • addCodedSequenceItemPropertyFromBusinessName

      protected void addCodedSequenceItemPropertyFromBusinessName(javax.json.JsonObject businessNamePayload, AttributeList csilist, AttributeTag tag, String reservedKeywordInBusinessNamesFile)
    • loadBusinessNamesDocument

      public void loadBusinessNamesDocument(javax.json.JsonArray document) throws DicomException

      Load the business names encoded in a JSON document.

      Parameters:
      document - the JSON document
      Throws:
      DicomException
    • loadBusinessNamesDocument

      public void loadBusinessNamesDocument(InputStream stream) throws IOException, DicomException

      Load the business names encoded in a JSON document.

      Parameters:
      stream - the input stream containing the JSON document
      Throws:
      IOException
      DicomException
    • loadBusinessNamesDocument

      public void loadBusinessNamesDocument(File file) throws IOException, DicomException

      Load the business names encoded in a JSON document.

      Parameters:
      file - the input file containing the JSON document
      Throws:
      IOException
      DicomException
    • loadBusinessNamesDocument

      public void loadBusinessNamesDocument(String name) throws IOException, DicomException

      Load the business names encoded in a JSON document.

      Parameters:
      name - the input file containing the JSON document
      Throws:
      IOException
      DicomException
    • walkTreeBuildingSimplifiedLabelsForReferencedContentItemIdentifiers

      protected void walkTreeBuildingSimplifiedLabelsForReferencedContentItemIdentifiers(ContentItem node, String location)

      Walk the tree starting at the specified node.

      Parameters:
      node -
      location - the dotted numeric string describing the location of the starting node
    • getDocument

      public javax.json.JsonArray getDocument(AttributeList list) throws DicomException

      Given a DICOM attribute list encoding a Structured Report, get a JSON document.

      Parameters:
      list - the attribute list
      Returns:
      the JSON encoded DICOM SR document
      Throws:
      DicomException
    • getDocument

      public javax.json.JsonArray getDocument(StructuredReport sr) throws DicomException

      Given a DICOM Structured Report, get a JSON document of the content tree only.

      Parameters:
      sr - the Structured Report
      Returns:
      the JSON encoded DICOM SR document
      Throws:
      DicomException
    • getDocument

      public javax.json.JsonArray getDocument(StructuredReport sr, AttributeList list) throws DicomException

      Given a DICOM Structured Report, get a JSON document of the content tree and the top level DICOM elements.

      Parameters:
      sr - the Structured Report may be null if list is not - will build an sr tree model
      list - the attribute list may be null if only the sr content tree is to be added
      Returns:
      the JSON encoded DICOM SR document
      Throws:
      DicomException
    • getDocument

      public javax.json.JsonArray getDocument(File file) throws IOException, DicomException

      Given a DICOM object encoded as a list of attributes, get a JSON document.

      Parameters:
      file - the DICOM file
      Returns:
      the JSON document
      Throws:
      IOException
      DicomException
    • getDocument

      public javax.json.JsonArray getDocument(String filename) throws IOException, DicomException

      Given a DICOM object encoded as a list of attributes, get a JSON document.

      Parameters:
      filename - the DICOM file name
      Returns:
      the JSON document
      Throws:
      IOException
      DicomException
    • getStringFromSelectedContentItemValue

      protected String getStringFromSelectedContentItemValue(javax.json.JsonArray contentItemValues, int which, String what, String valueType, CodedSequenceItem concept)
    • getSingleStringValueOrNullFromJsonStringOrNumberContentItemValue

      protected String getSingleStringValueOrNullFromJsonStringOrNumberContentItemValue(javax.json.JsonValue entry, String valueType, CodedSequenceItem concept)
    • getSingleStringValueOrNullFromJsonContentItemValue

      protected String getSingleStringValueOrNullFromJsonContentItemValue(javax.json.JsonValue entry, String valueType, CodedSequenceItem concept)
    • haveChildrenForSingleStringOrCodeJsonContentItemValue

      protected boolean haveChildrenForSingleStringOrCodeJsonContentItemValue(javax.json.JsonValue contentItemValue, javax.json.JsonObject contentItemAttributesObject)
    • determineUnknownValueType

      protected String determineUnknownValueType(String parentValueType, javax.json.JsonValue childObjectValue)
    • selectTheOtherOfTwoStringsInSet

      protected static String selectTheOtherOfTwoStringsInSet(String method, String location, Set<String> theSet, String doNotWant)
    • selectFromAlternativeValueTypesForBusinessName

      protected String selectFromAlternativeValueTypesForBusinessName(String childLocation, String childBusinessName, String parentValueType, Set<String> childValueTypes, javax.json.JsonValue childObjectValue)
    • selectFromAlternativeRelationshipTypesForBusinessName

      protected String selectFromAlternativeRelationshipTypesForBusinessName(String childLocation, String childBusinessName, String parentValueType, String childValueType, Set<String> childRelationshipTypes)
    • determineUnknownRelationshipType

      protected String determineUnknownRelationshipType(String parentValueType, String childValueType, javax.json.JsonValue childObjectValue)
    • getContentItemAttributesObject

      protected javax.json.JsonObject getContentItemAttributesObject(javax.json.JsonArray contentItemAttributesAndChildrenArray)
    • getContentItemAndChildrenFromJSONObjectValue

      protected ContentItem getContentItemAndChildrenFromJSONObjectValue(String businessName, CodedSequenceItem concept, String valueType, String relationshipType, javax.json.JsonValue contentItemValue, String location) throws DicomException
      Throws:
      DicomException
    • getStructuredReport

      public StructuredReport getStructuredReport(javax.json.JsonObject topLevelObject) throws DicomException

      Given a DICOM SR object encoded in a JSON document convert it to a StructuredReport using the content tree and ignoring any header attributes.

      Parameters:
      topLevelObject - the first object of the array that is the JSON document
      Returns:
      the StructuredReport
      Throws:
      DicomException
    • getStructuredReport

      public StructuredReport getStructuredReport(javax.json.JsonArray document) throws DicomException

      Given a DICOM SR object encoded as a JSON document convert it to a StructuredReport using the content tree and ignoring any header attributes.

      Parameters:
      document - the JSON document
      Returns:
      the StructuredReport
      Throws:
      DicomException
    • getAttributeList

      public AttributeList getAttributeList(javax.json.JsonObject topLevelObject) throws DicomException

      Given a DICOM SR object encoded in a JSON document convert it to a list of attributes.

      Parameters:
      topLevelObject - the first object of the array that is the JSON document
      Returns:
      the list of DICOM attributes
      Throws:
      DicomException
    • getAttributeList

      public AttributeList getAttributeList(javax.json.JsonArray document) throws DicomException

      Given a DICOM SR object encoded as a JSON document convert it to a list of attributes.

      Parameters:
      document - the JSON document
      Returns:
      the list of DICOM attributes
      Throws:
      DicomException
    • getAttributeList

      public AttributeList getAttributeList(InputStream stream) throws IOException, DicomException

      Given a DICOM SR object encoded as a JSON document in a stream convert it to a list of attributes.

      Parameters:
      stream - the input stream containing the JSON document
      Returns:
      the list of DICOM attributes
      Throws:
      IOException
      DicomException
    • getAttributeList

      public AttributeList getAttributeList(File file) throws IOException, DicomException

      Given a DICOM SR object encoded as a JSON document in a file convert it to a list of attributes.

      Parameters:
      file - the input file containing the JSON document
      Returns:
      the list of DICOM attributes
      Throws:
      IOException
      DicomException
    • getAttributeList

      public AttributeList getAttributeList(String name) throws IOException, DicomException

      Given a DICOM SR object encoded as a JSON document in a named file convert it to a list of attributes.

      Parameters:
      name - the input file containing the JSON document
      Returns:
      the list of DICOM attributes
      Throws:
      IOException
      DicomException
    • write

      public static void write(OutputStream out, javax.json.JsonArray document) throws IOException

      Serialize a JSON document.

      Parameters:
      out - the output stream to write to
      document - the JSON document
      Throws:
      IOException
    • write

      public static void write(File outputFile, javax.json.JsonArray document) throws IOException

      Serialize a JSON document.

      Parameters:
      outputFile - the output file to write to
      document - the JSON document
      Throws:
      IOException
    • write

      public static void write(String outputPath, javax.json.JsonArray document) throws IOException

      Serialize a JSON document.

      Parameters:
      outputPath - the output path to write to
      document - the JSON document
      Throws:
      IOException
    • createDocumentAndWriteIt

      public static void createDocumentAndWriteIt(AttributeList list, OutputStream out) throws IOException, DicomException

      Serialize a JSON document created from a DICOM Structured Report.

      Parameters:
      list - the attribute list
      out - the output stream to write to
      Throws:
      IOException
      DicomException
    • createDocumentAndWriteIt

      public static void createDocumentAndWriteIt(StructuredReport sr, OutputStream out) throws IOException, DicomException

      Serialize a JSON document created from a DICOM Structured Report.

      Parameters:
      sr - the Structured Report
      out - the output stream to write to
      Throws:
      IOException
      DicomException
    • createDocumentAndWriteIt

      public static void createDocumentAndWriteIt(StructuredReport sr, AttributeList list, OutputStream out) throws DicomException

      Serialize a JSON document created from a DICOM attribute list.

      Parameters:
      sr - the Structured Report - may be null if list is not - will build an sr tree model
      list - the list of DICOM attributes
      out - the output stream to write to
      Throws:
      DicomException
    • createDocumentAndWriteIt

      public static void createDocumentAndWriteIt(StructuredReport sr, AttributeList list, File outputFile) throws IOException, DicomException

      Serialize a JSON document created from a DICOM attribute list.

      Parameters:
      sr - the Structured Report - may be null if list is not - will build an sr tree model
      list - the list of DICOM attributes
      outputFile - the output file to write to
      Throws:
      IOException
      DicomException
    • createDocumentAndWriteIt

      public static void createDocumentAndWriteIt(StructuredReport sr, AttributeList list, String outputPath) throws IOException, DicomException

      Serialize a JSON document created from a DICOM attribute list.

      Parameters:
      sr - the Structured Report - may be null if list is not - will build an sr tree model
      list - the list of DICOM attributes
      outputPath - the output path to write to
      Throws:
      IOException
      DicomException
    • main

      public static void main(String[] arg)

      Read a DICOM dataset (that contains a structured report) and write a JSON representation of it to the standard output or specified path, or vice versa.

      Parameters:
      arg - either one input path of the file containing the DICOM/JSON dataset and a business name file path to read or write, or a direction argument (toDICOM or toJSON, case insensitive) and an input path and an input or output business name path, and optionally an output path