Skip to content

Commit

Permalink
Generalize Attribute Coercion and enable to apply multiple matching A…
Browse files Browse the repository at this point in the history
…ttribute Coercions in configurable order #2967
  • Loading branch information
gunterze committed Nov 11, 2021
1 parent 2b28c7d commit 8c8f497
Showing 1 changed file with 12 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,11 @@ public ArchiveAttributeCoercion getArchiveAttributeCoercion(RetrieveContext ctx,
@Override
public AttributesCoercion getAttributesCoercion(RetrieveContext ctx, InstanceLocations inst,
ArchiveAttributeCoercion rule) {
return uidRemap(inst, coercion(ctx, inst, rule));
AttributesCoercion coercion = rule != null
? coercion(ctx, inst, rule)
: new MergeAttributesCoercion(inst.getAttributes(), AttributesCoercion.NONE);
UIDMap uidMap = inst.getLocations().get(0).getUidMap();
return uidMap != null ? new RemapUIDsAttributesCoercion(uidMap.getUIDMap(), coercion) : coercion;
}

@Override
Expand Down Expand Up @@ -749,6 +753,12 @@ public String remapUID(String uid) {
}

private void coerceSeriesMetadata(RetrieveContext ctx, InstanceLocations inst, Attributes attrs) {
UIDMap uidMap = inst.getLocations().get(0).getUidMap();
if (uidMap != null) {
UIDUtils.remapUIDs(attrs, uidMap.getUIDMap());
}
Attributes.unifyCharacterSets(attrs, inst.getAttributes());
attrs.addAll(inst.getAttributes());
attrs.setString(Tag.RetrieveAETitle, VR.AE, inst.getRetrieveAETs());
attrs.setString(Tag.InstanceAvailability, VR.CS, inst.getAvailability().toString());

Expand Down Expand Up @@ -948,16 +958,7 @@ private int queryFallbackCMoveSCPLeadingCFindSCP(RetrieveContext ctx) {
return expected;
}

private AttributesCoercion uidRemap(InstanceLocations inst, AttributesCoercion next) {
UIDMap uidMap = inst.getLocations().get(0).getUidMap();
return uidMap != null ? new RemapUIDsAttributesCoercion(uidMap.getUIDMap(), next) : next;
}

private AttributesCoercion coercion(RetrieveContext ctx, InstanceLocations inst, ArchiveAttributeCoercion rule) {
Attributes instAttributes = inst.getAttributes();
if (rule == null)
return new MergeAttributesCoercion(instAttributes, AttributesCoercion.NONE);

AttributesCoercion coercion = DeIdentificationAttributesCoercion.valueOf(
rule.getDeIdentification(), AttributesCoercion.NONE);
String xsltStylesheetURI = rule.getXSLTStylesheetURI();
Expand All @@ -978,7 +979,7 @@ private AttributesCoercion coercion(RetrieveContext ctx, InstanceLocations inst,
rule.getAttributeUpdatePolicy(), cfindscu, leadingCFindSCPQueryCache, coercion);
}
if (!rule.isRetrieveAsReceived()) {
coercion = new MergeAttributesCoercion(instAttributes, coercion);
coercion = new MergeAttributesCoercion(inst.getAttributes(), coercion);
}
LOG.info("Coerce Attributes from rule: {}", rule);
return coercion;
Expand Down Expand Up @@ -1103,12 +1104,6 @@ public Attributes loadMetadata(RetrieveContext ctx, InstanceLocations inst)
attrs = loadMetadataFromDicomFile(ctx, inst);

if (ctx.isUpdateSeriesMetadata()) {
UIDMap uidMap = inst.getLocations().get(0).getUidMap();
if (uidMap != null) {
UIDUtils.remapUIDs(attrs, uidMap.getUIDMap());
}
Attributes.unifyCharacterSets(attrs, inst.getAttributes());
attrs.addAll(inst.getAttributes());
coerceSeriesMetadata(ctx, inst, attrs);
} else {
getAttributesCoercion(ctx, inst).coerce(attrs, null);
Expand Down

0 comments on commit 8c8f497

Please sign in to comment.