Search in sources :

Example 1 with ProfileEntity

use of org.karnak.backend.data.entity.ProfileEntity 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 ProfileEntity

use of org.karnak.backend.data.entity.ProfileEntity in project karnak by OsiriX-Foundation.

the class Profile method applyCleanPixelData.

public void applyCleanPixelData(Attributes dcmCopy, AttributeEditorContext context, ProfileEntity profileEntity) {
    Object pix = dcmCopy.getValue(Tag.PixelData);
    if ((pix instanceof BulkData || pix instanceof Fragments) && !profileEntity.getMaskEntities().isEmpty() && profiles.stream().anyMatch(p -> p instanceof CleanPixelData)) {
        String sopClassUID = dcmCopy.getString(Tag.SOPClassUID);
        if (!StringUtil.hasText(sopClassUID)) {
            throw new IllegalStateException("DICOM Object does not contain sopClassUID");
        }
        String scuPattern = sopClassUID + ".";
        MaskArea mask = getMask(dcmCopy.getString(Tag.StationName));
        // BurnedInAnnotation
        if (isCleanPixelAllowedDependingImageType(dcmCopy, sopClassUID, scuPattern) && evaluateConditionCleanPixelData(dcmCopy)) {
            context.setMaskArea(mask);
            if (mask == null) {
                throw new IllegalStateException("Clean pixel is not applied: mask not defined in station name");
            }
        } else {
            context.setMaskArea(null);
        }
    }
}
Also used : 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) CleanPixelData(org.karnak.backend.model.profiles.CleanPixelData) Fragments(org.dcm4che3.data.Fragments) BulkData(org.dcm4che3.data.BulkData) MaskArea(org.dcm4che3.img.op.MaskArea)

Example 3 with ProfileEntity

use of org.karnak.backend.data.entity.ProfileEntity in project karnak by OsiriX-Foundation.

the class ProfilePipeService method validateProfile.

public ArrayList<ProfileError> validateProfile(ProfilePipeBody profilePipeYml) {
    ProfileEntity newProfileEntity = createNewProfile(profilePipeYml, false);
    ArrayList<ProfileError> profileErrors = new ArrayList<>();
    for (ProfileElementEntity profileElementEntity : newProfileEntity.getProfileElementEntities()) {
        ProfileError profileError = new ProfileError(profileElementEntity);
        profileErrors.add(profileError);
        ProfileItemType t = ProfileItemType.getType(profileElementEntity.getCodename());
        if (t == null) {
            profileError.setError("Cannot find the profile codename: " + profileElementEntity.getCodename());
        } else {
            try {
                t.getProfileClass().getConstructor(ProfileElementEntity.class).newInstance(profileElementEntity);
            } catch (Exception e) {
                profileError.setError(e.getCause().getMessage());
                continue;
            }
        }
    }
    return profileErrors;
}
Also used : ProfileError(org.karnak.frontend.profile.component.errorprofile.ProfileError) ProfileElementEntity(org.karnak.backend.data.entity.ProfileElementEntity) ArrayList(java.util.ArrayList) ProfileItemType(org.karnak.backend.enums.ProfileItemType) ProfileEntity(org.karnak.backend.data.entity.ProfileEntity)

Example 4 with ProfileEntity

use of org.karnak.backend.data.entity.ProfileEntity in project karnak by OsiriX-Foundation.

the class ProfileLogic method setProfileComponent.

public void setProfileComponent(InputStream stream) {
    try {
        ProfilePipeBody profilePipe = readProfileYaml(stream);
        ArrayList<ProfileError> profileErrors = profilePipeService.validateProfile(profilePipe);
        Predicate<ProfileError> errorPredicate = profileError -> profileError.getError() != null;
        if (profileErrors.stream().noneMatch(errorPredicate)) {
            final ProfileEntity newProfileEntity = profilePipeService.saveProfilePipe(profilePipe, false);
            profileView.getProfileErrorView().removeAll();
            profileView.getProfileGrid().selectRow(newProfileEntity);
            profileView.getProfileComponent().setProfile(newProfileEntity);
            profileView.getProfileElementMainView().setProfile(newProfileEntity);
        } else {
            profileView.getProfileGrid().deselectAll();
            profileView.getProfileErrorView().setView(profileErrors);
            profileView.remove(profileView.getProfileHorizontalLayout());
            profileView.add(profileView.getProfileErrorView());
        }
        if (profilePipe.getDefaultIssuerOfPatientID() != null) {
            openWarningIssuerDialog();
        }
    } catch (YAMLException e) {
        LOGGER.error("Unable to read uploaded YAML", e);
        profileView.getProfileErrorView().setView("Unable to read uploaded YAML file.\n" + "Please make sure it is a YAML file and respects the YAML structure.");
    }
}
Also used : ProfileError(org.karnak.frontend.profile.component.errorprofile.ProfileError) Text(com.vaadin.flow.component.Text) ListDataProvider(com.vaadin.flow.data.provider.ListDataProvider) ProfileEntity(org.karnak.backend.data.entity.ProfileEntity) Logger(org.slf4j.Logger) Predicate(java.util.function.Predicate) Constructor(org.yaml.snakeyaml.constructor.Constructor) ProfilePipeService(org.karnak.backend.service.profilepipe.ProfilePipeService) LoggerFactory(org.slf4j.LoggerFactory) Div(com.vaadin.flow.component.html.Div) Autowired(org.springframework.beans.factory.annotation.Autowired) ArrayList(java.util.ArrayList) Yaml(org.yaml.snakeyaml.Yaml) Button(com.vaadin.flow.component.button.Button) Service(org.springframework.stereotype.Service) ProfileError(org.karnak.frontend.profile.component.errorprofile.ProfileError) ProfilePipeBody(org.karnak.backend.model.profilebody.ProfilePipeBody) Dialog(com.vaadin.flow.component.dialog.Dialog) InputStream(java.io.InputStream) YAMLException(org.yaml.snakeyaml.error.YAMLException) ProfilePipeBody(org.karnak.backend.model.profilebody.ProfilePipeBody) YAMLException(org.yaml.snakeyaml.error.YAMLException) ProfileEntity(org.karnak.backend.data.entity.ProfileEntity)

Example 5 with ProfileEntity

use of org.karnak.backend.data.entity.ProfileEntity in project karnak by OsiriX-Foundation.

the class ProfileElementRepoTest method shouldFindAllRecords.

/**
 * Test find all.
 */
@Test
void shouldFindAllRecords() {
    // Create an entity to save
    // Profile
    ProfileEntity profileEntity = new ProfileEntity();
    profileEntity.setName("name");
    profileEntity = profileRepo.saveAndFlush(profileEntity);
    // ProfileElement
    ProfileElementEntity entity = new ProfileElementEntity();
    entity.setName("Name");
    entity.setProfileEntity(profileEntity);
    // Save the entity
    LOGGER.info("Saving entity with name [{}]", entity.getName());
    repository.saveAndFlush(entity);
    // Find all
    List<ProfileElementEntity> all = repository.findAll();
    // Test find all
    assertNotNull(all);
    assertTrue(all.size() > 0);
    assertEquals(1, all.size());
    LOGGER.info("Number of entities found [{}]", all.size());
}
Also used : ProfileElementEntity(org.karnak.backend.data.entity.ProfileElementEntity) ProfileEntity(org.karnak.backend.data.entity.ProfileEntity) Test(org.junit.jupiter.api.Test) DataJpaTest(org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest)

Aggregations

ProfileEntity (org.karnak.backend.data.entity.ProfileEntity)42 Test (org.junit.jupiter.api.Test)33 ProfileElementEntity (org.karnak.backend.data.entity.ProfileElementEntity)26 Attributes (org.dcm4che3.data.Attributes)21 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)15 IncludedTagEntity (org.karnak.backend.data.entity.IncludedTagEntity)14 Profile (org.karnak.backend.service.profilepipe.Profile)12 DataJpaTest (org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest)10 HashSet (java.util.HashSet)9 Sequence (org.dcm4che3.data.Sequence)9 ProjectEntity (org.karnak.backend.data.entity.ProjectEntity)8 ArrayList (java.util.ArrayList)6 DestinationEntity (org.karnak.backend.data.entity.DestinationEntity)6 ArgumentEntity (org.karnak.backend.data.entity.ArgumentEntity)5 List (java.util.List)4 SecretEntity (org.karnak.backend.data.entity.SecretEntity)4 ProfileItemType (org.karnak.backend.enums.ProfileItemType)4 AttributeEditorContext (org.weasis.dicom.param.AttributeEditorContext)4 Comparator (java.util.Comparator)3 Set (java.util.Set)3