diff --git a/hub-prime/pom.xml b/hub-prime/pom.xml
index f2f278f9557..e9c3a096b76 100644
--- a/hub-prime/pom.xml
+++ b/hub-prime/pom.xml
@@ -11,7 +11,7 @@
org.techbd
hub-prime
- 0.65.1
+ 0.65.2
war
TechBD Hub (Prime)
TechBD Hub (Primary)
diff --git a/hub-prime/src/main/java/org/inferno/validator/Validator.java b/hub-prime/src/main/java/org/inferno/validator/Validator.java
index 4521886d3ec..ee42934d1f2 100644
--- a/hub-prime/src/main/java/org/inferno/validator/Validator.java
+++ b/hub-prime/src/main/java/org/inferno/validator/Validator.java
@@ -35,7 +35,6 @@ public class Validator {
private final Map loadedPackages;
private static String assignedUrlFrom = null;
- private static String vesrionFrom = null;
private static final Logger LOGGER = LoggerFactory.getLogger(Validator.class);
@@ -118,14 +117,6 @@ public static void setAssignedUrlFrom(String assignedUrlFrom) {
Validator.assignedUrlFrom = assignedUrlFrom;
}
- public String getVersionFrom() {
- return vesrionFrom;
- }
-
- public static void setVersionFrom(String vesrionFrom) {
- Validator.vesrionFrom = vesrionFrom;
- }
-
/**
* Lists the names of resources defined for this version of the validator.
*
@@ -253,7 +244,6 @@ public void loadProfile(byte[] profile) throws IOException {
StructureDefinition sd = (StructureDefinition)resource;
LOGGER.info("Loaded profile from file, url: " + sd.getUrl() + " version: " + sd.getVersion());
setAssignedUrlFrom(sd.getUrl());
- setVersionFrom(sd.getVersion());
} else if (resource != null) {
LOGGER.info("Loaded resource from file but it wasn't a StructureDefinition, it was a "
+ resource.fhirType());
diff --git a/hub-prime/src/main/java/org/techbd/orchestrate/fhir/OrchestrationEngine.java b/hub-prime/src/main/java/org/techbd/orchestrate/fhir/OrchestrationEngine.java
index 80c910cb851..579bc4cfa9b 100644
--- a/hub-prime/src/main/java/org/techbd/orchestrate/fhir/OrchestrationEngine.java
+++ b/hub-prime/src/main/java/org/techbd/orchestrate/fhir/OrchestrationEngine.java
@@ -27,7 +27,6 @@
import org.apache.commons.text.StringEscapeUtils;
import org.hl7.fhir.r5.model.OperationOutcome;
-//import org.techbd.orchestrate.fhir.OrchestrationEngine.OrchestrationSession;
import org.techbd.util.JsonText.JsonTextSerializer;
import com.fasterxml.jackson.core.JsonProcessingException;
@@ -44,6 +43,7 @@
import jakarta.validation.constraints.NotNull;
import org.inferno.validator.Validator;
+import org.springframework.cache.annotation.Cacheable;
/**
* The {@code OrchestrationEngine} class is responsible for managing and
@@ -137,6 +137,36 @@ public void orchestrate(@NotNull final OrchestrationSession... sessions) {
}
}
+ @Cacheable("fhirProfile")
+ public static String fetchFhirProfileVersion(String fhirProfileUrl) {
+ HttpClient client = HttpClient.newHttpClient();
+ HttpRequest request = HttpRequest.newBuilder()
+ .uri(URI.create(fhirProfileUrl))
+ .build();
+
+ String fhirProfileVersion = client.sendAsync(request, HttpResponse.BodyHandlers.ofString())
+ .thenApply(HttpResponse::body)
+ .thenApply(responseBody -> {
+ final var objectMapper = new ObjectMapper();
+
+ try {
+ // Read JSON response and parse it into a JsonNode
+ final var rootNode = objectMapper.readTree(responseBody);
+
+ // Get the value of the "version" key from FHIR IG profile JSON
+ JsonNode versionNode = rootNode.path("version");
+ return versionNode.asText();
+
+ } catch (IOException e) {
+ e.printStackTrace();
+ return null;
+ }
+ })
+ .join(); // Wait for the async operation to complete
+
+ return fhirProfileVersion;
+ }
+
public ValidationEngine getValidationEngine(@NotNull final ValidationEngineIdentifier type,
@NotNull final String fhirProfileUrl) {
ValidationEngineKey key = new ValidationEngineKey(type, fhirProfileUrl);
@@ -198,6 +228,8 @@ public interface ValidationResult {
String getProfileUrl();
+ String getFhirProfileVersion();
+
ValidationEngine.Observability getObservability();
boolean isValid();
@@ -237,9 +269,11 @@ public static class HapiValidationEngine implements OrchestrationEngine.Validati
private final FhirContext fhirContext;
private final FhirValidator validator;
private final ValidationOptions options;
+ private final String fhirProfileVersion;
private HapiValidationEngine(final Builder builder) {
this.fhirProfileUrl = builder.fhirProfileUrl;
+ fhirProfileVersion = OrchestrationEngine.fetchFhirProfileVersion(fhirProfileUrl);
this.fhirContext = FhirContext.forR4();
this.options = new ValidationOptions();
if (this.fhirProfileUrl != null) {
@@ -305,6 +339,11 @@ public String getProfileUrl() {
return HapiValidationEngine.this.fhirProfileUrl;
}
+ @Override
+ public String getFhirProfileVersion() {
+ return HapiValidationEngine.this.fhirProfileVersion;
+ }
+
@Override
public ValidationEngine.Observability getObservability() {
return observability;
@@ -359,6 +398,11 @@ public String getProfileUrl() {
return HapiValidationEngine.this.fhirProfileUrl;
}
+ @Override
+ public String getFhirProfileVersion() {
+ return HapiValidationEngine.this.fhirProfileVersion;
+ }
+
@Override
public ValidationEngine.Observability getObservability() {
return observability;
@@ -402,9 +446,11 @@ public static class Hl7ValidationEngineEmbedded implements ValidationEngine {
private final Instant engineInitAt = Instant.now();
private final Instant engineConstructedAt;
private final String fhirProfileUrl;
+ private final String fhirProfileVersion;
private Hl7ValidationEngineEmbedded(final Builder builder) {
this.fhirProfileUrl = builder.fhirProfileUrl;
+ fhirProfileVersion = OrchestrationEngine.fetchFhirProfileVersion(fhirProfileUrl);
engineConstructedAt = Instant.now();
observability = new Observability(Hl7ValidationEngineEmbedded.class.getName(),
"HL7 Official Embedded (TODO: version)", engineInitAt,
@@ -436,6 +482,11 @@ public String getProfileUrl() {
return Hl7ValidationEngineEmbedded.this.fhirProfileUrl;
}
+ @Override
+ public String getFhirProfileVersion() {
+ return Hl7ValidationEngineEmbedded.this.fhirProfileVersion;
+ }
+
@Override
public ValidationEngine.Observability getObservability() {
return observability;
@@ -481,9 +532,11 @@ public static class Hl7ValidationEngineApi implements ValidationEngine {
private final String locale;
private final String fileType;
private final String fileName;
+ private final String fhirProfileVersion;
private Hl7ValidationEngineApi(final Builder builder) {
this.fhirProfileUrl = builder.fhirProfileUrl;
+ fhirProfileVersion = OrchestrationEngine.fetchFhirProfileVersion(fhirProfileUrl);
this.fhirContext = "4.0.1";
this.locale = "en";
this.fileType = "json";
@@ -606,6 +659,11 @@ public String getProfileUrl() {
return Hl7ValidationEngineApi.this.fhirProfileUrl;
}
+ @Override
+ public String getFhirProfileVersion() {
+ return Hl7ValidationEngineApi.this.fhirProfileVersion;
+ }
+
@Override
public ValidationEngine.Observability getObservability() {
return observability;
@@ -650,9 +708,12 @@ public static class InfernoValidationEngine implements ValidationEngine {
private final String fhirProfileUrl;
private final Validator validator;
private List fhirBundleProfile;
-
+ private final String fhirProfileVersion;
+
private InfernoValidationEngine(final Builder builder) {
this.fhirProfileUrl = builder.fhirProfileUrl;
+ fhirProfileVersion = OrchestrationEngine.fetchFhirProfileVersion(fhirProfileUrl);
+ //fhirProfileVersion = OrchestrationEngine.fetchFhirProfileVersion(fhirProfileUrl);
Validator tempValidator;
try {
tempValidator = new Validator("hub-prime/igs", false);
@@ -685,7 +746,7 @@ public ValidationResult validate(@NotNull final String payload) {
OperationOutcome oo = validator.validate(payloadContent, fhirBundleProfile);
ArrayNode issueArray = displayValidationErrors(oo, false);
- ObjectMapper mapper = new ObjectMapper();
+ final var mapper = new ObjectMapper();
String responseBody = mapper.writeValueAsString(issueArray);
final Instant completedAt = Instant.now();
@@ -752,6 +813,11 @@ public String getProfileUrl() {
return InfernoValidationEngine.this.fhirProfileUrl;
}
+ @Override
+ public String getFhirProfileVersion() {
+ return InfernoValidationEngine.this.fhirProfileVersion;
+ }
+
@Override
public ValidationEngine.Observability getObservability() {
return observability;
@@ -805,6 +871,11 @@ public String getProfileUrl() {
return InfernoValidationEngine.this.fhirProfileUrl;
}
+ @Override
+ public String getFhirProfileVersion() {
+ return InfernoValidationEngine.this.fhirProfileVersion;
+ }
+
@Override
public ValidationEngine.Observability getObservability() {
return observability;