Skip to content

Commit

Permalink
Support multiple Patient IDs for one Patient dcm4che/dcm4chee-arc-li…
Browse files Browse the repository at this point in the history
  • Loading branch information
gunterze committed Jun 15, 2023
1 parent 5129a89 commit e8bf56e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 14 deletions.
28 changes: 18 additions & 10 deletions dcm4che-core/src/main/java/org/dcm4che3/data/IDWithIssuer.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,22 +156,30 @@ public boolean equals(Object obj) {
* @return {@code true}, if this ID equals other ID and this issuer matches other issuer, otherwise {@code false}.
*/
public boolean matches(IDWithIssuer other) {
return id.equals(other.id) &&
(issuer == null
? other.issuer == null
: issuer.matches(other.issuer));
return matches(other, false, false);
}

/**
* Test if this ID equals other ID and this issuer matches other issuer.
* If this ID equals other ID but only this or other is qualified by an issuer, the test succeeds.
* <p>If this ID equals other ID but only this or other is qualified by an issuer,
* the test returns the value passed by param <em>matchNoIssuer</em>.
*
* @param other-the @{code IDWithIssuer} to compare.
* <p>If this ID equals other ID and the issuer of this is only identified by its <em>Local Namespace Entity ID</em>
* and the issuer of this is only identified by its <em>Universal Entity ID</em> and <em>Universal Entity ID Type</em> or
* the issuer of this is only identified by its <em>Universal Entity ID</em> and Universal Entity ID Type</em>
* and the issuer of this is only identified by its <em>Local Namespace Entity ID</em>
* the test returns the value passed by param <em>matchOnNoMismatch</em>.
*
* @param other the @{code IDWithIssuer} to compare.
* @param matchNoIssuer value returned if only this or other is qualified by an issuer
* @param matchOnNoMismatch value returned if the issuer of this and the other includes different types of identifiers
* @return {@code true}, if this ID equals other ID and this issuer matches other issuer, otherwise {@code false}.
*/
public boolean matchesWithoutIssuer(IDWithIssuer other) {
return id.equals(other.id) &&
(issuer == null || other.issuer == null || issuer.matches(other.issuer));
public boolean matches(IDWithIssuer other, boolean matchNoIssuer, boolean matchOnNoMismatch) {
return id.equals(other.id)
&& (issuer == null
? (other.issuer == null || matchNoIssuer)
: issuer.matches(other.issuer, matchNoIssuer, matchOnNoMismatch));
}

public Attributes exportPatientIDWithIssuer(Attributes attrs) {
Expand Down Expand Up @@ -265,7 +273,7 @@ private static void addTo(IDWithIssuer pid, Set<IDWithIssuer> pids) {

for (Iterator<IDWithIssuer> itr = pids.iterator(); itr.hasNext();) {
IDWithIssuer next = itr.next();
if (next.matchesWithoutIssuer(pid)) {
if (next.matches(pid, true, true)) {
// replace existing matching pid if it is lesser qualified
if (pid.issuer != null && (next.issuer == null
|| next.issuer.isLesserQualifiedThan(pid.issuer)))
Expand Down
15 changes: 11 additions & 4 deletions dcm4che-core/src/main/java/org/dcm4che3/data/Issuer.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public final String getUniversalEntityIDType() {
}

public boolean merge(Issuer other) {
if (!matches(other))
if (!matches(other, true, true))
throw new IllegalArgumentException("other=" + other);

boolean mergeLocalNamespace;
Expand Down Expand Up @@ -198,16 +198,23 @@ private boolean equals(String s1, String s2) {
}

public boolean matches(Issuer other) {
if (this == other || other == null)
return matches(other, true, false);
}

public boolean matches(Issuer other, boolean matchNoIssuer, boolean matchOnNoMismatch) {
if (this == other)
return true;

if (other == null)
return matchNoIssuer;

boolean matchLocal = localNamespaceEntityID != null
&& other.getLocalNamespaceEntityID() != null;
boolean matchUniversal = universalEntityID != null
&& other.getUniversalEntityID() != null;

return (matchLocal || matchUniversal)
&& (!matchLocal
return !matchLocal && !matchUniversal ? matchOnNoMismatch
: (!matchLocal
|| localNamespaceEntityID.equals(other.getLocalNamespaceEntityID()))
&& (!matchUniversal
|| universalEntityID.equals(other.getUniversalEntityID())
Expand Down

0 comments on commit e8bf56e

Please sign in to comment.