Skip to content

Commit

Permalink
support for roles and purposes-of-use in balp oauth
Browse files Browse the repository at this point in the history
  • Loading branch information
Boris Stanojevic committed Feb 1, 2024
1 parent eb06baa commit 7220271
Show file tree
Hide file tree
Showing 16 changed files with 57 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ public class Constants {
public static final String AUDIT_ENTITY_SYSTEM_NAME = "http://terminology.hl7.org/CodeSystem/audit-entity-type";
public static final String OBJECT_ROLE_SYSTEM_NAME = "http://terminology.hl7.org/CodeSystem/object-role";
public static final String AUDIT_LIFECYCLE_SYSTEM_NAME = "http://terminology.hl7.org/CodeSystem/dicom-audit-lifecycle";
public static final String OUSER_AGENT_TYPE_SYSTEM_NAME = " http://terminology.hl7.org/CodeSystem/v3-ParticipationType";
public static final String OUSER_AGENT_TYPE_SYSTEM_NAME = "http://terminology.hl7.org/CodeSystem/v3-ParticipationType";
public static final String OUSER_AGENT_TYPE_CODE = "IRCP";
public static final String OUSER_AGENT_PURPOSE_OF_USE_SYSTEM_NAME = "http://terminology.hl7.org/CodeSystem/v3-ActReason";
public static final String OUSER_AGENT_ROLE_SYSTEM_NAME = "http://terminology.hl7.org/CodeSystem/v3-RoleClass";

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@

import static org.apache.commons.lang3.StringUtils.isNotBlank;
import static org.openehealth.ipf.commons.ihe.fhir.audit.codes.Constants.DCM_SYSTEM_NAME;
import static org.openehealth.ipf.commons.ihe.fhir.audit.codes.Constants.OUSER_AGENT_PURPOSE_OF_USE_SYSTEM_NAME;
import static org.openehealth.ipf.commons.ihe.fhir.audit.codes.Constants.OUSER_AGENT_ROLE_SYSTEM_NAME;
import static org.openehealth.ipf.commons.ihe.fhir.audit.codes.Constants.OUSER_AGENT_TYPE_SYSTEM_NAME;

public class BalpJwtUtils {
Expand All @@ -53,6 +55,16 @@ public static <D extends BaseAuditMessageBuilder<D>> void addJwtParticipant(D de
if (isNotBlank(dataSet.getIssuer())) {
ap.setAlternativeUserID(dataSet.getIssuer());
}
if (!dataSet.getIheIuaPurposeOfUse().isEmpty()) {
dataSet.getIheIuaPurposeOfUse().forEach(purpose -> ap.getRoleIDCodes().add(
ActiveParticipantRoleId.of(CodedValueType.of(purpose,
OUSER_AGENT_PURPOSE_OF_USE_SYSTEM_NAME, ""))));
}
if (!dataSet.getIheIuaSubjectRole().isEmpty()) {
dataSet.getIheIuaSubjectRole().forEach(role -> ap.getRoleIDCodes().add(
ActiveParticipantRoleId.of(CodedValueType.of(role,
OUSER_AGENT_ROLE_SYSTEM_NAME, ""))));
}
delegate.addActiveParticipant(ap);
if (isNotBlank(dataSet.getClientId())) {
ActiveParticipantType clientAp = new ActiveParticipantType(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ TlsParameters setupDefaultTlsParameter() {
@AfterEach
public void tearDown() {
LOG.info("FhirAuditRepository size: " + FhirAuditRepository.getAuditEvents().size() + ". Cleanup....");
FhirAuditRepository.getAuditEvents().clear();
FhirAuditRepository.clearAuditEvents();
LOG.info("FhirAuditRepository size: " + FhirAuditRepository.getAuditEvents().size());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ public List<AuditEvent> getAuditEvents() {
return new ArrayList<>(auditEvents.values());
}

public void clearAuditEvents() {
auditEvents.clear();
}

@Read()
public AuditEvent read(@IdParam IdType theId) {
AuditEvent auditEvent = auditEvents.get(theId.getIdPart());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ public static List<AuditEvent> getAuditEvents() {
return fhirAuditServer.getAuditEvents();
}

public static void clearAuditEvents() {
fhirAuditServer.clearAuditEvents();
}

private boolean hasStartedUndertow(){
return extensionContext.getRoot().getStore(GLOBAL).get(STORE_KEY) != null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,9 @@
import java.util.List;
import java.util.Optional;
import java.util.function.Function;
import java.util.stream.Collectors;

import static org.openehealth.ipf.commons.ihe.fhir.audit.codes.Constants.AUDIT_ENTITY_SYSTEM_NAME;
import static org.openehealth.ipf.commons.ihe.fhir.audit.codes.Constants.AUDIT_LIFECYCLE_SYSTEM_NAME;
import static org.openehealth.ipf.commons.ihe.fhir.audit.codes.Constants.DCM_OCLIENT_CODE;
import static org.openehealth.ipf.commons.ihe.fhir.audit.codes.Constants.DCM_SYSTEM_NAME;
import static org.openehealth.ipf.commons.ihe.fhir.audit.codes.Constants.OBJECT_ROLE_SYSTEM_NAME;
import static org.openehealth.ipf.commons.ihe.fhir.audit.codes.Constants.OUSER_AGENT_TYPE_CODE;
import static org.openehealth.ipf.commons.ihe.fhir.audit.codes.Constants.OUSER_AGENT_TYPE_SYSTEM_NAME;
import static org.openehealth.ipf.commons.ihe.fhir.audit.codes.Constants.SECURITY_SOURCE_SYSTEM_NAME;
import static org.openehealth.ipf.commons.ihe.fhir.audit.codes.Constants.*;

/**
* @author Christian Ohr
Expand Down Expand Up @@ -139,7 +133,7 @@ protected AuditEvent.AuditEventSourceComponent auditSourceIdentificationToEventS
protected AuditEvent.AuditEventAgentComponent activeParticipantToAgent(ActiveParticipantType ap) {
Optional<String> oUser = getOAuthAttrFromKnownActiveParticipantRoleIdCode(ap.getRoleIDCodes(), OUSER_AGENT_TYPE_SYSTEM_NAME);
if (oUser.isPresent()) {
return new AuditEvent.AuditEventAgentComponent()
AuditEvent.AuditEventAgentComponent agent = new AuditEvent.AuditEventAgentComponent()
.setType(new CodeableConcept(
new Coding(OUSER_AGENT_TYPE_SYSTEM_NAME, OUSER_AGENT_TYPE_CODE, "information recipient")))
.addPolicy(oUser.get())
Expand All @@ -149,6 +143,15 @@ protected AuditEvent.AuditEventAgentComponent activeParticipantToAgent(ActivePar
.setIdentifier(new Identifier().setSystem(ap.getAlternativeUserID()).setValue(ap.getUserID()))
.setDisplay(ap.getUserName()))
.setRequestor(ap.isUserIsRequestor());
getOAuthListAttrFromKnownActiveParticipantRoleIdCode(
ap.getRoleIDCodes(), OUSER_AGENT_PURPOSE_OF_USE_SYSTEM_NAME)
.forEach(purpose -> agent.getPurposeOfUse().add(
new CodeableConcept().addCoding(new Coding(OUSER_AGENT_PURPOSE_OF_USE_SYSTEM_NAME, purpose, ""))));
getOAuthListAttrFromKnownActiveParticipantRoleIdCode(
ap.getRoleIDCodes(), OUSER_AGENT_ROLE_SYSTEM_NAME)
.forEach(purpose -> agent.getRole().add(
new CodeableConcept().addCoding(new Coding(OUSER_AGENT_ROLE_SYSTEM_NAME, purpose, ""))));
return agent;
}
Optional<String> oClient = getOAuthAttrFromKnownActiveParticipantRoleIdCode(ap.getRoleIDCodes(), DCM_SYSTEM_NAME);
if (oClient.isPresent()) {
Expand Down Expand Up @@ -177,6 +180,12 @@ private Optional<String> getOAuthAttrFromKnownActiveParticipantRoleIdCode(List<A
.map(CodedValueType::getCode);
}

private List<String> getOAuthListAttrFromKnownActiveParticipantRoleIdCode(List<ActiveParticipantRoleId> roleCodes,
String knownCodeSystem) {
return roleCodes.stream().filter(p -> p.getCodeSystemName().equals(knownCodeSystem))
.map(CodedValueType::getCode).collect(Collectors.toList());
}

protected AuditEvent.AuditEventAgentNetworkType auditEventNetworkType(NetworkAccessPointTypeCode naptc) {
try {
return naptc != null?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.openehealth.ipf.commons.ihe.fhir.audit.FhirQueryAuditStrategy;
import org.openehealth.ipf.commons.ihe.fhir.audit.codes.FhirEventTypeCode;
import org.openehealth.ipf.commons.ihe.fhir.audit.codes.FhirParticipantObjectIdTypeCode;
import org.openehealth.ipf.commons.ihe.fhir.audit.events.BalpQueryInformationBuilder;


/**
Expand All @@ -37,7 +38,7 @@ public Iti66AuditStrategy(boolean serverSide) {

@Override
public AuditMessage[] makeAuditMessage(AuditContext auditContext, FhirQueryAuditDataset auditDataset) {
return new QueryInformationBuilder<>(auditContext, auditDataset, FhirEventTypeCode.MobileDocumentManifestQuery)
return new BalpQueryInformationBuilder(auditContext, auditDataset, FhirEventTypeCode.MobileDocumentManifestQuery)
.addPatients(auditDataset.getPatientIds())
.setQueryParameters("MobileDocumentManifestQuery",
FhirParticipantObjectIdTypeCode.MobileDocumentManifestQuery,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.openehealth.ipf.commons.ihe.fhir.audit.FhirQueryAuditStrategy;
import org.openehealth.ipf.commons.ihe.fhir.audit.codes.FhirEventTypeCode;
import org.openehealth.ipf.commons.ihe.fhir.audit.codes.FhirParticipantObjectIdTypeCode;
import org.openehealth.ipf.commons.ihe.fhir.audit.events.BalpQueryInformationBuilder;

/**
* @author Christian Ohr
Expand All @@ -35,7 +36,7 @@ public Iti67AuditStrategy(boolean serverSide) {

@Override
public AuditMessage[] makeAuditMessage(AuditContext auditContext, FhirQueryAuditDataset auditDataset) {
return new QueryInformationBuilder(auditContext, auditDataset, FhirEventTypeCode.MobileDocumentReferenceQuery)
return new BalpQueryInformationBuilder(auditContext, auditDataset, FhirEventTypeCode.MobileDocumentReferenceQuery)
.addPatients(auditDataset.getPatientIds())
.setQueryParameters("MobileDocumentReferenceQuery",
FhirParticipantObjectIdTypeCode.MobileDocumentReferenceQuery,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.openehealth.ipf.commons.ihe.core.atna.AuditStrategySupport;
import org.openehealth.ipf.commons.ihe.core.atna.event.PHIExportBuilder;
import org.openehealth.ipf.commons.ihe.fhir.audit.codes.FhirEventTypeCode;
import org.openehealth.ipf.commons.ihe.fhir.audit.events.BalpPHIExportBuilder;

import java.util.Map;

Expand All @@ -45,7 +46,7 @@ public Iti68AuditDataset enrichAuditDatasetFromRequest(Iti68AuditDataset auditDa

@Override
public AuditMessage[] makeAuditMessage(AuditContext auditContext, Iti68AuditDataset auditDataset) {
PHIExportBuilder builder = new PHIExportBuilder<>(auditContext, auditDataset,
BalpPHIExportBuilder builder = new BalpPHIExportBuilder(auditContext, auditDataset,
EventActionCode.Create,
FhirEventTypeCode.MobileDocumentRetrieval)
.setPatient(auditDataset.getPatientId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.openehealth.ipf.commons.ihe.core.atna.event.PHIExportBuilder;
import org.openehealth.ipf.commons.ihe.fhir.audit.FhirAuditDataset;
import org.openehealth.ipf.commons.ihe.fhir.audit.codes.FhirEventTypeCode;
import org.openehealth.ipf.commons.ihe.fhir.audit.events.BalpPHIExportBuilder;
import org.openehealth.ipf.commons.ihe.fhir.iti68.Iti68AuditDataset;

import java.util.Map;
Expand All @@ -45,7 +46,7 @@ public FhirAuditDataset enrichAuditDatasetFromRequest(FhirAuditDataset auditData

@Override
public AuditMessage[] makeAuditMessage(AuditContext auditContext, FhirAuditDataset auditDataset) {
PHIExportBuilder builder = new PHIExportBuilder<>(auditContext, auditDataset,
BalpPHIExportBuilder builder = new BalpPHIExportBuilder(auditContext, auditDataset,
EventActionCode.Create,
FhirEventTypeCode.MobileDocumentRetrieval)
.setPatient(auditDataset.getPatientId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public static void startServer(String contextDescriptor) {

@BeforeEach
public void beforeEach() {
FhirAuditRepository.getAuditEvents().clear();
FhirAuditRepository.clearAuditEvents();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static void setUpClass() {

@BeforeEach
public void beforeEach() {
FhirAuditRepository.getAuditEvents().clear();
FhirAuditRepository.clearAuditEvents();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public static void setUpClass() {

@BeforeEach
public void beforeEach() {
FhirAuditRepository.getAuditEvents().clear();
FhirAuditRepository.clearAuditEvents();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public static void setUpClass() {

@BeforeEach
public void beforeEach() {
FhirAuditRepository.getAuditEvents().clear();
FhirAuditRepository.clearAuditEvents();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static void setUpClass() {

@BeforeEach
public void beforeEach() {
FhirAuditRepository.getAuditEvents().clear();
FhirAuditRepository.clearAuditEvents();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static void setUpClass() {

@BeforeEach
public void beforeEach() {
FhirAuditRepository.getAuditEvents().clear();
FhirAuditRepository.clearAuditEvents();
}

@Test
Expand Down

0 comments on commit 7220271

Please sign in to comment.