1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
|
/*
* This file is part of ETL-Processor
*
* Copyright (c) 2023 Comprehensive Cancer Center Mainfranken
* Copyright (c) 2026 Paul-Christian Volkmer, Datenintegrationszentrum Philipps-Universität Marburg and Contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package dev.dnpm.etl.processor.consent;
import dev.dnpm.etl.processor.config.AppFhirConfig;
import dev.dnpm.etl.processor.config.GIcsConfigProperties;
import java.net.URISyntaxException;
import java.util.Date;
import org.apache.hc.core5.net.URIBuilder;
import org.hl7.fhir.r4.model.Bundle;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.retry.TerminatedRetryException;
import org.springframework.retry.support.RetryTemplate;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;
/**
* Service to request Broad Consent only from remote gICS installation using REST/HTTP GET request
*
* @since 0.12
*/
@NullMarked
public class GicsGetBroadConsentService extends AbstractConsentService {
private final RetryTemplate retryTemplate;
private final RestTemplate restTemplate;
private final GIcsConfigProperties gIcsConfigProperties;
public GicsGetBroadConsentService(
GIcsConfigProperties gIcsConfigProperties,
RetryTemplate retryTemplate,
RestTemplate restTemplate,
AppFhirConfig appFhirConfig) {
super(appFhirConfig.fhirContext(), LoggerFactory.getLogger(GicsGetBroadConsentService.class));
this.retryTemplate = retryTemplate;
this.restTemplate = restTemplate;
this.gIcsConfigProperties = gIcsConfigProperties;
if (null == this.gIcsConfigProperties.getUri()) {
throw new IllegalStateException("Missing gICS URI configuration");
}
log.info("GicsGetBroadConsentService initialized...");
}
@Override
public TtpConsentStatus getTtpBroadConsentStatus(String personIdentifierValue) {
var consentStatusResponse =
requestResponse(
personIdentifierValue, this.gIcsConfigProperties.getBroadConsentDomainName());
return evaluateConsentResponse(consentStatusResponse);
}
@Override
public Bundle getConsent(
String personIdentifierValue, Date requestDate, ConsentDomain consentDomain) {
return fhirContext
.newJsonParser()
.parseResource(
Bundle.class,
requestResponse(
personIdentifierValue, gIcsConfigProperties.getBroadConsentDomainName()));
}
@Nullable
private String requestResponse(String personIdentifierValue, String consentDomain) {
if (null == this.gIcsConfigProperties.getUri()) {
throw new IllegalStateException("Missing gICS URI configuration");
}
final var patientIdentifierQueryValue =
"%s|%s"
.formatted(
this.gIcsConfigProperties.getPersonIdentifierSystem(), personIdentifierValue);
try {
final var uri =
new URIBuilder(gIcsConfigProperties.getUri())
.appendPathSegments("Consent")
.addParameter("domain:identifier", consentDomain)
.addParameter(
"category",
"http://fhir.de/ConsentManagement/CodeSystem/ResultType|consent-status")
.addParameter("patient.identifier", patientIdentifierQueryValue)
.build();
final var requestHeaders = new HttpHeaders();
if (null != gIcsConfigProperties.getUsername()
&& null != gIcsConfigProperties.getPassword()
&& !gIcsConfigProperties.getUsername().isBlank()
&& !gIcsConfigProperties.getPassword().isBlank()) {
requestHeaders.setBasicAuth(
gIcsConfigProperties.getUsername(), gIcsConfigProperties.getPassword());
}
final var response =
this.retryTemplate.execute(
retryContext ->
this.restTemplate.exchange(
uri, HttpMethod.GET, new HttpEntity<>(requestHeaders), String.class));
if (response.getStatusCode().is2xxSuccessful()) {
return response.getBody();
} else {
var msg =
String.format(
"Trusted party system reached but request failed! code: '%s' response: '%s'",
response.getStatusCode(), response.getBody());
log.error(msg);
return null;
}
} catch (RestClientException e) {
var msg = String.format("Get consents status request failed reason: '%s", e.getMessage());
log.error(msg);
return null;
} catch (TerminatedRetryException terminatedRetryException) {
var msg =
String.format(
"Get consents status process has been terminated. termination reason: '%s",
terminatedRetryException.getMessage());
log.error(msg);
return null;
} catch (URISyntaxException e) {
var msg = String.format("Invalid URI for consents status request: '%s", e.getMessage());
log.error(msg);
return null;
}
}
@Override
protected TtpConsentStatus evaluateConsentResponse(@Nullable String consentStatusResponse) {
return MiiBroadConsentEvaluator.evaluate(this.fhirContext, consentStatusResponse);
}
}
|