Skip to content

Commit

Permalink
utility classes for CH:ADR; small refactorings
Browse files Browse the repository at this point in the history
  • Loading branch information
unixoid committed Mar 2, 2025
1 parent 78fffdb commit 6f4f8da
Show file tree
Hide file tree
Showing 23 changed files with 191 additions and 147 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ import org.hl7.fhir.r4.model.OperationOutcome
import org.openehealth.ipf.commons.ihe.fhir.chppqm.ChPpqmUtils
import org.openehealth.ipf.commons.ihe.xacml20.Xacml20Status
import org.openehealth.ipf.commons.ihe.xacml20.Xacml20Utils
import org.openehealth.ipf.commons.ihe.xacml20.model.PpqConstants
import org.openehealth.ipf.commons.ihe.xacml20.model.EprConstants.CodingSystemIds
import org.openehealth.ipf.commons.ihe.xacml20.model.EprConstants.StatusCode
import org.openehealth.ipf.commons.ihe.xacml20.stub.UnknownPolicySetIdFaultMessage
import org.openehealth.ipf.commons.ihe.xacml20.stub.ehealthswiss.AddPolicyRequest
import org.openehealth.ipf.commons.ihe.xacml20.stub.ehealthswiss.AssertionBasedRequestType
Expand Down Expand Up @@ -75,11 +76,11 @@ class XacmlToFhirTranslator {
for (subjectMatch in subjectMatches) {
def cv = subjectMatch.AttributeValue.CodedValue

if ((cv.@codeSystem.text() == PpqConstants.CodingSystemIds.SWISS_PURPOSE_OF_USE) && (cv.@code.text() == 'EMER')) {
if ((cv.@codeSystem.text() == CodingSystemIds.SWISS_PURPOSE_OF_USE) && (cv.@code.text() == 'EMER')) {
return create202Consent(id, eprSpid, policyIdReference)
}

if (cv.@codeSystem.text() == PpqConstants.CodingSystemIds.SWISS_SUBJECT_ROLE) {
if (cv.@codeSystem.text() == CodingSystemIds.SWISS_SUBJECT_ROLE) {
if (cv.@code.text() == 'PAT') {
return create201Consent(id, eprSpid)
}
Expand Down Expand Up @@ -140,7 +141,7 @@ class XacmlToFhirTranslator {
AssertionBasedRequestType ppq1Request,
EprPolicyRepositoryResponse ppq1Response)
{
if (ppq1Response.status == PpqConstants.StatusCode.SUCCESS) {
if (ppq1Response.status == StatusCode.SUCCESS) {
return new MethodOutcome(
id: new IdType(UUID.randomUUID().toString()),
responseStatusCode: (ppq1Request instanceof AddPolicyRequest) ? 201 : 200,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import org.hl7.fhir.r4.model.codesystems.ConsentScope;
import org.hl7.fhir.r4.model.codesystems.V3ActCode;
import org.openehealth.ipf.commons.ihe.fhir.Constants;
import org.openehealth.ipf.commons.ihe.xacml20.model.PpqConstants;
import org.openehealth.ipf.commons.ihe.xacml20.model.EprConstants.CodingSystemIds;
import org.openehealth.ipf.commons.ihe.xacml20.model.PurposeOfUse;
import org.openehealth.ipf.commons.ihe.xacml20.model.SubjectRole;

Expand Down Expand Up @@ -66,7 +66,7 @@ private static Consent createConsent(
V3ActCode.INFA.toCode(),
V3ActCode.INFA.getDisplay())))
.setPatient(new Reference().setIdentifier(new Identifier()
.setSystem("urn:oid:" + PpqConstants.CodingSystemIds.SWISS_PATIENT_ID)
.setSystem("urn:oid:" + CodingSystemIds.SWISS_PATIENT_ID)
.setValue(eprSpid)))
.setPolicyRule(new CodeableConcept(new Coding()
.setSystem(Constants.URN_IETF_RFC_3986)
Expand Down Expand Up @@ -139,7 +139,7 @@ public static Consent create201Consent(String id, String eprSpid) {
"201",
eprSpid,
"urn:e-health-suisse:2015:policies:access-level:full",
createInstanceActor(SubjectRole.PATIENT, "urn:e-health-suisse:2015:epr-spid", eprSpid, "urn:oid:" + PpqConstants.CodingSystemIds.SWISS_PATIENT_ID),
createInstanceActor(SubjectRole.PATIENT, "urn:e-health-suisse:2015:epr-spid", eprSpid, "urn:oid:" + CodingSystemIds.SWISS_PATIENT_ID),
null,
null,
Collections.emptyList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
import org.openehealth.ipf.commons.ihe.fhir.chppqm.translation.XacmlToFhirTranslator;
import org.openehealth.ipf.commons.ihe.xacml20.*;
import org.openehealth.ipf.commons.ihe.xacml20.chppq.ChPpqMessageCreator;
import org.openehealth.ipf.commons.ihe.xacml20.model.PpqConstants;
import org.openehealth.ipf.commons.ihe.xacml20.model.EprConstants.CodingSystemIds;
import org.openehealth.ipf.commons.ihe.xacml20.model.EprConstants.StatusCode;
import org.openehealth.ipf.commons.ihe.xacml20.stub.ehealthswiss.AddPolicyRequest;
import org.openehealth.ipf.commons.ihe.xacml20.stub.ehealthswiss.DeletePolicyRequest;
import org.openehealth.ipf.commons.ihe.xacml20.stub.ehealthswiss.EprPolicyRepositoryResponse;
Expand Down Expand Up @@ -175,7 +176,7 @@ public void testPpq1To3ResponseTranslation() {
AddPolicyRequest addRequest = PPQ_MESSAGE_CREATOR.createAddPolicyRequest(Collections.singletonList(policySet));

EprPolicyRepositoryResponse ppq1Response = new EprPolicyRepositoryResponse();
ppq1Response.setStatus(PpqConstants.StatusCode.SUCCESS);
ppq1Response.setStatus(StatusCode.SUCCESS);
MethodOutcome methodOutcome = XacmlToFhirTranslator.translatePpq1To3Response(consent, addRequest, ppq1Response);

log.info("");
Expand Down Expand Up @@ -229,7 +230,7 @@ public void testPpq1To4ResponseTranslation() {
Bundle ppq4Request = ChPpqmUtils.createPpq4SubmitRequestBundle(consents, Bundle.HTTPVerb.POST);
AddPolicyRequest ppq1Request = FHIR_TO_XACML_TRANSLATOR.translatePpq4To1Request(ppq4Request);
EprPolicyRepositoryResponse ppq1Response = new EprPolicyRepositoryResponse();
ppq1Response.setStatus(PpqConstants.StatusCode.SUCCESS);
ppq1Response.setStatus(StatusCode.SUCCESS);
Bundle ppq4Response = XacmlToFhirTranslator.translatePpq1To4Response(ppq4Request, ppq1Request, ppq1Response);
new ChPpq4Validator(ChPpqmUtils.FHIR_CONTEXT).validateResponse(ppq4Response, null);
log.info("");
Expand All @@ -243,7 +244,7 @@ public void testPpq5To2RequestTranslation() {

XACMLPolicyQueryType ppq2Request2 = FHIR_TO_XACML_TRANSLATOR.translatePpq5To2Request(
Consent.SP_PATIENT + ':' + Patient.SP_IDENTIFIER + '=' +
PpqConstants.CodingSystemIds.SWISS_PATIENT_ID + "|123456789012345678");
CodingSystemIds.SWISS_PATIENT_ID + "|123456789012345678");
Xacml20MessageValidator.validateChPpq2Request(ppq2Request2);

log.info("");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package org.openehealth.ipf.commons.ihe.xacml20
import org.apache.commons.lang3.Validate
import org.herasaf.xacml.core.context.impl.ObjectFactory as XacmlContextObjectFactory
import org.herasaf.xacml.core.policy.impl.ObjectFactory as XacmlPolicyObjectFactory
import org.openehealth.ipf.commons.ihe.xacml20.model.PpqConstants
import org.openehealth.ipf.commons.ihe.xacml20.model.EprConstants
import org.openehealth.ipf.commons.ihe.xacml20.stub.hl7v3.ObjectFactory as Hl7v3ObjectFactory
import org.openehealth.ipf.commons.ihe.xacml20.stub.saml20.assertion.AssertionType
import org.openehealth.ipf.commons.ihe.xacml20.stub.saml20.assertion.NameIDType
Expand Down Expand Up @@ -47,7 +47,7 @@ class Xacml20MessageCreator {

NameIDType createIssuer() {
return new NameIDType(
nameQualifier: PpqConstants.NAME_QUALIFIER_EHEALTH_SUISSSE_COMMUNITY_INDEX,
nameQualifier: EprConstants.NAME_QUALIFIER_EHEALTH_SUISSSE_COMMUNITY_INDEX,
value: homeCommunityId,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import org.openehealth.ipf.commons.ihe.xacml20.stub.saml20.protocol.ResponseType
import org.openehealth.ipf.commons.ihe.xacml20.stub.xacml20.saml.assertion.XACMLAuthzDecisionStatementType
import org.openehealth.ipf.commons.ihe.xacml20.stub.xacml20.saml.protocol.XACMLAuthzDecisionQueryType

import static org.openehealth.ipf.commons.ihe.xacml20.model.PpqConstants.AttributeIds
import static org.openehealth.ipf.commons.ihe.xacml20.model.EprConstants.AttributeIds

@CompileStatic
class AdrMessageCreator extends Xacml20MessageCreator {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import groovy.transform.CompileStatic
import org.herasaf.xacml.core.context.impl.ResourceType
import org.herasaf.xacml.core.dataTypeAttribute.impl.AnyURIDataTypeAttribute
import org.openehealth.ipf.commons.ihe.xacml20.herasaf.types.IiDataTypeAttribute
import org.openehealth.ipf.commons.ihe.xacml20.model.PpqConstants
import org.openehealth.ipf.commons.ihe.xacml20.model.EprConstants.AttributeIds

import static org.openehealth.ipf.commons.ihe.xacml20.chadr.AdrUtils.toIi

Expand All @@ -35,8 +35,8 @@ class AdrResourceAtcAttributes extends AdrAttributes<ResourceType> {
@Override
List<ResourceType> createAdrRequestParts() {
def result = new ResourceType()
add(result.attributes, PpqConstants.AttributeIds.XACML_1_0_RESOURCE_ID, new AnyURIDataTypeAttribute(), "urn:e-health-suisse:2015:epr-subset:${eprSpid}:patient-audit-trail-records".toString())
add(result.attributes, PpqConstants.AttributeIds.EHEALTH_SUISSSE_2015_EPR_SPID, new IiDataTypeAttribute(), toIi(eprSpid))
add(result.attributes, AttributeIds.XACML_1_0_RESOURCE_ID, new AnyURIDataTypeAttribute(), "urn:e-health-suisse:2015:epr-subset:${eprSpid}:patient-audit-trail-records".toString())
add(result.attributes, AttributeIds.EHEALTH_SUISSSE_2015_EPR_SPID, new IiDataTypeAttribute(), toIi(eprSpid))
return [result]
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import org.herasaf.xacml.core.context.impl.ResourceType
import org.herasaf.xacml.core.dataTypeAttribute.impl.AnyURIDataTypeAttribute
import org.herasaf.xacml.core.dataTypeAttribute.impl.DateDataTypeAttribute
import org.openehealth.ipf.commons.ihe.xacml20.herasaf.types.IiDataTypeAttribute
import org.openehealth.ipf.commons.ihe.xacml20.model.PpqConstants
import org.openehealth.ipf.commons.ihe.xacml20.model.EprConstants.AttributeIds

import java.time.LocalDate

Expand Down Expand Up @@ -49,11 +49,11 @@ class AdrResourcePpqAttributes extends AdrAttributes<ResourceType> {
@Override
List<ResourceType> createAdrRequestParts() {
def result = new ResourceType()
add(result.attributes, PpqConstants.AttributeIds.XACML_1_0_RESOURCE_ID, new AnyURIDataTypeAttribute(), policySetId)
add(result.attributes, PpqConstants.AttributeIds.EHEALTH_SUISSSE_2015_EPR_SPID, new IiDataTypeAttribute(), toIi(eprSpid))
add(result.attributes, PpqConstants.AttributeIds.EHEALTH_SUISSSE_2015_REFERENCED_POLICY_SET, new AnyURIDataTypeAttribute(), referencedPolicySet)
add(result.attributes, PpqConstants.AttributeIds.EHEALTH_SUISSSE_START_DATE, new DateDataTypeAttribute(), fromDate)
add(result.attributes, PpqConstants.AttributeIds.EHEALTH_SUISSSE_END_DATE, new DateDataTypeAttribute(), toDate)
add(result.attributes, AttributeIds.XACML_1_0_RESOURCE_ID, new AnyURIDataTypeAttribute(), policySetId)
add(result.attributes, AttributeIds.EHEALTH_SUISSSE_2015_EPR_SPID, new IiDataTypeAttribute(), toIi(eprSpid))
add(result.attributes, AttributeIds.EHEALTH_SUISSSE_2015_REFERENCED_POLICY_SET, new AnyURIDataTypeAttribute(), referencedPolicySet)
add(result.attributes, AttributeIds.EHEALTH_SUISSSE_START_DATE, new DateDataTypeAttribute(), fromDate)
add(result.attributes, AttributeIds.EHEALTH_SUISSSE_END_DATE, new DateDataTypeAttribute(), toDate)
return [result]
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import org.herasaf.xacml.core.context.impl.ResourceType
import org.herasaf.xacml.core.dataTypeAttribute.impl.AnyURIDataTypeAttribute
import org.openehealth.ipf.commons.ihe.xacml20.herasaf.types.CvDataTypeAttribute
import org.openehealth.ipf.commons.ihe.xacml20.herasaf.types.IiDataTypeAttribute
import org.openehealth.ipf.commons.ihe.xacml20.model.PpqConstants
import org.openehealth.ipf.commons.ihe.xacml20.model.EprConstants.AttributeIds

import static org.openehealth.ipf.commons.ihe.xacml20.chadr.AdrUtils.toCv
import static org.openehealth.ipf.commons.ihe.xacml20.chadr.AdrUtils.toIi
Expand All @@ -40,10 +40,10 @@ class AdrResourceXdsAttributes extends AdrAttributes<ResourceType> {
List<ResourceType> createAdrRequestParts() {
return ConfidentialityCode.values().collect { confCode ->
def result = new ResourceType()
add(result.attributes, PpqConstants.AttributeIds.XACML_1_0_RESOURCE_ID, new AnyURIDataTypeAttribute(), "urn:e-health-suisse:2015:epr-subset:${eprSpid}:${confCode.name().toLowerCase()}".toString())
add(result.attributes, PpqConstants.AttributeIds.EHEALTH_SUISSSE_2015_EPR_SPID, new IiDataTypeAttribute(), toIi(eprSpid))
add(result.attributes, PpqConstants.AttributeIds.XDS_2007_CONFIDENTIALITY_CODE, new CvDataTypeAttribute(), toCv(confCode.code))
add(result.attributes, PpqConstants.AttributeIds.XCA_2010_HOME_COMMUNITY_ID, new AnyURIDataTypeAttribute(), homeCommunityId)
add(result.attributes, AttributeIds.XACML_1_0_RESOURCE_ID, new AnyURIDataTypeAttribute(), "urn:e-health-suisse:2015:epr-subset:${eprSpid}:${confCode.name().toLowerCase()}".toString())
add(result.attributes, AttributeIds.EHEALTH_SUISSSE_2015_EPR_SPID, new IiDataTypeAttribute(), toIi(eprSpid))
add(result.attributes, AttributeIds.XDS_2007_CONFIDENTIALITY_CODE, new CvDataTypeAttribute(), toCv(confCode.code))
add(result.attributes, AttributeIds.XCA_2010_HOME_COMMUNITY_ID, new AnyURIDataTypeAttribute(), homeCommunityId)
return result
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import org.herasaf.xacml.core.dataTypeAttribute.impl.AnyURIDataTypeAttribute
import org.herasaf.xacml.core.dataTypeAttribute.impl.StringDataTypeAttribute
import org.openehealth.ipf.commons.ihe.xacml20.herasaf.types.CvDataTypeAttribute
import org.openehealth.ipf.commons.ihe.xacml20.model.NameQualifier
import org.openehealth.ipf.commons.ihe.xacml20.model.PpqConstants
import org.openehealth.ipf.commons.ihe.xacml20.model.EprConstants.AttributeIds
import org.openehealth.ipf.commons.ihe.xacml20.model.PurposeOfUse
import org.openehealth.ipf.commons.ihe.xacml20.model.SubjectRole

Expand Down Expand Up @@ -49,14 +49,14 @@ class AdrSubjectAttributes extends AdrAttributes<SubjectType> {
@Override
List<SubjectType> createAdrRequestParts() {
def result = new SubjectType()
add(result.attributes, PpqConstants.AttributeIds.XACML_1_0_SUBJECT_ID, new StringDataTypeAttribute(), subjectId)
add(result.attributes, PpqConstants.AttributeIds.XACML_1_0_SUBJECT_ID_QUALIFIER, new StringDataTypeAttribute(), subjectIdQualifier.qualifier)
add(result.attributes, PpqConstants.AttributeIds.XCA_2010_HOME_COMMUNITY_ID, new AnyURIDataTypeAttribute(), homeCommunityId)
add(result.attributes, PpqConstants.AttributeIds.XACML_2_0_SUBJECT_ROLE, new CvDataTypeAttribute(), toCv(subjectRole.code))
add(result.attributes, AttributeIds.XACML_1_0_SUBJECT_ID, new StringDataTypeAttribute(), subjectId)
add(result.attributes, AttributeIds.XACML_1_0_SUBJECT_ID_QUALIFIER, new StringDataTypeAttribute(), subjectIdQualifier.qualifier)
add(result.attributes, AttributeIds.XCA_2010_HOME_COMMUNITY_ID, new AnyURIDataTypeAttribute(), homeCommunityId)
add(result.attributes, AttributeIds.XACML_2_0_SUBJECT_ROLE, new CvDataTypeAttribute(), toCv(subjectRole.code))
organizationOids?.forEach { orgOid ->
add(result.attributes, PpqConstants.AttributeIds.XSPA_1_0_SUBJECT_ORGANIZATION_ID, new AnyURIDataTypeAttribute(), orgOid)
add(result.attributes, AttributeIds.XSPA_1_0_SUBJECT_ORGANIZATION_ID, new AnyURIDataTypeAttribute(), orgOid)
}
add(result.attributes, PpqConstants.AttributeIds.XSPA_1_0_SUBJECT_PURPOSE_OF_USE, new CvDataTypeAttribute(), toCv(purposeOfUse.code))
add(result.attributes, AttributeIds.XSPA_1_0_SUBJECT_PURPOSE_OF_USE, new CvDataTypeAttribute(), toCv(purposeOfUse.code))
return [result]
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import jakarta.xml.bind.JAXBElement
import org.herasaf.xacml.core.context.impl.*
import org.herasaf.xacml.core.dataTypeAttribute.DataTypeAttribute
import org.openehealth.ipf.commons.ihe.xacml20.model.CE
import org.openehealth.ipf.commons.ihe.xacml20.model.PpqConstants
import org.openehealth.ipf.commons.ihe.xacml20.model.EprConstants.AttributeIds
import org.openehealth.ipf.commons.ihe.xacml20.model.EprConstants.CodingSystemIds
import org.openehealth.ipf.commons.ihe.xacml20.stub.hl7v3.CV
import org.openehealth.ipf.commons.ihe.xacml20.stub.hl7v3.II
import org.openehealth.ipf.commons.ihe.xacml20.stub.hl7v3.ObjectFactory
Expand Down Expand Up @@ -61,19 +62,25 @@ class AdrUtils {
}

static JAXBElement<II> toIi(String eprSpid) {
def ii = new II(extension: eprSpid, root: PpqConstants.CodingSystemIds.SWISS_PATIENT_ID)
def ii = new II(extension: eprSpid, root: CodingSystemIds.SWISS_PATIENT_ID)
return HL7V3_OBJECT_FACTORY.createInstanceIdentifier(ii)
}

static String extractEprSpid(RequestType request) {
return request.resources[0].attributes.stream()
.filter(attr -> attr.attributeId == PpqConstants.AttributeIds.EHEALTH_SUISSSE_2015_EPR_SPID)
.findAny()
.map(attr -> {
def jaxbElement = attr.attributeValues[0].content[0] as JAXBElement<II>
return jaxbElement.value.extension
})
.orElseThrow(() -> new IllegalArgumentException('Cannot extract EPR-SPID from ADR request'))
for (resource in request.resources) {
for (attr in resource.attributes) {
if (attr.attributeId == AttributeIds.EHEALTH_SUISSSE_2015_EPR_SPID) {
for (value in attr.attributeValues) {
for (content in value.content) {
if (content instanceof JAXBElement<II>) {
return content.value.extension
}
}
}
}
}
}
throw new IllegalArgumentException('Cannot extract EPR-SPID from ADR request')
}

static ResultType createNotHolderOfPatientPoliciesResult() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import org.herasaf.xacml.core.policy.impl.PolicySetType
import org.openehealth.ipf.commons.ihe.xacml20.Xacml20MessageCreator
import org.openehealth.ipf.commons.ihe.xacml20.Xacml20Status
import org.openehealth.ipf.commons.ihe.xacml20.herasaf.types.IiDataTypeAttribute
import org.openehealth.ipf.commons.ihe.xacml20.model.PpqConstants
import org.openehealth.ipf.commons.ihe.xacml20.model.EprConstants.AttributeIds
import org.openehealth.ipf.commons.ihe.xacml20.stub.ehealthswiss.AddPolicyRequest
import org.openehealth.ipf.commons.ihe.xacml20.stub.ehealthswiss.DeletePolicyRequest
import org.openehealth.ipf.commons.ihe.xacml20.stub.ehealthswiss.UpdatePolicyRequest
Expand Down Expand Up @@ -88,7 +88,7 @@ class ChPpqMessageCreator extends Xacml20MessageCreator {
new ResourceType(
attributes: [
new AttributeType(
attributeId: PpqConstants.AttributeIds.EHEALTH_SUISSSE_2015_EPR_SPID,
attributeId: AttributeIds.EHEALTH_SUISSSE_2015_EPR_SPID,
dataType: new IiDataTypeAttribute(),
attributeValues: [
new AttributeValueType(
Expand Down
Loading

0 comments on commit 6f4f8da

Please sign in to comment.