Skip to content

Commit

Permalink
BALP: support for patientId and organizationId + fix for XdsHl7v2Rend…
Browse files Browse the repository at this point in the history
…eringTest
  • Loading branch information
Boris Stanojevic committed Feb 20, 2024
1 parent 7fd09f5 commit 0d3c387
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.openehealth.ipf.commons.ihe.fhir.audit.auth.BalpJwtDataSet;
import org.openehealth.ipf.commons.ihe.fhir.audit.auth.BalpJwtParser;

import java.util.Collections;
import java.util.Optional;

import static org.apache.commons.lang3.StringUtils.isNotBlank;
Expand All @@ -48,6 +49,21 @@ public static <D extends BaseAuditMessageBuilder<D>> void addJwtParticipant(D de
Optional<BalpJwtDataSet> balpDataSet = BalpJwtParser.parseAuthorizationToBalpDataSet(
auditDataset.getAuthorization(), balpJwtExtractorProperties);
balpDataSet.ifPresent(dataSet -> {
if (isNotBlank(dataSet.getIheBppcPatientId())) {
delegate.addPatientParticipantObject(
dataSet.getIheBppcPatientId(),
"oAuth Token Patient ID",
Collections.emptyList(),
null);
}
if (isNotBlank(dataSet.getIheIuaSubjectOrganizationId())) {
ActiveParticipantType ap = new ActiveParticipantType(dataSet.getIheIuaSubjectOrganizationId(), true);
ap.setUserName(dataSet.getIheIuaSubjectOrganization());
ap.getRoleIDCodes().add(
ActiveParticipantRoleId.of(CodedValueType.of(dataSet.getIheIuaSubjectOrganizationId(),
DCM_SYSTEM_NAME, "oAuth Token Subject Organization ID")));
delegate.addActiveParticipant(ap);
}
if (isNotBlank(dataSet.getJwtId())) {
ActiveParticipantType ap = new ActiveParticipantType(dataSet.getSubject(), true);
ap.getRoleIDCodes().add(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import java.util.function.Function;
import java.util.stream.Collectors;

import static org.apache.commons.lang3.StringUtils.isNotBlank;
import static org.openehealth.ipf.commons.ihe.fhir.audit.codes.Constants.*;

/**
Expand Down Expand Up @@ -114,8 +115,15 @@ protected AuditEvent.AuditEventEntityComponent participantObjectIdentificationTo
entity.addDetail(new AuditEvent.AuditEventEntityDetailComponent()
.setType(tvp.getType())
.setValue(new Base64BinaryType(tvp.getValue()))));
if (poit.getParticipantObjectTypeCodeRole() == ParticipantObjectTypeCodeRole.Patient) {
entity.setWhat(new Reference(poit.getParticipantObjectID()));
if (poit.getParticipantObjectTypeCodeRole() == ParticipantObjectTypeCodeRole.Patient &&
isNotBlank(poit.getParticipantObjectID())) {
Reference patReference = new Reference(poit.getParticipantObjectID());
if (patReference.getReferenceElement().hasResourceType()) {
entity.setWhat(new Reference(poit.getParticipantObjectID()));
} else {
entity.setWhat(new Reference().setIdentifier(
new Identifier().setValue(poit.getParticipantObjectID())));
}
}
return entity;
}
Expand All @@ -130,6 +138,20 @@ protected AuditEvent.AuditEventSourceComponent auditSourceIdentificationToEventS
}

protected AuditEvent.AuditEventAgentComponent activeParticipantToAgent(ActiveParticipantType ap) {
Optional<AuditEvent.AuditEventAgentComponent> oAuthEventAgent = oAuthActiveParticipantToAgent(ap);
return oAuthEventAgent.orElseGet(() -> new AuditEvent.AuditEventAgentComponent()
.setType(ap.getRoleIDCodes().isEmpty() ? null : codedValueTypeToCodeableConcept(ap.getRoleIDCodes().get(0), DCM_SYSTEM_NAME))
.setWho(new Reference().setDisplay(ap.getUserID()))
.setAltId(ap.getAlternativeUserID())
.setName(ap.getUserName())
.setRequestor(ap.isUserIsRequestor())
.setMedia(codedValueTypeToCoding(ap.getMediaType()))
.setNetwork(new AuditEvent.AuditEventAgentNetworkComponent()
.setAddress(ap.getNetworkAccessPointID())
.setType(auditEventNetworkType(ap.getNetworkAccessPointTypeCode()))));
}

private Optional<AuditEvent.AuditEventAgentComponent> oAuthActiveParticipantToAgent(ActiveParticipantType ap) {
Optional<String> oUser = getOAuthAttrFromKnownRoleIdCode(ap.getRoleIDCodes(), OUSER_AGENT_TYPE_SYSTEM_NAME);
if (oUser.isPresent()) {
AuditEvent.AuditEventAgentComponent agent = new AuditEvent.AuditEventAgentComponent()
Expand All @@ -147,33 +169,25 @@ protected AuditEvent.AuditEventAgentComponent activeParticipantToAgent(ActivePar
getOAuthListAttrFromKnownRoleIdCode(ap.getRoleIDCodes(), OUSER_AGENT_ROLE_SYSTEM_NAME)
.forEach(purpose -> agent.getRole().add(
systemAndCodeToCodeableConcept(OUSER_AGENT_ROLE_SYSTEM_NAME, purpose, "")));
return agent;
return Optional.of(agent);
}
Optional<String> oClient = getOAuthAttrFromKnownRoleIdCode(ap.getRoleIDCodes(), DCM_SYSTEM_NAME);
if (oClient.isPresent()) {
return new AuditEvent.AuditEventAgentComponent()
return Optional.of(new AuditEvent.AuditEventAgentComponent()
.setType(systemAndCodeToCodeableConcept(DCM_SYSTEM_NAME, DCM_OCLIENT_CODE, "Application"))
.setRequestor(ap.isUserIsRequestor())
.setWho(new Reference().setIdentifier(new Identifier().setValue(oClient.get())));
.setWho(new Reference().setIdentifier(
new Identifier().setValue(oClient.get())).setDisplay(ap.getUserName())));
}
Optional<String> opaqueToken = getOAuthAttrFromKnownRoleIdCode(ap.getRoleIDCodes(),
OUSER_AGENT_TYPE_OPAQUE_SYSTEM_NAME);
if (opaqueToken.isPresent()) {
return new AuditEvent.AuditEventAgentComponent()
return Optional.of(new AuditEvent.AuditEventAgentComponent()
.setType(new CodeableConcept(
new Coding(OUSER_AGENT_TYPE_OPAQUE_SYSTEM_NAME, OUSER_AGENT_TYPE_OPAQUE_CODE, "")))
.setRequestor(true);
.setRequestor(true));
}
return new AuditEvent.AuditEventAgentComponent()
.setType(codedValueTypeToCodeableConcept(ap.getRoleIDCodes().get(0), DCM_SYSTEM_NAME))
.setWho(new Reference().setDisplay(ap.getUserID()))
.setAltId(ap.getAlternativeUserID())
.setName(ap.getUserName())
.setRequestor(ap.isUserIsRequestor())
.setMedia(codedValueTypeToCoding(ap.getMediaType()))
.setNetwork(new AuditEvent.AuditEventAgentNetworkComponent()
.setAddress(ap.getNetworkAccessPointID())
.setType(auditEventNetworkType(ap.getNetworkAccessPointTypeCode())));
return Optional.empty();
}

private Optional<String> getOAuthAttrFromKnownRoleIdCode(List<ActiveParticipantRoleId> roleCodes,
Expand Down
5 changes: 5 additions & 0 deletions commons/ihe/xds/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.java.quickcheck</groupId>
<artifactId>quickcheck</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<profiles>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package org.openehealth.ipf.commons.ihe.xds.core.transform.hl7;

import net.java.quickcheck.generator.PrimitiveGenerators;
import org.junit.jupiter.api.Test;
import org.openehealth.ipf.commons.ihe.xds.core.metadata.*;

Expand Down Expand Up @@ -61,25 +62,19 @@ public void testIdentifiableRendering() {

@Test
public void testReferenceIdRendering() {
var cx1 = "1^2^3^41&42&43&44&45&46^51&52^^^&&^^";
var referenceId1 = Hl7v2Based.parse(cx1, ReferenceId.class);
assertEquals("1^^^41&42&43^51", Hl7v2Based.render(referenceId1));
var cx2 = "1^2^3^41&42&43&44&45&46^51&52^&1.2.40.0.34.3.1.2.99.1000001&ISO^2015^&&^^";
var referenceId2 = Hl7v2Based.parse(cx2, ReferenceId.class);
assertEquals("1^^^41&42&43^51", Hl7v2Based.render(referenceId2));
assertEquals("1^2^3^41&42&43&44&45&46^51&52^&1.2.40.0.34.3.1.2.99.1000001&ISO^2015", Hl7v2Based.rawRender(referenceId2));
}

@Test
public void testReferenceIdRenderingCp1292() {
System.setProperty("XDS_VALIDATION_CP_1292", "true");
Boolean cp1292Enabled = PrimitiveGenerators.booleans().next();
System.setProperty("XDS_VALIDATION_CP_1292", cp1292Enabled.toString());
try {
var cx1 = "1^2^3^41&42&43&44&45&46^51&52^^^&&^^";
var referenceId1 = Hl7v2Based.parse(cx1, ReferenceId.class);
assertEquals("1^^^41&42&43^51", Hl7v2Based.render(referenceId1));
var cx2 = "1^2^3^41&42&43&44&45&46^51&52^&1.2.40.0.34.3.1.2.99.1000001&ISO^2015^&&^^";
var referenceId2 = Hl7v2Based.parse(cx2, ReferenceId.class);
assertEquals("1^^^41&42&43^51^&1.2.40.0.34.3.1.2.99.1000001&ISO", Hl7v2Based.render(referenceId2));
if (cp1292Enabled) {
assertEquals("1^^^41&42&43^51^&1.2.40.0.34.3.1.2.99.1000001&ISO", Hl7v2Based.render(referenceId2));
} else {
assertEquals("1^^^41&42&43^51", Hl7v2Based.render(referenceId2));
}
assertEquals("1^2^3^41&42&43&44&45&46^51&52^&1.2.40.0.34.3.1.2.99.1000001&ISO^2015", Hl7v2Based.rawRender(referenceId2));
} finally {
System.clearProperty("XDS_VALIDATION_CP_1292");
Expand Down

0 comments on commit 0d3c387

Please sign in to comment.