Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor endpoint string creation and add hppClientPolicy bean to con… #130

Merged
merged 3 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
*
*/
package org.projecthusky.communication.configuration;

import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
* Configuration clas for specific husky beans and other configs.
*/
@Configuration
public class HuskyConfiguration {

@Value("${husky.communication.timeout:60000}")
private Long communicationTimeout;
ralych marked this conversation as resolved.
Show resolved Hide resolved

/**
* Configuration for the husky http client policy.
*
* @return the HTTPClientPolicy
*/
@Bean
public HTTPClientPolicy huskyHttpClientPolicy() {
var policy = new HTTPClientPolicy();
policy.setConnectionRequestTimeout(communicationTimeout);
policy.setReceiveTimeout(communicationTimeout);
return policy;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@
import org.projecthusky.communication.mpi.impl.pdq.V3PdqContinuationQuery;
import org.projecthusky.communication.mpi.impl.pdq.V3PdqQuery;
import org.projecthusky.communication.mpi.impl.pdq.V3PdqQueryResponse;
import org.projecthusky.communication.utils.HuskyUtils;
import org.projecthusky.fhir.structures.gen.FhirPatient;
import org.projecthusky.xua.core.SecurityHeaderElement;
import org.openehealth.ipf.commons.audit.AuditContext;
import org.openehealth.ipf.commons.ihe.hl7v3.PDQV3;
import org.openehealth.ipf.commons.ihe.xds.XDS;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
Expand Down Expand Up @@ -49,20 +52,23 @@ public PdqV3Query(AffinityDomain affinityDomain, String homeCommunityOid, CamelC
setAuditContext(auditContext);
}

public PdqV3Query(AffinityDomain affinityDomain, String homeCommunityOid, String homeCommunityNameSpace,
CamelContext context, AuditContext auditContext) {
public PdqV3Query(AffinityDomain affinityDomain, String homeCommunityOid,
String homeCommunityNameSpace, CamelContext context, AuditContext auditContext) {
super(affinityDomain, homeCommunityOid, homeCommunityNameSpace, null, null, context);
setAuditContext(auditContext);
}

/**
* Performs a PDQ Query (ITI-47)
*
* @param mpiQuery the mpi query object
* @param assertion a security header element for example an assertion
* @param mpiQuery
* the mpi query object
* @param assertion
* a security header element for example an assertion
* @return the v3 pdq query response
*/
public V3PdqQueryResponse queryPatients(V3PdqQuery mpiQuery, SecurityHeaderElement assertion, String messageId) {
public V3PdqQueryResponse queryPatients(V3PdqQuery mpiQuery, SecurityHeaderElement assertion,
String messageId) {
final var queryResponse = new V3PdqQueryResponse();

/* The last pdq consumer response. */
Expand All @@ -71,8 +77,8 @@ public V3PdqQueryResponse queryPatients(V3PdqQuery mpiQuery, SecurityHeaderEleme
if (!mpiQuery.doCancelQuery()) {
PRPAIN201306UV02Type lastPdqConsumerResponse = null;
if (!mpiQuery.doContinueQuery()) {
lastPdqConsumerResponse = sendITI47Query(mpiQuery.getV3PdqConsumerQuery(), assertion,
this.pdqConsumerUri, messageId);
lastPdqConsumerResponse = sendITI47Query(mpiQuery.getV3PdqConsumerQuery(),
assertion, this.pdqConsumerUri, messageId);
} else {
final var continuationQuery = new V3PdqContinuationQuery(
mpiQuery.getV3PdqConsumerQuery().getSendingApplication(),
Expand All @@ -81,8 +87,8 @@ public V3PdqQueryResponse queryPatients(V3PdqQuery mpiQuery, SecurityHeaderEleme
mpiQuery.getV3PdqConsumerQuery().getReceivingFacility(0),
mpiQuery.getLastPdqConsumerResponse(), mpiQuery.getPageCount());
continuationQuery.setProcessingCode("T");
lastPdqConsumerResponse = sendITI47ContinuationQuery(continuationQuery, assertion,
this.pdqConsumerUri, messageId);
lastPdqConsumerResponse = sendITI47ContinuationQuery(continuationQuery,
assertion, this.pdqConsumerUri, messageId);
}

var response = new V3PdqConsumerResponse(lastPdqConsumerResponse);
Expand All @@ -98,20 +104,22 @@ public V3PdqQueryResponse queryPatients(V3PdqQuery mpiQuery, SecurityHeaderEleme
queryResponse.setInfoTexts(List.of(response.getAcknowledgementDetailText()));
}
queryResponse.setErrorText(response.getErrorText());
final INT totalNumbers = response.getPdqResponse().getControlActProcess().getQueryAck()
.getResultTotalQuantity();
final INT totalNumbers = response.getPdqResponse().getControlActProcess()
.getQueryAck().getResultTotalQuantity();
if (totalNumbers != null) {
queryResponse.setTotalNumbers(totalNumbers.getValue());
}

mpiQuery.setLastPdqConsumerResponse(response);
} else {
V3PdqConsumerResponse lastPdqConsumerResponse = mpiQuery.getLastPdqConsumerResponse();
V3PdqConsumerResponse lastPdqConsumerResponse = mpiQuery
.getLastPdqConsumerResponse();
final var continuationCancel = new V3PdqContinuationCancel(
mpiQuery.getV3PdqConsumerQuery().getSendingApplication(),
mpiQuery.getV3PdqConsumerQuery().getSendingFacility(),
mpiQuery.getV3PdqConsumerQuery().getReceivingApplication(0),
mpiQuery.getV3PdqConsumerQuery().getReceivingFacility(0), lastPdqConsumerResponse);
mpiQuery.getV3PdqConsumerQuery().getReceivingFacility(0),
lastPdqConsumerResponse);
var response = sendITI47ContinuationQuery(continuationCancel, assertion,
this.pdqConsumerUri, messageId);

Expand All @@ -129,15 +137,17 @@ public V3PdqQueryResponse queryPatients(V3PdqQuery mpiQuery, SecurityHeaderEleme
/**
* Gets the patients from pdq query.
*
* @param response the response
* @param response
* the response
* @return the patients from pdq query
*/
public List<FhirPatient> getPatientsFromPdqQuery(V3PdqConsumerResponse response) {
var success = false;
if (response != null) {
success = !response.hasError();
if (success) {
final List<FhirPatient> listFhirPatients = new ArrayList<>(response.getNumRecordsCurrent());
final List<FhirPatient> listFhirPatients = new ArrayList<>(
response.getNumRecordsCurrent());
for (var i = 0; i < response.getNumRecordsCurrent(); ++i) {
final var fhirPatient = new FhirPatient();
addDemographicData(getPatientByIndex(response, i), fhirPatient);
Expand All @@ -152,20 +162,28 @@ public List<FhirPatient> getPatientsFromPdqQuery(V3PdqConsumerResponse response)
/**
* Get the specified patient object.
*
* @param v3PdqConsumerResponse the consumer response
* @param patientIndex the patient index
* @return PRPAMT201310UV02Patient - the patient object at the specified index.
* @param v3PdqConsumerResponse
* the consumer response
* @param patientIndex
* the patient index
* @return PRPAMT201310UV02Patient - the patient object at the specified
* index.
*/
protected PRPAMT201310UV02Patient getPatientByIndex(V3PdqConsumerResponse v3PdqConsumerResponse, int patientIndex) {
return v3PdqConsumerResponse.getPdqResponse().getControlActProcess().getSubject().get(patientIndex)
.getRegistrationEvent().getSubject1().getPatient();
protected PRPAMT201310UV02Patient getPatientByIndex(V3PdqConsumerResponse v3PdqConsumerResponse,
int patientIndex) {
return v3PdqConsumerResponse.getPdqResponse().getControlActProcess().getSubject()
.get(patientIndex).getRegistrationEvent().getSubject1().getPatient();
}

private PRPAIN201306UV02Type sendITI47Query(V3PdqConsumerQuery request, SecurityHeaderElement assertion,
URI pdqDest, String messageId) throws Exception {
final var endpoint = String.format(
"pdqv3-iti47://%s?inInterceptors=#serverInLogger&inFaultInterceptors=#serverInLogger&outInterceptors=#serverOutLogger&outFaultInterceptors=#serverOutLogger&secure=%s&audit=%s&auditContext=#auditContext",
pdqDest.toString().replace("https://", ""), true, getAuditContext().isAuditEnabled());
private PRPAIN201306UV02Type sendITI47Query(V3PdqConsumerQuery request,
SecurityHeaderElement assertion, URI pdqDest, String messageId) throws Exception {

final String endpoint = HuskyUtils.createEndpoint(
PDQV3.Interactions.ITI_47.getWsTransactionConfiguration().getName(), //
pdqDest, //
true, //
getAuditContext().isAuditEnabled());

LOGGER.info("Sending request to '{}' endpoint", endpoint);

String message = XmlMarshaller.marshall(request.getRootElement());
Expand All @@ -184,9 +202,13 @@ private PRPAIN201306UV02Type sendITI47Query(V3PdqConsumerQuery request, Security

private PRPAIN201306UV02Type sendITI47ContinuationQuery(V3PdqContinuationBase request,
SecurityHeaderElement assertion, URI pdqDest, String messageId) throws Exception {
final var endpoint = String.format(
"pdqv3-iti47://%s?inInterceptors=#serverInLogger&inFaultInterceptors=#serverInLogger&outInterceptors=#serverOutLogger&outFaultInterceptors=#serverOutLogger&secure=%s&supportContinuation=%s&defaultContinuationThreshold=50&audit=%s&auditContext=#auditContext",
pdqDest.toString().replace("https://", ""), true, true, getAuditContext().isAuditEnabled());

String endpoint = HuskyUtils.createEndpoint(
PDQV3.Interactions.ITI_47.getWsTransactionConfiguration().getName(), //
pdqDest, //
true, //
getAuditContext().isAuditEnabled());
endpoint += "&defaultContinuationThreshold=50&supportContinuation=true";
LOGGER.info("Sending request to '{}' endpoint", endpoint);

String message = XmlMarshaller.marshall(request.getRootElement());
Expand Down
Loading
Loading