-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'vsm_operations' into aphl-300-valueset-interceptor
- Loading branch information
Showing
20 changed files
with
3,208 additions
and
2,391 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
core/src/main/java/org/opencds/cqf/ruler/provider/HapiFhirRepositoryProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package org.opencds.cqf.ruler.provider; | ||
|
||
import org.opencds.cqf.ruler.api.OperationProvider; | ||
import org.opencds.cqf.ruler.behavior.DaoRegistryUser; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
import ca.uhn.fhir.cr.repo.HapiFhirRepository; | ||
import ca.uhn.fhir.jpa.api.dao.DaoRegistry; | ||
import ca.uhn.fhir.rest.api.server.RequestDetails; | ||
import ca.uhn.fhir.rest.server.RestfulServer; | ||
|
||
public class HapiFhirRepositoryProvider implements OperationProvider, DaoRegistryUser { | ||
@Autowired | ||
private DaoRegistry myDaoRegistry; | ||
|
||
@Autowired | ||
RestfulServer myRestfulServer; | ||
|
||
public DaoRegistry getDaoRegistry() { | ||
return myDaoRegistry; | ||
} | ||
public HapiFhirRepository getRepository(RequestDetails theRequestDetails) { | ||
return new HapiFhirRepository(myDaoRegistry, theRequestDetails, myRestfulServer); | ||
} | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
309 changes: 220 additions & 89 deletions
309
plugin/cr/src/main/java/org/opencds/cqf/ruler/cr/KnowledgeArtifactProcessor.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
plugin/cr/src/main/java/org/opencds/cqf/ruler/cr/TerminologyServerClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package org.opencds.cqf.ruler.cr; | ||
|
||
import ca.uhn.fhir.context.FhirContext; | ||
import ca.uhn.fhir.rest.client.api.IGenericClient; | ||
import ca.uhn.fhir.rest.client.interceptor.AdditionalRequestHeadersInterceptor; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.hl7.fhir.r4.model.Parameters; | ||
import org.hl7.fhir.r4.model.ValueSet; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.opencds.cqf.cql.evaluator.fhir.util.Canonicals; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
import java.util.Base64; | ||
|
||
public class TerminologyServerClient { | ||
|
||
private final FhirContext ctx; | ||
|
||
private String username; | ||
|
||
private String getUsername() { | ||
return username; | ||
} | ||
|
||
private void setUsername(String username) { | ||
this.username = username; | ||
} | ||
|
||
private String apiKey; | ||
|
||
private String getApiKey() { | ||
return apiKey; | ||
} | ||
|
||
private void setApiKey(String apiKey) { | ||
this.apiKey = apiKey; | ||
} | ||
public TerminologyServerClient() { | ||
ctx = FhirContext.forR4(); | ||
} | ||
|
||
public TerminologyServerClient(String username, String apiKey) { | ||
this(); | ||
setUsername(username); | ||
setApiKey(apiKey); | ||
} | ||
|
||
public ValueSet expand(ValueSet valueSet, String authoritativeSource, Parameters expansionParameters) { | ||
IGenericClient fhirClient = ctx.newRestfulGenericClient(getAuthoritativeSourceBase(authoritativeSource)); | ||
fhirClient.registerInterceptor(getAuthInterceptor(getUsername(), getApiKey())); | ||
|
||
// Invoke by Value Set ID | ||
return fhirClient | ||
.operation() | ||
.onInstance(valueSet.getId()) | ||
.named("$expand") | ||
.withParameters(expansionParameters) | ||
.returnResourceType(ValueSet.class) | ||
.execute(); | ||
} | ||
|
||
private AdditionalRequestHeadersInterceptor getAuthInterceptor(String username, String apiKey) { | ||
String authString = StringUtils.join("Basic ", Base64.getEncoder() | ||
.encodeToString(StringUtils.join(username, ":", apiKey).getBytes(StandardCharsets.UTF_8))); | ||
AdditionalRequestHeadersInterceptor authInterceptor = new AdditionalRequestHeadersInterceptor(); | ||
authInterceptor.addHeaderValue("Authorization", authString); | ||
return authInterceptor; | ||
} | ||
|
||
// Strips resource and id from the authoritative source URL, these are not needed as the client constructs the URL. | ||
// Converts http URLs to https | ||
private String getAuthoritativeSourceBase(String authoritativeSource) { | ||
authoritativeSource = authoritativeSource.substring(0, authoritativeSource.indexOf(Canonicals.getResourceType(authoritativeSource))); | ||
if (authoritativeSource.startsWith("http://")) { | ||
authoritativeSource = authoritativeSource.replaceFirst("http://", "https://"); | ||
} | ||
return authoritativeSource; | ||
} | ||
} |
87 changes: 87 additions & 0 deletions
87
plugin/cr/src/main/java/org/opencds/cqf/ruler/cr/r4/helper/ResourceClassMapHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package org.opencds.cqf.ruler.cr.r4.helper; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import org.hl7.fhir.exceptions.FHIRException; | ||
import org.hl7.fhir.instance.model.api.IBaseResource; | ||
import org.hl7.fhir.r4.model.ActivityDefinition; | ||
import org.hl7.fhir.r4.model.CapabilityStatement; | ||
import org.hl7.fhir.r4.model.ChargeItemDefinition; | ||
import org.hl7.fhir.r4.model.CodeSystem; | ||
import org.hl7.fhir.r4.model.CompartmentDefinition; | ||
import org.hl7.fhir.r4.model.ConceptMap; | ||
import org.hl7.fhir.r4.model.EffectEvidenceSynthesis; | ||
import org.hl7.fhir.r4.model.EventDefinition; | ||
import org.hl7.fhir.r4.model.Evidence; | ||
import org.hl7.fhir.r4.model.EvidenceVariable; | ||
import org.hl7.fhir.r4.model.ExampleScenario; | ||
import org.hl7.fhir.r4.model.GraphDefinition; | ||
import org.hl7.fhir.r4.model.ImplementationGuide; | ||
import org.hl7.fhir.r4.model.Library; | ||
import org.hl7.fhir.r4.model.Measure; | ||
import org.hl7.fhir.r4.model.MessageDefinition; | ||
import org.hl7.fhir.r4.model.NamingSystem; | ||
import org.hl7.fhir.r4.model.OperationDefinition; | ||
import org.hl7.fhir.r4.model.PlanDefinition; | ||
import org.hl7.fhir.r4.model.Questionnaire; | ||
import org.hl7.fhir.r4.model.ResearchDefinition; | ||
import org.hl7.fhir.r4.model.ResearchElementDefinition; | ||
import org.hl7.fhir.r4.model.ResourceType; | ||
import org.hl7.fhir.r4.model.RiskEvidenceSynthesis; | ||
import org.hl7.fhir.r4.model.SearchParameter; | ||
import org.hl7.fhir.r4.model.StructureDefinition; | ||
import org.hl7.fhir.r4.model.StructureMap; | ||
import org.hl7.fhir.r4.model.TerminologyCapabilities; | ||
import org.hl7.fhir.r4.model.TestScript; | ||
import org.hl7.fhir.r4.model.ValueSet; | ||
|
||
import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; | ||
|
||
public class ResourceClassMapHelper { | ||
public static final Map<ResourceType, Class<? extends IBaseResource>> resourceTypeToClass = new HashMap<ResourceType, Class<? extends IBaseResource>>() {{ | ||
put(ResourceType.ActivityDefinition, ActivityDefinition.class); | ||
put(ResourceType.CapabilityStatement, CapabilityStatement.class); | ||
put(ResourceType.ChargeItemDefinition, ChargeItemDefinition.class); | ||
put(ResourceType.CompartmentDefinition, CompartmentDefinition.class); | ||
put(ResourceType.ConceptMap, ConceptMap.class); | ||
put(ResourceType.EffectEvidenceSynthesis, EffectEvidenceSynthesis.class); | ||
put(ResourceType.EventDefinition, EventDefinition.class); | ||
put(ResourceType.Evidence, Evidence.class); | ||
put(ResourceType.EvidenceVariable, EvidenceVariable.class); | ||
put(ResourceType.ExampleScenario, ExampleScenario.class); | ||
put(ResourceType.GraphDefinition, GraphDefinition.class); | ||
put(ResourceType.ImplementationGuide, ImplementationGuide.class); | ||
put(ResourceType.Library, Library.class); | ||
put(ResourceType.Measure, Measure.class); | ||
put(ResourceType.MessageDefinition, MessageDefinition.class); | ||
put(ResourceType.NamingSystem, NamingSystem.class); | ||
put(ResourceType.OperationDefinition, OperationDefinition.class); | ||
put(ResourceType.PlanDefinition, PlanDefinition.class); | ||
put(ResourceType.Questionnaire, Questionnaire.class); | ||
put(ResourceType.ResearchDefinition, ResearchDefinition.class); | ||
put(ResourceType.ResearchElementDefinition, ResearchElementDefinition.class); | ||
put(ResourceType.RiskEvidenceSynthesis, RiskEvidenceSynthesis.class); | ||
put(ResourceType.SearchParameter, SearchParameter.class); | ||
put(ResourceType.StructureDefinition, StructureDefinition.class); | ||
put(ResourceType.StructureMap, StructureMap.class); | ||
put(ResourceType.TerminologyCapabilities, TerminologyCapabilities.class); | ||
put(ResourceType.TestScript, TestScript.class); | ||
put(ResourceType.ValueSet, ValueSet.class); | ||
put(ResourceType.CodeSystem, CodeSystem.class); | ||
}}; | ||
|
||
public static Class<? extends IBaseResource> getClass(String resourceType) throws UnprocessableEntityException { | ||
ResourceType type = null; | ||
try { | ||
type = ResourceType.fromCode(resourceType); | ||
} catch (FHIRException e) { | ||
throw new UnprocessableEntityException("Could not find resource type : " + resourceType); | ||
} | ||
Class<? extends IBaseResource> retval = resourceTypeToClass.get(type); | ||
if (retval == null) { | ||
throw new UnprocessableEntityException(resourceType + " is not a valid KnowledgeArtifact resource type"); | ||
} | ||
return retval; | ||
} | ||
} |
Oops, something went wrong.