Search in sources :

Example 1 with Tag

use of org.dcm4che3.data.Tag 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 Tag

use of org.dcm4che3.data.Tag in project karnak by OsiriX-Foundation.

the class MetadataDICOMObject method getValueRec.

private static String getValueRec(Attributes dcm, int tag) {
    String tagValue = dcm.getString(tag);
    Attributes dcmParent = dcm.getParent();
    if (dcmParent != null && tagValue == null) {
        return getValueRec(dcmParent, tag);
    }
    return tagValue;
}
Also used : Attributes(org.dcm4che3.data.Attributes)

Example 3 with Tag

use of org.dcm4che3.data.Tag in project karnak by OsiriX-Foundation.

the class AddTest method should_add_tag.

@Test
void should_add_tag() {
    // Init data
    Attributes attributes = new Attributes();
    Add add = new Add("symbol", 524294, VR.AE, "dummyValue");
    // Add tag
    add.execute(attributes, 524291, null);
    // Test result
    assertEquals("dummyValue", attributes.getString(524294));
}
Also used : Attributes(org.dcm4che3.data.Attributes) Test(org.junit.jupiter.api.Test)

Example 4 with Tag

use of org.dcm4che3.data.Tag in project karnak by OsiriX-Foundation.

the class ReplaceTest method should_replace_tag_not_null.

@Test
void should_replace_tag_not_null() {
    // Init data
    Attributes attributes = new Attributes();
    attributes.setString(524294, VR.AE, "initialValue");
    Replace replace = new Replace("symbol", "dummyValue");
    // Add tag
    replace.execute(attributes, 524294, null);
    // Test result
    assertEquals("dummyValue", attributes.getString(524294));
}
Also used : Attributes(org.dcm4che3.data.Attributes) Test(org.junit.jupiter.api.Test)

Example 5 with Tag

use of org.dcm4che3.data.Tag in project karnak by OsiriX-Foundation.

the class ProfileTest method xandZProfile.

@Test
void xandZProfile() {
    final Attributes dataset1 = new Attributes();
    final Attributes dataset2 = new Attributes();
    dataset1.setString(Tag.PatientName, VR.PN, "TEST-Expr-AddAction");
    dataset1.setString(Tag.StudyInstanceUID, VR.UI, "12345");
    dataset1.setString(Tag.PatientAge, VR.AS, "075Y");
    dataset2.setNull(Tag.PatientName, VR.PN);
    dataset2.setNull(Tag.StudyInstanceUID, VR.UI);
    dataset2.setString(Tag.PatientAge, VR.AS, "075Y");
    dataset2.remove(Tag.PatientAge);
    final ProfileEntity profileEntity = new ProfileEntity("TEST", "0.9.1", "0.9.1", "DPA");
    final ProfileElementEntity profileElementEntity = new ProfileElementEntity("Remove tag", "action.on.specific.tags", null, "X", null, 0, profileEntity);
    profileElementEntity.addIncludedTag(new IncludedTagEntity("(0010,1010)", profileElementEntity));
    profileEntity.addProfilePipe(profileElementEntity);
    final ProfileElementEntity profileElementEntity2 = new ProfileElementEntity("Replace by null", "action.on.specific.tags", null, "Z", null, 1, profileEntity);
    profileElementEntity2.addIncludedTag(new IncludedTagEntity("(xxxx,xxxx)", profileElementEntity2));
    profileEntity.addProfilePipe(profileElementEntity2);
    Profile profile = new Profile(profileEntity);
    profile.applyAction(dataset1, dataset1, defaultHMAC, null, null, null);
    assertTrue(DicomObjectTools.dicomObjectEquals(dataset2, dataset1));
}
Also used : IncludedTagEntity(org.karnak.backend.data.entity.IncludedTagEntity) ProfileElementEntity(org.karnak.backend.data.entity.ProfileElementEntity) Attributes(org.dcm4che3.data.Attributes) ProfileEntity(org.karnak.backend.data.entity.ProfileEntity) Profile(org.karnak.backend.service.profilepipe.Profile) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

Attributes (org.dcm4che3.data.Attributes)25 Test (org.junit.jupiter.api.Test)11 Sequence (org.dcm4che3.data.Sequence)10 ProfileElementEntity (org.karnak.backend.data.entity.ProfileElementEntity)9 ProfileEntity (org.karnak.backend.data.entity.ProfileEntity)9 IncludedTagEntity (org.karnak.backend.data.entity.IncludedTagEntity)8 Profile (org.karnak.backend.service.profilepipe.Profile)8 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)8 VR (org.dcm4che3.data.VR)5 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Set (java.util.Set)2 Component (com.vaadin.flow.component.Component)1 VerticalLayout (com.vaadin.flow.component.orderedlayout.VerticalLayout)1 Tab (com.vaadin.flow.component.tabs.Tab)1 BeanValidationBinder (com.vaadin.flow.data.binder.BeanValidationBinder)1 Binder (com.vaadin.flow.data.binder.Binder)1 java.awt (java.awt)1 Color (java.awt.Color)1