Search in sources :

Example 1 with Attributes

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

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

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

the class Profile method apply.

public void apply(Attributes dcm, DestinationEntity destinationEntity, ProfileEntity profileEntity, AttributeEditorContext context) {
    final String SOPInstanceUID = dcm.getString(Tag.SOPInstanceUID);
    final String SeriesInstanceUID = dcm.getString(Tag.SeriesInstanceUID);
    final String IssuerOfPatientID = dcm.getString(Tag.IssuerOfPatientID);
    final String PatientID = dcm.getString(Tag.PatientID);
    final HMAC hmac = generateHMAC(destinationEntity, PatientID);
    MDC.put("SOPInstanceUID", SOPInstanceUID);
    MDC.put("SeriesInstanceUID", SeriesInstanceUID);
    MDC.put("issuerOfPatientID", IssuerOfPatientID);
    MDC.put("PatientID", PatientID);
    String pseudonymValue = this.pseudonym.generatePseudonym(destinationEntity, dcm);
    String profilesCodeName = profiles.stream().map(ProfileItem::getCodeName).collect(Collectors.joining("-"));
    BigInteger patientValue = generatePatientID(pseudonymValue, hmac);
    String newPatientID = patientValue.toString(16).toUpperCase();
    Attributes dcmCopy = new Attributes(dcm);
    // Apply clean pixel data
    applyCleanPixelData(dcmCopy, context, profileEntity);
    // Apply clean recognizable visual features option
    applyDefacing(dcmCopy, context);
    applyAction(dcm, dcmCopy, hmac, null, null, context);
    // Set tags by default
    AttributesByDefault.setPatientModule(dcm, newPatientID, pseudonymValue, destinationEntity.getProjectEntity());
    AttributesByDefault.setSOPCommonModule(dcm);
    AttributesByDefault.setClinicalTrialAttributes(dcm, destinationEntity.getProjectEntity(), pseudonymValue);
    final Marker clincalMarker = MarkerFactory.getMarker("CLINICAL");
    MDC.put("DeidentifySOPInstanceUID", dcm.getString(Tag.SOPInstanceUID));
    MDC.put("DeidentifySeriesInstanceUID", dcm.getString(Tag.SeriesInstanceUID));
    MDC.put("ProjectName", destinationEntity.getProjectEntity().getName());
    MDC.put("ProfileName", profileEntity.getName());
    MDC.put("ProfileCodenames", profilesCodeName);
    LOGGER.info(clincalMarker, "");
    MDC.clear();
}
Also used : HMAC(org.karnak.backend.model.profilepipe.HMAC) Attributes(org.dcm4che3.data.Attributes) BigInteger(java.math.BigInteger) Marker(org.slf4j.Marker)

Example 4 with Attributes

use of org.dcm4che3.data.Attributes 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 5 with Attributes

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

Aggregations

Attributes (org.dcm4che3.data.Attributes)384 IOException (java.io.IOException)75 DicomServiceException (org.dcm4che3.net.service.DicomServiceException)64 QueryAttributes (org.dcm4chee.arc.query.util.QueryAttributes)38 Sequence (org.dcm4che3.data.Sequence)36 DicomInputStream (org.dcm4che3.io.DicomInputStream)36 ConfigurationException (org.dcm4che3.conf.api.ConfigurationException)34 ApplicationEntity (org.dcm4che3.net.ApplicationEntity)28 Test (org.junit.jupiter.api.Test)25 Logger (org.slf4j.Logger)23 LoggerFactory (org.slf4j.LoggerFactory)23 File (java.io.File)22 ArchiveAEExtension (org.dcm4chee.arc.conf.ArchiveAEExtension)22 ArchiveDeviceExtension (org.dcm4chee.arc.conf.ArchiveDeviceExtension)21 ProfileElementEntity (org.karnak.backend.data.entity.ProfileElementEntity)21 ProfileEntity (org.karnak.backend.data.entity.ProfileEntity)21 DicomOutputStream (org.dcm4che3.io.DicomOutputStream)20 StoreSession (org.dcm4chee.arc.store.StoreSession)20 ArrayList (java.util.ArrayList)18 Inject (javax.inject.Inject)17