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); }
Constructor and Description |
---|
JSONRepresentationOfStructuredReportObjectFactory()
Construct a factory object, which can be used to get JSON documents from DICOM objects.
|
Modifier and Type | Method and Description |
---|---|
protected void |
addCodedSequenceItemPropertyFromBusinessName(javax.json.JsonObject businessNamePayload,
AttributeList csilist,
AttributeTag tag,
String reservedKeywordInBusinessNamesFile) |
static void |
createDocumentAndWriteIt(AttributeList list,
OutputStream out)
Serialize a JSON document created from a DICOM Structured Report.
|
static void |
createDocumentAndWriteIt(StructuredReport sr,
AttributeList list,
File outputFile)
Serialize a JSON document created from a DICOM attribute list.
|
static void |
createDocumentAndWriteIt(StructuredReport sr,
AttributeList list,
OutputStream out)
Serialize a JSON document created from a DICOM attribute list.
|
static void |
createDocumentAndWriteIt(StructuredReport sr,
AttributeList list,
String outputPath)
Serialize a JSON document created from a DICOM attribute list.
|
static void |
createDocumentAndWriteIt(StructuredReport sr,
OutputStream out)
Serialize a JSON document created from a DICOM Structured Report.
|
protected String |
determineUnknownRelationshipType(String parentValueType,
String childValueType,
javax.json.JsonValue childObjectValue) |
protected String |
determineUnknownValueType(String parentValueType,
javax.json.JsonValue childObjectValue) |
AttributeList |
getAttributeList(File file)
Given a DICOM SR object encoded as a JSON document in a file
convert it to a list of attributes.
|
AttributeList |
getAttributeList(InputStream stream)
Given a DICOM SR object encoded as a JSON document in a stream
convert it to a list of attributes.
|
AttributeList |
getAttributeList(javax.json.JsonArray document)
Given a DICOM SR object encoded as a JSON document
convert it to a list of attributes.
|
AttributeList |
getAttributeList(javax.json.JsonObject topLevelObject)
Given a DICOM SR object encoded in a JSON document
convert it to a list of attributes.
|
AttributeList |
getAttributeList(String name)
Given a DICOM SR object encoded as a JSON document in a named file
convert it to a list of attributes.
|
javax.json.JsonArray |
getBusinessNamesDocument() |
CodedSequenceItem |
getCodedSequenceItemForBusinessName(String businessName,
String location,
boolean roleIsAsConceptName) |
CodedSequenceItem |
getCodedSequenceItemForBusinessNameUsedAsConceptName(String businessName,
String location) |
CodedSequenceItem |
getCodedSequenceItemForBusinessNameUsedAsUnits(String businessName,
String location) |
CodedSequenceItem |
getCodedSequenceItemForBusinessNameUsedAsValue(String businessName,
String location) |
protected ContentItem |
getContentItemAndChildrenFromJSONObjectValue(String businessName,
CodedSequenceItem concept,
String valueType,
String relationshipType,
javax.json.JsonValue contentItemValue,
String location) |
protected javax.json.JsonObject |
getContentItemAttributesObject(javax.json.JsonArray contentItemAttributesAndChildrenArray) |
javax.json.JsonArray |
getDocument(AttributeList list)
Given a DICOM attribute list encoding a Structured Report, get a JSON document.
|
javax.json.JsonArray |
getDocument(File file)
Given a DICOM object encoded as a list of attributes, get a JSON document.
|
javax.json.JsonArray |
getDocument(String filename)
Given a DICOM object encoded as a list of attributes, get a JSON document.
|
javax.json.JsonArray |
getDocument(StructuredReport sr)
Given a DICOM Structured Report, get a JSON document of the content tree only.
|
javax.json.JsonArray |
getDocument(StructuredReport sr,
AttributeList list)
Given a DICOM Structured Report, get a JSON document of the content tree and the top level DICOM elements.
|
protected String |
getSingleStringValueOrNullFromJsonContentItemValue(javax.json.JsonValue entry,
String valueType,
CodedSequenceItem concept) |
protected String |
getSingleStringValueOrNullFromJsonStringOrNumberContentItemValue(javax.json.JsonValue entry,
String valueType,
CodedSequenceItem concept) |
protected String |
getStringFromSelectedContentItemValue(javax.json.JsonArray contentItemValues,
int which,
String what,
String valueType,
CodedSequenceItem concept) |
StructuredReport |
getStructuredReport(javax.json.JsonArray document)
Given a DICOM SR object encoded as a JSON document
convert it to a StructuredReport using the content tree and ignoring any header attributes.
|
StructuredReport |
getStructuredReport(javax.json.JsonObject topLevelObject)
Given a DICOM SR object encoded in a JSON document
convert it to a StructuredReport using the content tree and ignoring any header attributes.
|
protected boolean |
haveChildrenForSingleStringOrCodeJsonContentItemValue(javax.json.JsonValue contentItemValue,
javax.json.JsonObject contentItemAttributesObject) |
protected boolean |
isCommonAnnotationAttribute(String attributeName) |
void |
loadBusinessNamesDocument(File file)
Load the business names encoded in a JSON document.
|
void |
loadBusinessNamesDocument(InputStream stream)
Load the business names encoded in a JSON document.
|
void |
loadBusinessNamesDocument(javax.json.JsonArray document)
Load the business names encoded in a JSON document.
|
void |
loadBusinessNamesDocument(String name)
Load the business names encoded in a JSON document.
|
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.
|
static String |
makeBusinessNameFromCodeMeaning(CodedSequenceItem conceptName) |
static String |
makeBusinessNameFromCodeMeaning(String codeMeaning,
boolean upperCamelCase) |
protected String |
selectFromAlternativeRelationshipTypesForBusinessName(String childLocation,
String childBusinessName,
String parentValueType,
String childValueType,
Set<String> childRelationshipTypes) |
protected String |
selectFromAlternativeValueTypesForBusinessName(String childLocation,
String childBusinessName,
String parentValueType,
Set<String> childValueTypes,
javax.json.JsonValue childObjectValue) |
protected static String |
selectTheOtherOfTwoStringsInSet(String method,
String location,
Set<String> theSet,
String doNotWant) |
protected void |
walkTreeBuildingSimplifiedLabelsForReferencedContentItemIdentifiers(ContentItem node,
String location)
Walk the tree starting at the specified node.
|
static void |
write(File outputFile,
javax.json.JsonArray document)
Serialize a JSON document.
|
static void |
write(OutputStream out,
javax.json.JsonArray document)
Serialize a JSON document.
|
static void |
write(String outputPath,
javax.json.JsonArray document)
Serialize a JSON document.
|
protected Map<String,CodedSequenceItem> businessNames
protected static String businessNameToUseForAnonymousContentItems
protected static boolean collapseAttributeValueArrays
protected static boolean collapseContentTreeArrays
protected static boolean collapseEmptyToNull
protected ContentItemFactory contentItemFactory
protected Map<ContentItem,String> contentItemIdentifiersByContentItem
protected static boolean elideSeparateContinuityOfContent
protected Map<String,String> referencedContentItemIdentifiersBySimplifiedLabel
protected Map<String,SortedSet<String>> relationshipTypesByBusinessName
protected static String reservedKeywordFor2DCoordinatesAttributeInCoordinatesContentItem
protected static String reservedKeywordFor3DCoordinatesAttributeInCoordinatesContentItem
protected static String reservedKeywordForAlphabeticPropertyInPersonNameContentItem
protected static String reservedKeywordForCodeMeaningInBusinessNamesFile
protected static String reservedKeywordForCodeValueInBusinessNamesFile
protected static String reservedKeywordForCodingSchemeDesignatorInBusinessNamesFile
protected static String reservedKeywordForCodingSchemeVersionInBusinessNamesFile
protected static String reservedKeywordForContextGroupExtensionCreatorUIDInBusinessNamesFile
protected static String reservedKeywordForContextGroupExtensionFlagInBusinessNamesFile
protected static String reservedKeywordForContextGroupLocalVersionInBusinessNamesFile
protected static String reservedKeywordForContextGroupVersionInBusinessNamesFile
protected static String reservedKeywordForContextIdentifierInBusinessNamesFile
protected static String reservedKeywordForContextUIDInBusinessNamesFile
protected static String reservedKeywordForContinuityOfContentAttributeInSRFile
protected static String reservedKeywordForFiducialUIDAttributeInCoordinatesContentItem
protected static String reservedKeywordForFloatingPointValueAttributeInNumericContentItem
protected static String reservedKeywordForGraphicTypeAttributeInCoordinatesContentItem
protected static String reservedKeywordForIdeographicPropertyInPersonNameContentItem
protected static String reservedKeywordForLongCodeValueInBusinessNamesFile
protected static String reservedKeywordForMappingResourceInBusinessNamesFile
protected static String reservedKeywordForMappingResourceNameInBusinessNamesFile
protected static String reservedKeywordForMappingResourceUIDInBusinessNamesFile
protected static String reservedKeywordForMeasurementUnitsAttributeInNumericContentItem
protected static String reservedKeywordForNumericValueQualifierAttributeInNumericContentItem
protected static String reservedKeywordForObservationDateTimeAttributeInSRFile
protected static String reservedKeywordForObservationUIDAttributeInSRFile
protected static String reservedKeywordForPhoneticPropertyInPersonNameContentItem
protected static String reservedKeywordForPixelOriginInterpretationAttributeInCoordinatesContentItem
protected static String reservedKeywordForPresentationStateSOPClassUIDAttributeInCompositeContentItem
protected static String reservedKeywordForPresentationStateSOPInstanceUIDAttributeInCompositeContentItem
protected static String reservedKeywordForRationalDenominatorAttributeInNumericContentItem
protected static String reservedKeywordForRationalNumeratorAttributeInNumericContentItem
protected static String reservedKeywordForRealWorldValueMappingSOPClassUIDAttributeInCompositeContentItem
protected static String reservedKeywordForRealWorldValueMappingSOPInstanceUIDAttributeInCompositeContentItem
protected static String reservedKeywordForReferencedFrameNumberAttributeInCompositeContentItem
protected static String reservedKeywordForReferencedFrameOfReferenceUIDAttributeInCoordinatesContentItem
protected static String reservedKeywordForReferencedSegmentNumberAttributeInCompositeContentItem
protected static String reservedKeywordForReferencedSOPClassUIDAttributeInCompositeContentItem
protected static String reservedKeywordForReferencedSOPInstanceUIDAttributeInCompositeContentItem
protected static String reservedKeywordForRelationshipTypeInBusinessNamesFile
protected static String reservedKeywordForSimplifiedLabelAttributeInSRFile
protected static String reservedKeywordForSimplifiedReferenceToLabelAttributeInSRFile
protected static String reservedKeywordForTemplateIdentifierAttributeInSRFile
protected static String reservedKeywordForTemplateMappingResourceAttributeInSRFile
protected static String reservedKeywordForURNCodeValueInBusinessNamesFile
protected static String reservedKeywordForValueTypeInBusinessNamesFile
protected Map<String,String> simplifiedLabelByReferencedContentItemIdentifiers
protected int simplifiedLabelCounter
protected static String simplifiedLabelPrefix
protected static boolean substituteUIDKeywords
protected static String symbolSignifyingReservedKeyword
protected static boolean useNumberForNumericContentItemValue
public JSONRepresentationOfStructuredReportObjectFactory()
Construct a factory object, which can be used to get JSON documents from DICOM objects.
protected void addCodedSequenceItemPropertyFromBusinessName(javax.json.JsonObject businessNamePayload, AttributeList csilist, AttributeTag tag, String reservedKeywordInBusinessNamesFile)
public static void createDocumentAndWriteIt(AttributeList list, OutputStream out) throws IOException, DicomException
Serialize a JSON document created from a DICOM Structured Report.
list
- the attribute listout
- the output stream to write toIOException
DicomException
public static void createDocumentAndWriteIt(StructuredReport sr, AttributeList list, File outputFile) throws IOException, DicomException
Serialize a JSON document created from a DICOM attribute list.
sr
- the Structured Report - may be null if list is not - will build an sr tree modellist
- the list of DICOM attributesoutputFile
- the output file to write toIOException
DicomException
public static void createDocumentAndWriteIt(StructuredReport sr, AttributeList list, OutputStream out) throws DicomException
Serialize a JSON document created from a DICOM attribute list.
sr
- the Structured Report - may be null if list is not - will build an sr tree modellist
- the list of DICOM attributesout
- the output stream to write toDicomException
public static void createDocumentAndWriteIt(StructuredReport sr, AttributeList list, String outputPath) throws IOException, DicomException
Serialize a JSON document created from a DICOM attribute list.
sr
- the Structured Report - may be null if list is not - will build an sr tree modellist
- the list of DICOM attributesoutputPath
- the output path to write toIOException
DicomException
public static void createDocumentAndWriteIt(StructuredReport sr, OutputStream out) throws IOException, DicomException
Serialize a JSON document created from a DICOM Structured Report.
sr
- the Structured Reportout
- the output stream to write toIOException
DicomException
protected String determineUnknownRelationshipType(String parentValueType, String childValueType, javax.json.JsonValue childObjectValue)
protected String determineUnknownValueType(String parentValueType, javax.json.JsonValue childObjectValue)
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.
file
- the input file containing the JSON documentIOException
DicomException
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.
stream
- the input stream containing the JSON documentIOException
DicomException
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.
document
- the JSON documentDicomException
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.
topLevelObject
- the first object of the array that is the JSON documentDicomException
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.
name
- the input file containing the JSON documentIOException
DicomException
public javax.json.JsonArray getBusinessNamesDocument()
public CodedSequenceItem getCodedSequenceItemForBusinessName(String businessName, String location, boolean roleIsAsConceptName)
public CodedSequenceItem getCodedSequenceItemForBusinessNameUsedAsConceptName(String businessName, String location)
public CodedSequenceItem getCodedSequenceItemForBusinessNameUsedAsUnits(String businessName, String location)
public CodedSequenceItem getCodedSequenceItemForBusinessNameUsedAsValue(String businessName, String location)
protected ContentItem getContentItemAndChildrenFromJSONObjectValue(String businessName, CodedSequenceItem concept, String valueType, String relationshipType, javax.json.JsonValue contentItemValue, String location) throws DicomException
DicomException
protected javax.json.JsonObject getContentItemAttributesObject(javax.json.JsonArray contentItemAttributesAndChildrenArray)
public javax.json.JsonArray getDocument(AttributeList list) throws DicomException
Given a DICOM attribute list encoding a Structured Report, get a JSON document.
list
- the attribute listDicomException
public javax.json.JsonArray getDocument(File file) throws IOException, DicomException
Given a DICOM object encoded as a list of attributes, get a JSON document.
file
- the DICOM fileIOException
DicomException
public javax.json.JsonArray getDocument(String filename) throws IOException, DicomException
Given a DICOM object encoded as a list of attributes, get a JSON document.
filename
- the DICOM file nameIOException
DicomException
public javax.json.JsonArray getDocument(StructuredReport sr) throws DicomException
Given a DICOM Structured Report, get a JSON document of the content tree only.
sr
- the Structured ReportDicomException
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.
sr
- the Structured Report may be null if list is not - will build an sr tree modellist
- the attribute list may be null if only the sr content tree is to be addedDicomException
protected String getSingleStringValueOrNullFromJsonContentItemValue(javax.json.JsonValue entry, String valueType, CodedSequenceItem concept)
protected String getSingleStringValueOrNullFromJsonStringOrNumberContentItemValue(javax.json.JsonValue entry, String valueType, CodedSequenceItem concept)
protected String getStringFromSelectedContentItemValue(javax.json.JsonArray contentItemValues, int which, String what, String valueType, CodedSequenceItem concept)
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.
document
- the JSON documentDicomException
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.
topLevelObject
- the first object of the array that is the JSON documentDicomException
protected boolean haveChildrenForSingleStringOrCodeJsonContentItemValue(javax.json.JsonValue contentItemValue, javax.json.JsonObject contentItemAttributesObject)
protected boolean isCommonAnnotationAttribute(String attributeName)
public void loadBusinessNamesDocument(File file) throws IOException, DicomException
Load the business names encoded in a JSON document.
file
- the input file containing the JSON documentIOException
DicomException
public void loadBusinessNamesDocument(InputStream stream) throws IOException, DicomException
Load the business names encoded in a JSON document.
stream
- the input stream containing the JSON documentIOException
DicomException
public void loadBusinessNamesDocument(javax.json.JsonArray document) throws DicomException
Load the business names encoded in a JSON document.
document
- the JSON documentDicomException
public void loadBusinessNamesDocument(String name) throws IOException, DicomException
Load the business names encoded in a JSON document.
name
- the input file containing the JSON documentIOException
DicomException
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.
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 pathpublic static String makeBusinessNameFromCodeMeaning(CodedSequenceItem conceptName)
public static String makeBusinessNameFromCodeMeaning(String codeMeaning, boolean upperCamelCase)
protected String selectFromAlternativeRelationshipTypesForBusinessName(String childLocation, String childBusinessName, String parentValueType, String childValueType, Set<String> childRelationshipTypes)
protected String selectFromAlternativeValueTypesForBusinessName(String childLocation, String childBusinessName, String parentValueType, Set<String> childValueTypes, javax.json.JsonValue childObjectValue)
protected static String selectTheOtherOfTwoStringsInSet(String method, String location, Set<String> theSet, String doNotWant)
protected void walkTreeBuildingSimplifiedLabelsForReferencedContentItemIdentifiers(ContentItem node, String location)
Walk the tree starting at the specified node.
node
- location
- the dotted numeric string describing the location of the starting nodepublic static void write(File outputFile, javax.json.JsonArray document) throws IOException
Serialize a JSON document.
outputFile
- the output file to write todocument
- the JSON documentIOException
public static void write(OutputStream out, javax.json.JsonArray document) throws IOException
Serialize a JSON document.
out
- the output stream to write todocument
- the JSON documentIOException
public static void write(String outputPath, javax.json.JsonArray document) throws IOException
Serialize a JSON document.
outputPath
- the output path to write todocument
- the JSON documentIOException