From e8bf56e6535c8111e6b02a20b797b62a9a49614f Mon Sep 17 00:00:00 2001 From: Gunter Zeilinger Date: Thu, 15 Jun 2023 17:38:24 +0200 Subject: [PATCH] Support multiple Patient IDs for one Patient dcm4che/dcm4chee-arc-light#4053 --- .../java/org/dcm4che3/data/IDWithIssuer.java | 28 ++++++++++++------- .../main/java/org/dcm4che3/data/Issuer.java | 15 +++++++--- 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/dcm4che-core/src/main/java/org/dcm4che3/data/IDWithIssuer.java b/dcm4che-core/src/main/java/org/dcm4che3/data/IDWithIssuer.java index a7567614ee..310b707db1 100644 --- a/dcm4che-core/src/main/java/org/dcm4che3/data/IDWithIssuer.java +++ b/dcm4che-core/src/main/java/org/dcm4che3/data/IDWithIssuer.java @@ -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. + *

If this ID equals other ID but only this or other is qualified by an issuer, + * the test returns the value passed by param matchNoIssuer. * - * @param other-the @{code IDWithIssuer} to compare. + *

If this ID equals other ID and the issuer of this is only identified by its Local Namespace Entity ID + * and the issuer of this is only identified by its Universal Entity ID and Universal Entity ID Type or + * the issuer of this is only identified by its Universal Entity ID and Universal Entity ID Type + * and the issuer of this is only identified by its Local Namespace Entity ID + * the test returns the value passed by param matchOnNoMismatch. + * + * @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) { @@ -265,7 +273,7 @@ private static void addTo(IDWithIssuer pid, Set pids) { for (Iterator 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))) diff --git a/dcm4che-core/src/main/java/org/dcm4che3/data/Issuer.java b/dcm4che-core/src/main/java/org/dcm4che3/data/Issuer.java index 55d21b6c9e..b6ade29d47 100644 --- a/dcm4che-core/src/main/java/org/dcm4che3/data/Issuer.java +++ b/dcm4che-core/src/main/java/org/dcm4che3/data/Issuer.java @@ -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; @@ -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())