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);
}
}
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);
}
}
}
}
}
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();
}
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);
}
}
}
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;
}
Aggregations