Skip to content

Commit

Permalink
Improve mapping between XDS XON and FHIR Organization
Browse files Browse the repository at this point in the history
Fixes #165
  • Loading branch information
qligier committed Jul 30, 2024
1 parent 610d886 commit 217b4d7
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 17 deletions.
1 change: 1 addition & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## Unreleased

- Fixed an NPE in the assertion route
- Improved mapping between XDS XON and FHIR Organization [165](https://github.com/i4mi/MobileAccessGateway/issues/165)

## 2024/05/15 v070
- support for multiple IDP's [128](https://github.com/i4mi/MobileAccessGateway/issues/128)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@
import ch.bfh.ti.i4mi.mag.Config;
import ch.bfh.ti.i4mi.mag.pmir.PatientReferenceCreator;

import static ch.bfh.ti.i4mi.mag.mhd.Utils.isUnprefixedOid;
import static ch.bfh.ti.i4mi.mag.mhd.Utils.isUnprefixedUuid;

/**
* base query response converter XDS to MHD
* @author alexander kreutz
Expand Down Expand Up @@ -236,21 +239,35 @@ public Patient transformPatient(Person person) {
}

/**
* XDS Organization -> FHIR Organization
* IPF Organization (XDS XON) -> FHIR Organization
* @param org
* @return
*/
public Organization transform(org.openehealth.ipf.commons.ihe.xds.core.metadata.Organization org) {
if (org == null) return null;
Organization result = new Organization();
if (org == null) {
return null;
}
final var result = new Organization();
result.setName(org.getOrganizationName());
String id = org.getIdNumber();
// TODO handle system not given
String id = org.getIdNumber();
if (isUnprefixedOid(id)) {
id = "urn:oid:" + id;
} else if (isUnprefixedUuid(id)) {
id = "urn:uuid:" + id;
}

if (org.getAssigningAuthority()!=null) {
String system = org.getAssigningAuthority().getUniversalId();
result.addIdentifier().setSystem("urn:oid:"+system).setValue(id);
} else result.addIdentifier().setValue(id);
if (org.getAssigningAuthority() != null) {
String system = org.getAssigningAuthority().getUniversalId();
if (isUnprefixedOid(system)) {
system = "urn:oid:" + system;
}
result.addIdentifier().setSystem(system).setValue(id);
} else {
final var identifier = result.addIdentifier().setValue(id);
if (id.startsWith("urn:oid:") || id.startsWith("urn:uuid:")) {
identifier.setSystem("urn:ietf:rfc:3986");
}
}
return result;
}

Expand Down
8 changes: 8 additions & 0 deletions src/main/java/ch/bfh/ti/i4mi/mag/mhd/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,12 @@ public static Processor retrievedDocumentSetToHttResponse() {
};
}
*/

public static boolean isUnprefixedOid(final String oid) {
return oid != null && oid.matches("\\d+(\\.\\d+)+");
}

public static boolean isUnprefixedUuid(final String uuid) {
return uuid != null && uuid.matches("[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1000,20 +1000,30 @@ public Telecom transform(ContactPoint contactPoint) {
}

/**
* FHIR Organization -> XDS Organization
* FHIR Organization -> IPF Organization (XDS XON)
* @param org
* @return
*/
public org.openehealth.ipf.commons.ihe.xds.core.metadata.Organization transform(Organization org) {
org.openehealth.ipf.commons.ihe.xds.core.metadata.Organization result = new org.openehealth.ipf.commons.ihe.xds.core.metadata.Organization();
final var result = new org.openehealth.ipf.commons.ihe.xds.core.metadata.Organization();
result.setOrganizationName(org.getName());
Identifier identifier = org.getIdentifierFirstRep();
final Identifier identifier = org.getIdentifierFirstRep();
if (identifier != null) {
result.setIdNumber(identifier.getValue());
result.setAssigningAuthority(new AssigningAuthority(noPrefix(identifier.getSystem())));
}
return result;
}
if (identifier.hasSystem()) {
if (identifier.getSystem().equals("urn:ietf:rfc:3986")) {
// The value is a URI, remove the prefix and ignore the system
result.setIdNumber(noPrefix(identifier.getValue()));
} else {
// The value is an identifier, use the system as assigning authority
result.setIdNumber(identifier.getValue());
result.setAssigningAuthority(new AssigningAuthority(noPrefix(identifier.getSystem())));
}
} else if (identifier.hasValue()) {
result.setIdNumber(identifier.getValue());
}
}
return result;
}

/**
* FHIR Reference to Author -> XDS Author
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package ch.bfh.ti.i4mi.mag.mhd;

import ch.bfh.ti.i4mi.mag.Config;
import ch.bfh.ti.i4mi.mag.mhd.iti67.Iti67ResponseConverter;
import org.junit.jupiter.api.Test;
import org.openehealth.ipf.commons.ihe.xds.core.metadata.Hl7v2Based;
import org.openehealth.ipf.commons.ihe.xds.core.metadata.Organization;

import static org.junit.jupiter.api.Assertions.*;

/**
* Tests for {@link BaseQueryResponseConverter}.
*
* @author Quentin Ligier
**/
class BaseQueryResponseConverterTest {

@Test
void testTransformOrganization() {
final var converter = new Iti67ResponseConverter(new Config());

var fhirOrg = converter.transform(Hl7v2Based.parse("Test^^^^^^^^^1234", Organization.class));
assertEquals("Test", fhirOrg.getName());
assertEquals(1, fhirOrg.getIdentifier().size());
assertEquals("1234", fhirOrg.getIdentifierFirstRep().getValue());
assertFalse(fhirOrg.getIdentifierFirstRep().hasSystem());

fhirOrg = converter.transform(Hl7v2Based.parse("Test^^^^^&1.2.3&ISO^^^^1234", Organization.class));
assertEquals("Test", fhirOrg.getName());
assertEquals(1, fhirOrg.getIdentifier().size());
assertEquals("1234", fhirOrg.getIdentifierFirstRep().getValue());
assertEquals("urn:oid:1.2.3", fhirOrg.getIdentifierFirstRep().getSystem());

fhirOrg = converter.transform(Hl7v2Based.parse("Test^^^^^^^^^1.2.3", Organization.class));
assertEquals("Test", fhirOrg.getName());
assertEquals(1, fhirOrg.getIdentifier().size());
assertEquals("urn:oid:1.2.3", fhirOrg.getIdentifierFirstRep().getValue());
assertEquals("urn:ietf:rfc:3986", fhirOrg.getIdentifierFirstRep().getSystem());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package ch.bfh.ti.i4mi.mag.mhd.iti65;

import org.hl7.fhir.r4.model.Organization;
import org.junit.jupiter.api.Test;
import org.openehealth.ipf.commons.ihe.xds.core.metadata.Hl7v2Based;

import static org.junit.jupiter.api.Assertions.*;

/**
* Tests for {@link Iti65RequestConverter}.
*
* @author Quentin Ligier
**/
class Iti65RequestConverterTest {

@Test
void testTransformOrganization() {
final var iti65RequestConverter = new Iti65RequestConverter();

final var org = new Organization();
org.setName("Test");
org.addIdentifier().setValue("1234");

var xon = iti65RequestConverter.transform(org);
assertEquals("Test^^^^^^^^^1234", Hl7v2Based.render(xon));

org.getIdentifierFirstRep().setSystem("urn:oid:1.2.3");
xon = iti65RequestConverter.transform(org);
assertEquals("Test^^^^^&1.2.3&ISO^^^^1234", Hl7v2Based.render(xon));

org.getIdentifierFirstRep().setValue("urn:oid:1.2.3").setSystem("urn:ietf:rfc:3986");
xon = iti65RequestConverter.transform(org);
assertEquals("Test^^^^^^^^^1.2.3", Hl7v2Based.render(xon));
}
}

0 comments on commit 217b4d7

Please sign in to comment.