Search in sources :

Example 1 with ActionItem

use of org.karnak.backend.model.action.ActionItem in project karnak by OsiriX-Foundation.

the class Profile method applyAction.

public void applyAction(Attributes dcm, Attributes dcmCopy, HMAC hmac, ProfileItem profilePassedInSequence, ActionItem actionPassedInSequence, AttributeEditorContext context) {
    for (int tag : dcm.tags()) {
        VR vr = dcm.getVR(tag);
        final ExprCondition exprCondition = new ExprCondition(dcmCopy);
        ActionItem currentAction = null;
        ProfileItem currentProfile = null;
        for (ProfileItem profileEntity : profiles.stream().filter(p -> !(p instanceof CleanPixelData)).collect(Collectors.toList())) {
            currentProfile = profileEntity;
            if (profileEntity.getCondition() == null || profileEntity.getCodeName().equals(ProfileItemType.DEFACING.getClassAlias()) || profileEntity.getCodeName().equals(ProfileItemType.CLEAN_PIXEL_DATA.getClassAlias())) {
                currentAction = profileEntity.getAction(dcm, dcmCopy, tag, hmac);
            } else {
                boolean conditionIsOk = (Boolean) ExpressionResult.get(profileEntity.getCondition(), exprCondition, Boolean.class);
                if (conditionIsOk) {
                    currentAction = profileEntity.getAction(dcm, dcmCopy, tag, hmac);
                }
            }
            if (currentAction != null) {
                break;
            }
            if (profileEntity.equals(profilePassedInSequence)) {
                currentAction = actionPassedInSequence;
                break;
            }
        }
        if (!(currentAction instanceof Remove) && !(currentAction instanceof ReplaceNull) && vr == VR.SQ) {
            final ProfileItem finalCurrentProfile = currentProfile;
            final ActionItem finalCurrentAction = currentAction;
            Sequence seq = dcm.getSequence(tag);
            if (seq != null) {
                for (Attributes d : seq) {
                    applyAction(d, dcmCopy, hmac, finalCurrentProfile, finalCurrentAction, context);
                }
            }
        } else {
            if (currentAction != null) {
                try {
                    currentAction.execute(dcm, tag, hmac);
                } catch (final Exception e) {
                    LOGGER.error("Cannot execute the currentAction {} for tag: {}", currentAction, TagUtils.toString(tag), e);
                }
            }
        }
    }
}
Also used : ProfileItem(org.karnak.backend.model.profiles.ProfileItem) Color(java.awt.Color) ProfileEntity(org.karnak.backend.data.entity.ProfileEntity) AttributeEditorContext(org.weasis.dicom.param.AttributeEditorContext) VR(org.dcm4che3.data.VR) Attributes(org.dcm4che3.data.Attributes) ReplaceNull(org.karnak.backend.model.action.ReplaceNull) LoggerFactory(org.slf4j.LoggerFactory) MarkerFactory(org.slf4j.MarkerFactory) HashMap(java.util.HashMap) StringUtil(org.weasis.core.util.StringUtil) Remove(org.karnak.backend.model.action.Remove) ArrayList(java.util.ArrayList) SecretEntity(org.karnak.backend.data.entity.SecretEntity) Map(java.util.Map) ProfileItem(org.karnak.backend.model.profiles.ProfileItem) ProjectEntity(org.karnak.backend.data.entity.ProjectEntity) BigInteger(java.math.BigInteger) BulkData(org.dcm4che3.data.BulkData) ProfileElementEntity(org.karnak.backend.data.entity.ProfileElementEntity) ActionItem(org.karnak.backend.model.action.ActionItem) ExpressionResult(org.karnak.backend.model.expression.ExpressionResult) ExprCondition(org.karnak.backend.model.expression.ExprCondition) Shape(java.awt.Shape) DefacingUtil.isAxial(org.karnak.backend.dicom.DefacingUtil.isAxial) HMAC(org.karnak.backend.model.profilepipe.HMAC) Logger(org.slf4j.Logger) ActionTags(org.karnak.backend.model.profiles.ActionTags) Set(java.util.Set) HashContext(org.karnak.backend.model.profilepipe.HashContext) CleanPixelData(org.karnak.backend.model.profiles.CleanPixelData) Collectors(java.util.stream.Collectors) TagUtils(org.dcm4che3.util.TagUtils) List(java.util.List) ProfileItemType(org.karnak.backend.enums.ProfileItemType) Tag(org.dcm4che3.data.Tag) Marker(org.slf4j.Marker) MDC(org.slf4j.MDC) Sequence(org.dcm4che3.data.Sequence) Defacer(org.karnak.backend.dicom.Defacer) Fragments(org.dcm4che3.data.Fragments) DestinationEntity(org.karnak.backend.data.entity.DestinationEntity) DefacingUtil.isCT(org.karnak.backend.dicom.DefacingUtil.isCT) Comparator(java.util.Comparator) Collections(java.util.Collections) Defacing(org.karnak.backend.model.profiles.Defacing) MaskArea(org.dcm4che3.img.op.MaskArea) ActionItem(org.karnak.backend.model.action.ActionItem) Attributes(org.dcm4che3.data.Attributes) Remove(org.karnak.backend.model.action.Remove) Sequence(org.dcm4che3.data.Sequence) ReplaceNull(org.karnak.backend.model.action.ReplaceNull) ExprCondition(org.karnak.backend.model.expression.ExprCondition) CleanPixelData(org.karnak.backend.model.profiles.CleanPixelData) VR(org.dcm4che3.data.VR)

Example 2 with ActionItem

use of org.karnak.backend.model.action.ActionItem in project karnak by OsiriX-Foundation.

the class ExprAction method Replace.

public ActionItem Replace(String dummyValue) {
    ActionItem replace = new Replace("D");
    replace.setDummyValue(dummyValue);
    return replace;
}
Also used : Replace(org.karnak.backend.model.action.Replace) ActionItem(org.karnak.backend.model.action.ActionItem)

Example 3 with ActionItem

use of org.karnak.backend.model.action.ActionItem in project karnak by OsiriX-Foundation.

the class TagActionMap method get.

public ActionItem get(Integer tag) {
    ActionItem action = tagAction.get(tag);
    if (action == null) {
        for (Map.Entry<String, ActionItem> entry : tagPatternAction.entrySet()) {
            String currentTagPattern = entry.getKey();
            int patternTag = TagUtils.intFromHexString(currentTagPattern.replace("X", "0"));
            int patternMask = TagUtils.intFromHexString(getMask(currentTagPattern));
            if ((tag & patternMask) == patternTag) {
                return entry.getValue();
            }
        }
    }
    return action;
}
Also used : ActionItem(org.karnak.backend.model.action.ActionItem) Map(java.util.Map) HashMap(java.util.HashMap)

Example 4 with ActionItem

use of org.karnak.backend.model.action.ActionItem in project karnak by OsiriX-Foundation.

the class Expression method getAction.

@Override
public ActionItem getAction(Attributes dcm, Attributes dcmCopy, int tag, HMAC hmac) {
    if (exceptedTagsAction.get(tag) == null && tagsAction.get(tag) != null) {
        final String expr = argumentEntities.get(0).getValue();
        final ExprAction exprAction = new ExprAction(tag, dcm.getVR(tag), dcm, dcmCopy);
        return (ActionItem) ExpressionResult.get(expr, exprAction, ActionItem.class);
    }
    return null;
}
Also used : ExprAction(org.karnak.backend.model.expression.ExprAction) ActionItem(org.karnak.backend.model.action.ActionItem)

Aggregations

ActionItem (org.karnak.backend.model.action.ActionItem)4 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Color (java.awt.Color)1 Shape (java.awt.Shape)1 BigInteger (java.math.BigInteger)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 List (java.util.List)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 Attributes (org.dcm4che3.data.Attributes)1 BulkData (org.dcm4che3.data.BulkData)1 Fragments (org.dcm4che3.data.Fragments)1 Sequence (org.dcm4che3.data.Sequence)1 Tag (org.dcm4che3.data.Tag)1 VR (org.dcm4che3.data.VR)1 MaskArea (org.dcm4che3.img.op.MaskArea)1 TagUtils (org.dcm4che3.util.TagUtils)1