Skip to content

Commit

Permalink
Added client_id OAuth 2.0 support to CDSHooks service (#701)
Browse files Browse the repository at this point in the history
Added client_id configuration to Cds Hooks properties
  • Loading branch information
c-schuler authored Apr 14, 2023
1 parent 24cb5f5 commit 37475b0
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ public void setEnabled(boolean enabled) {
this.enabled = enabled;
}

private String clientIdHeaderName;

public String getClientIdHeaderName() {
return clientIdHeaderName;
}

public void setClientIdHeaderName(String clientIdHeaderName) {
this.clientIdHeaderName = clientIdHeaderName;
}

private FhirServer fhirServer = new FhirServer();

public FhirServer getFhirServer() {
Expand All @@ -27,7 +37,7 @@ public void setFhirServer(FhirServer fhirServer) {
this.fhirServer = fhirServer;
}

public class FhirServer {
public static class FhirServer {
private Integer maxCodesPerQuery;

public Integer getMaxCodesPerQuery() {
Expand Down Expand Up @@ -79,7 +89,7 @@ public void setPrefetch(Prefetch prefetch) {
this.prefetch = prefetch;
}

public class Prefetch {
public static class Prefetch {
private Integer maxUriLength;

public Integer getMaxUriLength() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,12 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
useServerData = new BooleanType(false);
remoteDataEndpoint = new Endpoint().setAddress(cdsHooksRequest.fhirServer);
if (cdsHooksRequest.fhirAuthorization != null) {
remoteDataEndpoint.addHeader(cdsHooksRequest.fhirAuthorization.tokenType + ": "
+ cdsHooksRequest.fhirAuthorization.accessToken);
remoteDataEndpoint.addHeader(cdsHooksRequest.fhirAuthorization.tokenType
+ ": " + cdsHooksRequest.fhirAuthorization.accessToken);
if (cdsHooksRequest.fhirAuthorization.subject != null) {
remoteDataEndpoint.addHeader(this.getProviderConfiguration().getClientIdHeaderName()
+ ": " + cdsHooksRequest.fhirAuthorization.subject);
}
}
}
Bundle data = CdsHooksUtil.getPrefetchResources(cdsHooksRequest);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,26 @@

public class ProviderConfiguration {

public static final ProviderConfiguration DEFAULT_PROVIDER_CONFIGURATION = new ProviderConfiguration(true, null,
SearchStyleEnum.GET, 8000, false, null);
public static final ProviderConfiguration DEFAULT_PROVIDER_CONFIGURATION = new ProviderConfiguration(true, 64,
SearchStyleEnum.GET, 8000, false, 5, "client_id");

private Integer maxCodesPerQuery;
private SearchStyleEnum searchStyle;
private boolean expandValueSets;
private Integer queryBatchThreshold;
private int maxUriLength;
private boolean cqlLoggingEnabled;
private final Integer maxCodesPerQuery;
private final SearchStyleEnum searchStyle;
private final boolean expandValueSets;
private final Integer queryBatchThreshold;
private final Integer maxUriLength;
private final String clientIdHeaderName;
private final boolean cqlLoggingEnabled;

public ProviderConfiguration(boolean expandValueSets, Integer maxCodesPerQuery, SearchStyleEnum searchStyle,
int maxUriLength, boolean cqlLoggingEnabled, Integer queryBatchThreshold) {
Integer maxUriLength, boolean cqlLoggingEnabled, Integer queryBatchThreshold, String clientIdHeaderName) {
this.maxCodesPerQuery = maxCodesPerQuery;
this.searchStyle = searchStyle;
this.expandValueSets = expandValueSets;
this.maxUriLength = maxUriLength;
this.cqlLoggingEnabled = cqlLoggingEnabled;
this.queryBatchThreshold = queryBatchThreshold;
this.clientIdHeaderName = clientIdHeaderName;
}

public ProviderConfiguration(CdsHooksProperties cdsProperties, CqlProperties cqlProperties) {
Expand All @@ -33,6 +35,7 @@ public ProviderConfiguration(CdsHooksProperties cdsProperties, CqlProperties cql
this.searchStyle = cdsProperties.getFhirServer().getSearchStyle();
this.maxUriLength = cdsProperties.getPrefetch().getMaxUriLength();
this.queryBatchThreshold = cdsProperties.getFhirServer().getQueryBatchThreshold();
this.clientIdHeaderName = cdsProperties.getClientIdHeaderName();
this.cqlLoggingEnabled = cqlProperties.getOptions().getCqlEngineOptions().isDebugLoggingEnabled();
}

Expand All @@ -50,10 +53,14 @@ public boolean getExpandValueSets() {

public Integer getQueryBatchThreshold() { return this.queryBatchThreshold; }

public int getMaxUriLength() {
public Integer getMaxUriLength() {
return this.maxUriLength;
}

public String getClientIdHeaderName() {
return this.clientIdHeaderName;
}

public boolean getCqlLoggingEnabled() {
return this.cqlLoggingEnabled;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,12 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
useServerData = new BooleanType(false);
remoteDataEndpoint = new Endpoint().setAddress(cdsHooksRequest.fhirServer);
if (cdsHooksRequest.fhirAuthorization != null) {
remoteDataEndpoint.addHeader(cdsHooksRequest.fhirAuthorization.tokenType + ": "
+ cdsHooksRequest.fhirAuthorization.accessToken);
remoteDataEndpoint.addHeader(cdsHooksRequest.fhirAuthorization.tokenType
+ ": " + cdsHooksRequest.fhirAuthorization.accessToken);
if (cdsHooksRequest.fhirAuthorization.subject != null) {
remoteDataEndpoint.addHeader(this.getProviderConfiguration().getClientIdHeaderName()
+ ": " + cdsHooksRequest.fhirAuthorization.subject);
}
}
}
Bundle data = CdsHooksUtil.getPrefetchResources(cdsHooksRequest);
Expand Down
1 change: 1 addition & 0 deletions plugin/cds-hooks/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ hapi:
fhir:
cdshooks:
enabled: true
clientIdHeaderName: client_id
fhirserver:
expandValueSets: true
maxCodesPerQuery: 64
Expand Down
7 changes: 4 additions & 3 deletions server/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,11 @@ hapi:
## CDS Hook Settings
cdshooks:
enabled: true
clientIdHeaderName: client_id
fhirserver:
# expandValueSets: true
# maxCodesPerQuery: 64
# queryBatchThreshold: 10
expandValueSets: true
maxCodesPerQuery: 64
queryBatchThreshold: 5
searchStyle: GET
prefetch:
maxUriLength: 8000

0 comments on commit 37475b0

Please sign in to comment.