Search in sources :

Example 1 with AttributeEditorContext

use of org.weasis.dicom.param.AttributeEditorContext in project karnak by OsiriX-Foundation.

the class GatewaySetUpService method addDestinationNode.

private void addDestinationNode(List<ForwardDestination> dstList, ForwardDicomNode fwdSrcNode, DestinationEntity dstNode) {
    try {
        List<AttributeEditor> editors = new ArrayList<>();
        if (!dstNode.getCondition().isEmpty()) {
            editors.add(new ConditionEditor(dstNode.getCondition()));
        }
        final boolean filterBySOPClassesEnable = dstNode.isFilterBySOPClasses();
        if (filterBySOPClassesEnable) {
            editors.add(new FilterEditor(dstNode.getSOPClassUIDEntityFilters()));
        }
        final List<KheopsAlbumsEntity> kheopsAlbumEntities = dstNode.getKheopsAlbumEntities();
        SwitchingAlbum switchingAlbum = new SwitchingAlbum();
        if (kheopsAlbumEntities != null && !kheopsAlbumEntities.isEmpty()) {
            editors.add((Attributes dcm, AttributeEditorContext context) -> {
                kheopsAlbumEntities.forEach(kheopsAlbums -> {
                    switchingAlbum.apply(dstNode, kheopsAlbums, dcm);
                });
            });
        }
        StreamRegistryEditor streamRegistryEditor = new StreamRegistryEditor();
        editors.add(streamRegistryEditor);
        boolean deidentificationEnable = dstNode.isDesidentification();
        boolean profileDefined = dstNode.getProjectEntity() != null && dstNode.getProjectEntity().getProfileEntity() != null;
        if (deidentificationEnable && profileDefined) {
            // TODO add an option in destination model
            editors.add(new DeIdentifyEditor(dstNode));
        }
        DicomProgress progress = new DicomProgress();
        if (dstNode.isActivate()) {
            if (dstNode.getDestinationType() == DestinationType.stow) {
                // parse headers to hashmap
                HashMap<String, String> map = new HashMap<>();
                String headers = dstNode.getHeaders();
                Document doc = Jsoup.parse(headers);
                String key = doc.getElementsByTag("key").text();
                String value = doc.getElementsByTag("value").text();
                if (StringUtil.hasText(key)) {
                    map.put(key, value);
                }
                WebForwardDestination fwd = new WebForwardDestination(dstNode.getId(), fwdSrcNode, dstNode.getUrl(), map, progress, editors, dstNode.getTransferSyntax(), dstNode.isTranscodeOnlyUncompressed());
                if (kheopsAlbumEntities != null && !kheopsAlbumEntities.isEmpty()) {
                    progress.addProgressListener((DicomProgress dicomProgress) -> {
                        Attributes dcm = dicomProgress.getAttributes();
                        kheopsAlbumEntities.forEach(kheopsAlbums -> {
                            switchingAlbum.applyAfterTransfer(kheopsAlbums, dcm);
                        });
                    });
                }
                dstList.add(fwd);
            } else {
                DicomNode destinationNode = new DicomNode(dstNode.getAeTitle(), dstNode.getHostname(), dstNode.getPort());
                DicomForwardDestination dest = new DicomForwardDestination(dstNode.getId(), getDefaultAdvancedParameters(), fwdSrcNode, destinationNode, dstNode.getUseaetdest(), progress, editors, dstNode.getTransferSyntax(), dstNode.isTranscodeOnlyUncompressed());
                dstList.add(dest);
            }
        }
    } catch (IOException e) {
        LOGGER.error("Cannot build ForwardDestination", e);
    }
}
Also used : HashMap(java.util.HashMap) ConditionEditor(org.karnak.backend.model.editor.ConditionEditor) ArrayList(java.util.ArrayList) Attributes(org.dcm4che3.data.Attributes) FilterEditor(org.karnak.backend.model.editor.FilterEditor) IOException(java.io.IOException) KheopsAlbumsEntity(org.karnak.backend.data.entity.KheopsAlbumsEntity) Document(org.jsoup.nodes.Document) StreamRegistryEditor(org.karnak.backend.model.editor.StreamRegistryEditor) DicomProgress(org.weasis.dicom.param.DicomProgress) AttributeEditorContext(org.weasis.dicom.param.AttributeEditorContext) DeIdentifyEditor(org.karnak.backend.model.editor.DeIdentifyEditor) SwitchingAlbum(org.karnak.backend.service.kheops.SwitchingAlbum) AttributeEditor(org.weasis.dicom.param.AttributeEditor) DicomForwardDestination(org.karnak.backend.dicom.DicomForwardDestination) WebForwardDestination(org.karnak.backend.dicom.WebForwardDestination) DicomNode(org.weasis.dicom.param.DicomNode) ForwardDicomNode(org.karnak.backend.dicom.ForwardDicomNode)

Example 2 with AttributeEditorContext

use of org.weasis.dicom.param.AttributeEditorContext 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 3 with AttributeEditorContext

use of org.weasis.dicom.param.AttributeEditorContext 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 4 with AttributeEditorContext

use of org.weasis.dicom.param.AttributeEditorContext in project karnak by OsiriX-Foundation.

the class ProfileTest method should_apply.

@Test
void should_apply() {
    // Init data
    Attributes attributes = new Attributes();
    DestinationEntity destinationEntity = new DestinationEntity();
    destinationEntity.setDestinationType(DestinationType.dicom);
    ProjectEntity projectEntity = new ProjectEntity();
    ProfileEntity profileEntityProject = new ProfileEntity();
    projectEntity.setProfileEntity(profileEntityProject);
    byte[] tabByte = new byte[16];
    tabByte[0] = 1;
    projectEntity.addActiveSecretEntity(new SecretEntity(tabByte));
    destinationEntity.setProjectEntity(projectEntity);
    destinationEntity.setPseudonymType(PseudonymType.EXTID_IN_TAG);
    destinationEntity.setTag("0008,0080");
    destinationEntity.setSavePseudonym(false);
    ProfileEntity profileEntity = new ProfileEntity();
    Set<ProfileElementEntity> profileElementEntities = new HashSet<>();
    ProfileElementEntity profileElementEntityBasic = new ProfileElementEntity();
    profileElementEntityBasic.setCodename("basic.dicom.profile");
    profileElementEntityBasic.setName("nameBasic");
    ProfileElementEntity profileElementEntityCleanPixelData = new ProfileElementEntity();
    profileElementEntityCleanPixelData.setCodename("clean.pixel.data");
    profileElementEntityCleanPixelData.setName("nameCleanPixel");
    profileElementEntityBasic.setPosition(1);
    profileElementEntityCleanPixelData.setPosition(2);
    profileElementEntityBasic.setAction("ReplaceNull");
    profileElementEntityCleanPixelData.setAction("ReplaceNull");
    profileElementEntityCleanPixelData.setCondition("!tagValueContains(#Tag.StationName,'ICT256')");
    profileElementEntities.add(profileElementEntityBasic);
    profileElementEntities.add(profileElementEntityCleanPixelData);
    profileEntity.setProfileElementEntities(profileElementEntities);
    profileEntity.setDefaultIssuerOfPatientId("defaultIssuerOfPatientId");
    Set<MaskEntity> maskEntities = new HashSet<>();
    MaskEntity maskEntity = new MaskEntity();
    maskEntities.add(maskEntity);
    maskEntity.setColor("1234567897");
    maskEntity.setStationName("stationName");
    maskEntity.setRectangles(Arrays.asList(new Rectangle()));
    profileEntity.setMaskEntities(maskEntities);
    AttributeEditorContext context = new AttributeEditorContext("tsuid", null, null);
    attributes.setString(Tag.PatientID, VR.SH, "patientID");
    attributes.setString(Tag.SeriesInstanceUID, VR.SH, "seriesInstanceUID");
    attributes.setString(Tag.SOPInstanceUID, VR.SH, "sopInstanceUID");
    attributes.setString(Tag.IssuerOfPatientID, VR.SH, "issuerOfPatientID");
    attributes.setString(Tag.PixelData, VR.SH, "pixelData");
    attributes.setString(Tag.SOPClassUID, VR.SH, "1.2.840.10008.5.1.4.1.1.88.74");
    attributes.setString(Tag.BurnedInAnnotation, VR.SH, "YES");
    attributes.setString(Tag.StationName, VR.SH, "stationName");
    attributes.setString(524416, VR.SH, "pseudonym");
    // Call method
    Profile profile = new Profile(profileEntity);
    // profile.init(profileEntity);
    profile.apply(attributes, destinationEntity, profileEntity, context);
    // Test results
    assertEquals("NONE", context.getAbort().name());
    assertNull(context.getMaskArea());
}
Also used : MaskEntity(org.karnak.backend.data.entity.MaskEntity) Attributes(org.dcm4che3.data.Attributes) Rectangle(java.awt.Rectangle) SecretEntity(org.karnak.backend.data.entity.SecretEntity) ProfileEntity(org.karnak.backend.data.entity.ProfileEntity) DestinationEntity(org.karnak.backend.data.entity.DestinationEntity) AttributeEditorContext(org.weasis.dicom.param.AttributeEditorContext) ProjectEntity(org.karnak.backend.data.entity.ProjectEntity) ProfileElementEntity(org.karnak.backend.data.entity.ProfileElementEntity) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 5 with AttributeEditorContext

use of org.weasis.dicom.param.AttributeEditorContext in project karnak by OsiriX-Foundation.

the class DeIdentifyEditorTest method should_apply_to_dicom_object.

@Test
void should_apply_to_dicom_object() {
    // Init data
    Attributes attributes = new Attributes();
    DicomNode source = new DicomNode("source");
    DicomNode destination = new DicomNode("destination");
    AttributeEditorContext attributeEditorContext = new AttributeEditorContext("tsuid", source, destination);
    DestinationEntity destinationEntity = new DestinationEntity();
    ProfileEntity profileEntity = new ProfileEntity();
    ProjectEntity projectEntity = new ProjectEntity();
    projectEntity.setProfileEntity(profileEntity);
    destinationEntity.setProjectEntity(projectEntity);
    destinationEntity.setPseudonymType(PseudonymType.EXTID_IN_TAG);
    destinationEntity.setTag("0008,0080");
    destinationEntity.setSavePseudonym(false);
    byte[] tabByte = new byte[16];
    tabByte[0] = 1;
    projectEntity.addActiveSecretEntity(new SecretEntity(tabByte));
    attributes.setString(Tag.PatientID, VR.SH, "patientID");
    attributes.setString(Tag.SeriesInstanceUID, VR.SH, "seriesInstanceUID");
    attributes.setString(Tag.SOPInstanceUID, VR.SH, "sopInstanceUID");
    attributes.setString(Tag.IssuerOfPatientID, VR.SH, "issuerOfPatientID");
    attributes.setString(Tag.PixelData, VR.SH, "pixelData");
    attributes.setString(Tag.SOPClassUID, VR.SH, "1.2.840.10008.5.1.4.1.1.88.74");
    attributes.setString(Tag.BurnedInAnnotation, VR.SH, "YES");
    attributes.setString(Tag.StationName, VR.SH, "stationName");
    attributes.setString(524416, VR.SH, "pseudonym");
    DeIdentifyEditor deIdentifyEditor = new DeIdentifyEditor(destinationEntity);
    // Call method
    deIdentifyEditor.apply(attributes, attributeEditorContext);
    // Test results
    assertEquals("NONE", attributeEditorContext.getAbort().name());
    assertNull(attributeEditorContext.getMaskArea());
}
Also used : DestinationEntity(org.karnak.backend.data.entity.DestinationEntity) AttributeEditorContext(org.weasis.dicom.param.AttributeEditorContext) ProjectEntity(org.karnak.backend.data.entity.ProjectEntity) Attributes(org.dcm4che3.data.Attributes) SecretEntity(org.karnak.backend.data.entity.SecretEntity) DicomNode(org.weasis.dicom.param.DicomNode) ProfileEntity(org.karnak.backend.data.entity.ProfileEntity) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

Attributes (org.dcm4che3.data.Attributes)14 AttributeEditorContext (org.weasis.dicom.param.AttributeEditorContext)14 IOException (java.io.IOException)6 BytesWithImageDescriptor (org.dcm4che3.img.stream.BytesWithImageDescriptor)6 AdaptTransferSyntax (org.dcm4che3.img.stream.ImageAdapter.AdaptTransferSyntax)6 AttributeEditor (org.weasis.dicom.param.AttributeEditor)6 Test (org.junit.jupiter.api.Test)5 AbortException (org.karnak.backend.exception.AbortException)5 DicomNode (org.weasis.dicom.param.DicomNode)5 HttpException (org.weasis.dicom.web.HttpException)5 PlanarImage (org.weasis.opencv.data.PlanarImage)5 ArrayList (java.util.ArrayList)4 DestinationEntity (org.karnak.backend.data.entity.DestinationEntity)4 ProfileEntity (org.karnak.backend.data.entity.ProfileEntity)4 ProjectEntity (org.karnak.backend.data.entity.ProjectEntity)4 SecretEntity (org.karnak.backend.data.entity.SecretEntity)4 File (java.io.File)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 List (java.util.List)3