diff --git a/src/main/java/ca/uhn/fhir/jpa/starter/AppProperties.java b/src/main/java/ca/uhn/fhir/jpa/starter/AppProperties.java index 87b1aea..504d4fc 100644 --- a/src/main/java/ca/uhn/fhir/jpa/starter/AppProperties.java +++ b/src/main/java/ca/uhn/fhir/jpa/starter/AppProperties.java @@ -928,7 +928,8 @@ public class AppProperties { request_tenant_partitioning_mode = theRequest_tenant_partitioning_mode; } } - public static class RemoteSystem{ + + public static class RemoteSystem { private String system; private String url; diff --git a/src/main/java/ca/uhn/fhir/jpa/starter/common/FhirServerConfigR4.java b/src/main/java/ca/uhn/fhir/jpa/starter/common/FhirServerConfigR4.java index ca0ca8e..ffc4c44 100644 --- a/src/main/java/ca/uhn/fhir/jpa/starter/common/FhirServerConfigR4.java +++ b/src/main/java/ca/uhn/fhir/jpa/starter/common/FhirServerConfigR4.java @@ -30,20 +30,60 @@ public class FhirServerConfigR4 { @Bean(name = "myHybridRemoteValidationSupportChain") @Conditional({OnR4Condition.class, OnRemoteTerminologyPresent.class}) - public IValidationSupport addRemoteValidation(ValidationSupportChain theValidationSupport, FhirContext theFhirContext, AppProperties theAppProperties) - { - theAppProperties.getRemoteTerminologyServicesMap().forEach((key, remoteSystem) -> { - theValidationSupport.addValidationSupport(0 , new RemoteTerminologyServiceValidationSupport(theFhirContext, remoteSystem.getUrl()){ - @Override - public CodeValidationResult validateCode(ValidationSupportContext theValidationSupportContext, ConceptValidationOptions theOptions, String theCodeSystem, String theCode, String theDisplay, String theValueSetUrl) { - if (remoteSystem.getSystem().equalsIgnoreCase(theCodeSystem)) { - return super.validateCode(theValidationSupportContext, theOptions, theCodeSystem, theCode, theDisplay, theValueSetUrl); - } - return null; - } - }); - }); + public IValidationSupport addRemoteValidation( + ValidationSupportChain theValidationSupport, FhirContext theFhirContext, AppProperties theAppProperties) { + var values = theAppProperties.getRemoteTerminologyServicesMap().values(); + // If the remote terminology service is "*" and is the only one then forward all requests to the remote + // terminology service + if (values.size() == 1 && "*".equalsIgnoreCase(values.iterator().next().getSystem())) { + var remoteSystem = values.iterator().next(); + theValidationSupport.addValidationSupport( + 0, new RemoteTerminologyServiceValidationSupport(theFhirContext, remoteSystem.getUrl()) { + @Override + public CodeValidationResult validateCode( + ValidationSupportContext theValidationSupportContext, + ConceptValidationOptions theOptions, + String theCodeSystem, + String theCode, + String theDisplay, + String theValueSetUrl) { + return super.validateCode( + theValidationSupportContext, + theOptions, + theCodeSystem, + theCode, + theDisplay, + theValueSetUrl); + } + }); + return theValidationSupport; + + // If there are multiple remote terminology services, then add each one to the validation chain + } else { + values.forEach((remoteSystem) -> theValidationSupport.addValidationSupport( + 0, new RemoteTerminologyServiceValidationSupport(theFhirContext, remoteSystem.getUrl()) { + @Override + public CodeValidationResult validateCode( + ValidationSupportContext theValidationSupportContext, + ConceptValidationOptions theOptions, + String theCodeSystem, + String theCode, + String theDisplay, + String theValueSetUrl) { + if (remoteSystem.getSystem().equalsIgnoreCase(theCodeSystem)) { + return super.validateCode( + theValidationSupportContext, + theOptions, + theCodeSystem, + theCode, + theDisplay, + theValueSetUrl); + } + return null; + } + })); + } return theValidationSupport; } } diff --git a/src/main/java/ca/uhn/fhir/jpa/starter/common/validation/OnRemoteTerminologyPresent.java b/src/main/java/ca/uhn/fhir/jpa/starter/common/validation/OnRemoteTerminologyPresent.java index 03e444b..bd11463 100644 --- a/src/main/java/ca/uhn/fhir/jpa/starter/common/validation/OnRemoteTerminologyPresent.java +++ b/src/main/java/ca/uhn/fhir/jpa/starter/common/validation/OnRemoteTerminologyPresent.java @@ -11,8 +11,8 @@ public class OnRemoteTerminologyPresent implements Condition { public boolean matches(ConditionContext conditionContext, AnnotatedTypeMetadata metadata) { AppProperties config = Binder.get(conditionContext.getEnvironment()) - .bind("hapi.fhir", AppProperties.class) - .orElse(null); + .bind("hapi.fhir", AppProperties.class) + .orElse(null); if (config == null) return false; if (config.getRemoteTerminologyServicesMap() == null) return false; return !config.getRemoteTerminologyServicesMap().isEmpty(); diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml index cd66379..5827556 100644 --- a/src/main/resources/application.yaml +++ b/src/main/resources/application.yaml @@ -290,12 +290,15 @@ hapi: # retain_cached_searches_mins: 60 # reuse_cached_search_results_millis: 60000 remote_terminology_service: + # all: + # system: '*' + # url: 'https://tx.fhir.org/r4/' snomed: system: 'http://snomed.info/sct' url: 'https://tx.fhir.org/r4/' loinc: system: 'http://loinc.org' - url: 'https://fhir.loinc.org/' + url: 'https://hapi.fhir.org/baseR4/' tester: home: name: Local Tester