Search in sources :

Example 1 with ExprCondition

use of org.karnak.backend.model.expression.ExprCondition 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 ExprCondition

use of org.karnak.backend.model.expression.ExprCondition in project karnak by OsiriX-Foundation.

the class TextFieldsBindSwitchingAlbum method buildBinder.

private Binder<KheopsAlbumsEntity> buildBinder() {
    Binder<KheopsAlbumsEntity> b = new BeanValidationBinder<>(KheopsAlbumsEntity.class);
    b.forField(textAuthorizationDestination).withValidator(StringUtils::isNotBlank, "Token destination is mandatory").withValidator(value -> {
        if (!textUrlAPI.getValue().isBlank()) {
            return validateToken(value, textUrlAPI.getValue(), SwitchingAlbum.MIN_SCOPE_DESTINATION);
        }
        return true;
    }, "Token can't be validate, minimum permissions: [write]").bind(KheopsAlbumsEntity::getAuthorizationDestination, KheopsAlbumsEntity::setAuthorizationDestination);
    b.forField(textAuthorizationSource).withValidator(StringUtils::isNotBlank, "Token source is mandatory").withValidator(value -> {
        if (!textUrlAPI.getValue().isBlank()) {
            return validateToken(value, textUrlAPI.getValue(), SwitchingAlbum.MIN_SCOPE_SOURCE);
        }
        return true;
    }, "Token can't be validate, minimum permissions: [read, send]").bind(KheopsAlbumsEntity::getAuthorizationSource, KheopsAlbumsEntity::setAuthorizationSource);
    b.forField(textUrlAPI).withValidator(StringUtils::isNotBlank, "Url API is mandatory").bind(KheopsAlbumsEntity::getUrlAPI, KheopsAlbumsEntity::setUrlAPI);
    b.forField(textCondition).withValidator(value -> {
        if (!textCondition.getValue().equals("")) {
            expressionError = ExpressionResult.isValid(textCondition.getValue(), new ExprCondition(), Boolean.class);
            textErrorConditionMsg.setText(expressionError.getMsg());
            return expressionError.isValid();
        }
        textErrorConditionMsg.setText("");
        return true;
    }, "Condition is not valid").bind(KheopsAlbumsEntity::getCondition, KheopsAlbumsEntity::setCondition);
    return b;
}
Also used : KheopsAlbumsEntity(org.karnak.backend.data.entity.KheopsAlbumsEntity) Binder(com.vaadin.flow.data.binder.Binder) StringUtils(org.apache.commons.lang3.StringUtils) List(java.util.List) JSONObject(org.json.JSONObject) ExpressionError(org.karnak.backend.model.expression.ExpressionError) BeanValidationBinder(com.vaadin.flow.data.binder.BeanValidationBinder) KheopsApi(org.karnak.backend.api.KheopsApi) TextField(com.vaadin.flow.component.textfield.TextField) ExpressionResult(org.karnak.backend.model.expression.ExpressionResult) Span(com.vaadin.flow.component.html.Span) SwitchingAlbum(org.karnak.backend.service.kheops.SwitchingAlbum) ExprCondition(org.karnak.backend.model.expression.ExprCondition) ExprCondition(org.karnak.backend.model.expression.ExprCondition) StringUtils(org.apache.commons.lang3.StringUtils) BeanValidationBinder(com.vaadin.flow.data.binder.BeanValidationBinder) KheopsAlbumsEntity(org.karnak.backend.data.entity.KheopsAlbumsEntity)

Example 3 with ExprCondition

use of org.karnak.backend.model.expression.ExprCondition in project karnak by OsiriX-Foundation.

the class DestinationCondition method setBinder.

private void setBinder(Binder<DestinationEntity> binder) {
    binder.forField(condition).withValidator(value -> {
        if (!condition.getValue().equals("")) {
            ExpressionError expressionError = ExpressionResult.isValid(condition.getValue(), new ExprCondition(), Boolean.class);
            textErrorConditionMsg.setText(expressionError.getMsg());
            return expressionError.isValid();
        }
        return true;
    }, "Condition not valid").withValidationStatusHandler(status -> {
        if (!status.isError()) {
            textErrorConditionMsg.setText("");
        }
    }).bind(DestinationEntity::getCondition, DestinationEntity::setCondition);
}
Also used : Binder(com.vaadin.flow.data.binder.Binder) ExpressionError(org.karnak.backend.model.expression.ExpressionError) HorizontalLayout(com.vaadin.flow.component.orderedlayout.HorizontalLayout) Div(com.vaadin.flow.component.html.Div) DestinationEntity(org.karnak.backend.data.entity.DestinationEntity) UIS(org.karnak.frontend.util.UIS) TextField(com.vaadin.flow.component.textfield.TextField) ExpressionResult(org.karnak.backend.model.expression.ExpressionResult) Span(com.vaadin.flow.component.html.Span) ExprCondition(org.karnak.backend.model.expression.ExprCondition) DestinationEntity(org.karnak.backend.data.entity.DestinationEntity) ExprCondition(org.karnak.backend.model.expression.ExprCondition) ExpressionError(org.karnak.backend.model.expression.ExpressionError)

Example 4 with ExprCondition

use of org.karnak.backend.model.expression.ExprCondition in project karnak by OsiriX-Foundation.

the class Profile method applyDefacing.

public void applyDefacing(Attributes dcmCopy, AttributeEditorContext context) {
    ProfileItem profileItemDefacing = profiles.stream().filter(p -> p instanceof Defacing).findFirst().orElse(null);
    if (profileItemDefacing != null) {
        if (isCT(dcmCopy) && isAxial(dcmCopy)) {
            if (profileItemDefacing.getCondition() == null) {
                context.getProperties().setProperty(Defacer.APPLY_DEFACING, "true");
            } else {
                ExprCondition exprCondition = new ExprCondition(dcmCopy);
                boolean conditionIsOk = (Boolean) ExpressionResult.get(profileItemDefacing.getCondition(), exprCondition, Boolean.class);
                if (conditionIsOk) {
                    context.getProperties().setProperty(Defacer.APPLY_DEFACING, "true");
                }
            }
        }
    }
}
Also used : ProfileItem(org.karnak.backend.model.profiles.ProfileItem) Defacing(org.karnak.backend.model.profiles.Defacing) ExprCondition(org.karnak.backend.model.expression.ExprCondition)

Example 5 with ExprCondition

use of org.karnak.backend.model.expression.ExprCondition in project karnak by OsiriX-Foundation.

the class Profile method evaluateConditionCleanPixelData.

/**
 * Evaluate the condition on the profile Clean Pixel Data
 *
 * @param dcmCopy Context copy
 * @return true if the condition match, false if there are some exclusions
 */
boolean evaluateConditionCleanPixelData(Attributes dcmCopy) {
    boolean conditionCleanPixelData = true;
    // Retrieve the profile item
    ProfileItem profileItemCleanPixelData = profiles.stream().filter(CleanPixelData.class::isInstance).findFirst().orElse(null);
    if (profileItemCleanPixelData != null && profileItemCleanPixelData.getCondition() != null) {
        // Evaluate the condition
        ExprCondition exprCondition = new ExprCondition(dcmCopy);
        conditionCleanPixelData = (Boolean) ExpressionResult.get(profileItemCleanPixelData.getCondition(), exprCondition, Boolean.class);
    }
    return conditionCleanPixelData;
}
Also used : ProfileItem(org.karnak.backend.model.profiles.ProfileItem) ExprCondition(org.karnak.backend.model.expression.ExprCondition) CleanPixelData(org.karnak.backend.model.profiles.CleanPixelData)

Aggregations

ExprCondition (org.karnak.backend.model.expression.ExprCondition)6 ExpressionResult (org.karnak.backend.model.expression.ExpressionResult)3 Span (com.vaadin.flow.component.html.Span)2 TextField (com.vaadin.flow.component.textfield.TextField)2 Binder (com.vaadin.flow.data.binder.Binder)2 List (java.util.List)2 Attributes (org.dcm4che3.data.Attributes)2 DestinationEntity (org.karnak.backend.data.entity.DestinationEntity)2 ExpressionError (org.karnak.backend.model.expression.ExpressionError)2 ProfileItem (org.karnak.backend.model.profiles.ProfileItem)2 Div (com.vaadin.flow.component.html.Div)1 HorizontalLayout (com.vaadin.flow.component.orderedlayout.HorizontalLayout)1 BeanValidationBinder (com.vaadin.flow.data.binder.BeanValidationBinder)1 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 HashMap (java.util.HashMap)1