-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
360 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
weasis-dicom-tools/src/main/java/org/weasis/dicom/ref/AnatomicItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* Copyright (c) 2024 Weasis Team and other contributors. | ||
* | ||
* This program and the accompanying materials are made available under the terms of the Eclipse | ||
* Public License 2.0 which is available at https://www.eclipse.org/legal/epl-2.0, or the Apache | ||
* License, Version 2.0 which is available at https://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 | ||
*/ | ||
package org.weasis.dicom.ref; | ||
|
||
public interface AnatomicItem { | ||
String getCodeValue(); | ||
|
||
String getCodeMeaning(); | ||
|
||
CodingScheme getScheme(); | ||
|
||
String getLegacyCode(); | ||
|
||
boolean isPaired(); | ||
} |
144 changes: 144 additions & 0 deletions
144
weasis-dicom-tools/src/main/java/org/weasis/dicom/ref/AnatomicRegion.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
/* | ||
* Copyright (c) 2024 Weasis Team and other contributors. | ||
* | ||
* This program and the accompanying materials are made available under the terms of the Eclipse | ||
* Public License 2.0 which is available at https://www.eclipse.org/legal/epl-2.0, or the Apache | ||
* License, Version 2.0 which is available at https://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 | ||
*/ | ||
package org.weasis.dicom.ref; | ||
|
||
import java.util.HashSet; | ||
import java.util.Objects; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
import org.dcm4che3.data.Attributes; | ||
import org.dcm4che3.data.Sequence; | ||
import org.dcm4che3.data.Tag; | ||
import org.dcm4che3.data.VR; | ||
import org.weasis.core.util.StringUtil; | ||
import org.weasis.dicom.macro.Code; | ||
import org.weasis.dicom.ref.AnatomicBuilder.Category; | ||
|
||
public class AnatomicRegion { | ||
|
||
private final Category category; | ||
private final AnatomicItem region; | ||
private final Set<AnatomicModifier> modifiers; | ||
|
||
public AnatomicRegion(AnatomicItem region) { | ||
this(null, region, null); | ||
} | ||
|
||
public AnatomicRegion(Category category, AnatomicItem region, Set<AnatomicModifier> modifiers) { | ||
this.category = category; | ||
this.region = Objects.requireNonNull(region); | ||
this.modifiers = modifiers == null ? new HashSet<>() : modifiers; | ||
} | ||
|
||
public static AnatomicRegion read(Attributes dcm) { | ||
if (dcm == null) { | ||
return null; | ||
} | ||
// Get only the first item | ||
Attributes regionAttributes = dcm.getNestedDataset(Tag.AnatomicRegionSequence); | ||
if (regionAttributes == null) { | ||
String bodyPart = dcm.getString(Tag.BodyPartExamined); | ||
if (StringUtil.hasText(bodyPart)) { | ||
BodyPart item = AnatomicBuilder.getBodyPartFromLegacyCode(bodyPart); | ||
if (item != null) { | ||
return new AnatomicRegion(item); | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
String codeValue = new Code(regionAttributes).getExistingCodeValue(); | ||
AnatomicItem item = AnatomicBuilder.getBodyPartFromCode(codeValue); | ||
if (item == null) { | ||
item = AnatomicBuilder.getSurfacePartFromCode(codeValue); | ||
} | ||
|
||
AnatomicRegion region = new AnatomicRegion(item); | ||
addModifiers(regionAttributes, region); | ||
return region; | ||
} | ||
|
||
public static void write(Attributes dcm, AnatomicRegion region) { | ||
if (dcm == null || region == null) { | ||
return; | ||
} | ||
Attributes regAttributes = new Attributes(); | ||
AnatomicItem anatomicItem = region.getRegion(); | ||
regAttributes.setString(Tag.CodeValue, VR.SH, anatomicItem.getCodeValue()); | ||
regAttributes.setString(Tag.CodeMeaning, VR.LO, anatomicItem.getCodeMeaning()); | ||
writeScheme(regAttributes, anatomicItem.getScheme()); | ||
if (anatomicItem.getLegacyCode() != null) { | ||
dcm.setString(Tag.BodyPartExamined, VR.CS, anatomicItem.getLegacyCode()); | ||
} | ||
|
||
Set<AnatomicModifier> modifiers = region.getModifiers(); | ||
if (modifiers != null && !modifiers.isEmpty()) { | ||
Sequence seq = | ||
regAttributes.newSequence(Tag.AnatomicRegionModifierSequence, modifiers.size()); | ||
for (AnatomicModifier modifier : modifiers) { | ||
Attributes mod = new Attributes(); | ||
writeScheme(mod, modifier.getScheme()); | ||
mod.setString(Tag.CodeValue, VR.SH, modifier.getCodeValue()); | ||
mod.setString(Tag.CodeMeaning, VR.LO, modifier.getCodeMeaning()); | ||
seq.add(mod); | ||
} | ||
} | ||
dcm.newSequence(Tag.AnatomicRegionSequence, 1).add(regAttributes); | ||
} | ||
|
||
private static void writeScheme(Attributes regionAttributes, CodingScheme scheme) { | ||
regionAttributes.setString(Tag.CodingSchemeDesignator, VR.SH, scheme.getDesignator()); | ||
regionAttributes.setString(Tag.CodingSchemeName, VR.SH, scheme.getCodeName()); | ||
regionAttributes.setString(Tag.CodingSchemeUID, VR.UI, scheme.getUid()); | ||
} | ||
|
||
private static void addModifiers(Attributes regionAttributes, AnatomicRegion region) { | ||
Sequence seq = regionAttributes.getSequence(Tag.AnatomicRegionModifierSequence); | ||
if (seq != null) { | ||
for (Attributes attribute : seq) { | ||
AnatomicModifier modifier = | ||
AnatomicBuilder.getAnatomicModifierFromCode(new Code(attribute).getExistingCodeValue()); | ||
if (modifier != null) { | ||
region.addModifier(modifier); | ||
} | ||
} | ||
} | ||
} | ||
|
||
public AnatomicItem getRegion() { | ||
return region; | ||
} | ||
|
||
public Category getCategory() { | ||
return category; | ||
} | ||
|
||
public Set<AnatomicModifier> getModifiers() { | ||
return modifiers; | ||
} | ||
|
||
public void addModifier(AnatomicModifier modifier) { | ||
modifiers.add(modifier); | ||
} | ||
|
||
public void removeModifier(AnatomicModifier modifier) { | ||
modifiers.remove(modifier); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
String modifiersList = | ||
modifiers.stream().map(AnatomicModifier::getCodeMeaning).collect(Collectors.joining(", ")); | ||
if (StringUtil.hasText(modifiersList)) { | ||
modifiersList = " (" + modifiersList + ")"; | ||
} | ||
return region.getCodeMeaning() + modifiersList; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
weasis-dicom-tools/src/main/java/org/weasis/dicom/ref/MesCategory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright (c) 2009-2020 Weasis Team and other contributors. | ||
* | ||
* This program and the accompanying materials are made available under the terms of the Eclipse | ||
* Public License 2.0 which is available at https://www.eclipse.org/legal/epl-2.0, or the Apache | ||
* License, Version 2.0 which is available at https://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 | ||
*/ | ||
package org.weasis.dicom.ref; | ||
|
||
import java.util.MissingResourceException; | ||
import java.util.ResourceBundle; | ||
|
||
public class MesCategory { | ||
private static final String BUNDLE_NAME = "org.weasis.dicom.ref.category"; // NON-NLS | ||
|
||
private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME); | ||
|
||
private MesCategory() {} | ||
|
||
public static String getString(String key) { | ||
try { | ||
return RESOURCE_BUNDLE.getString(key); | ||
} catch (MissingResourceException e) { | ||
return '!' + key + '!'; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
weasis-dicom-tools/src/main/resources/org/weasis/dicom/ref/category.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#Sun May 19 20:36:34 CEST 2024 | ||
SURFACE=Dermatology (surface) | ||
ALL_RADIO=Radiology | ||
COMMON=Common | ||
ENDOSCOPY=Endoscopy |
5 changes: 5 additions & 0 deletions
5
weasis-dicom-tools/src/main/resources/org/weasis/dicom/ref/category_fr.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#Sun May 19 20:36:34 CEST 2024 | ||
SURFACE=Dermatologie (surface) | ||
ALL_RADIO=Radiologie | ||
COMMON=Commun | ||
ENDOSCOPY=Endoscopie |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.