Skip to content

Commit

Permalink
FI-1223: Expose multiple software versions at /version endpoint (#62)
Browse files Browse the repository at this point in the history
* starting point from #42

* FI-1223 refactor /version to return a JSON

* FI-1223: update api doc with new description of /version

* remove redundant function
  • Loading branch information
dehall authored Jul 24, 2023
1 parent 8474832 commit 74ccd94
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
11 changes: 11 additions & 0 deletions rest-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,17 @@ Also note that the request must have the `Content-Encoding: gzip` header.
- **Response:**
the NPM ID, version, and list of profile URLs of the loaded IG. [See here](#loading-a-custom-ig) for an example.

### Get this wrapper's version
- **Route:**
`GET /version`
- **Response:**
A JSON object containing identifiers and version numbers for the software in use, such as the version of the wrapper itself and the version of the HL7 validator.
- **Example Response:**
```
{"org.hl7.fhir.validation":"5.6.93","inferno-framework/fhir-validator-wrapper":"2.2.1"}
```


# FHIRPath Routes

### Evaluate a FHIRPath expression
Expand Down
4 changes: 0 additions & 4 deletions src/main/java/org/mitre/inferno/Validator.java
Original file line number Diff line number Diff line change
Expand Up @@ -305,10 +305,6 @@ public Map<String, List<String>> getProfilesByIg() {
));
}

public String getVersion() {
return VersionUtil.getVersion();
}

/**
* Load a profile from a file.
*
Expand Down
23 changes: 21 additions & 2 deletions src/main/java/org/mitre/inferno/rest/ValidatorEndpoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.hl7.fhir.r5.formats.JsonParser;
import org.hl7.fhir.r5.model.OperationOutcome;
import org.mitre.inferno.Validator;
import org.mitre.inferno.Version;

public class ValidatorEndpoint {
private static ValidatorEndpoint validatorEndpoint = null;
Expand Down Expand Up @@ -65,7 +67,7 @@ private void createRoutes() {
(req, res) -> validator.loadIg(req.params("id"), req.queryParams("version")),
TO_JSON);

get("/version", (req, res) -> Version.getVersion());
get("/version", (req, res) -> buildVersionResponse(), TO_JSON);
}

/**
Expand All @@ -87,4 +89,21 @@ private String validateResource(byte[] resource, String profile) throws Exceptio
OperationOutcome oo = validator.validate(resource, patientProfiles);
return new JsonParser().composeString(oo);
}

/**
* Build a Map of the library versions used by this validator.
*
* @return a Map of library identifier -> version string
*/
private Map<String,String> buildVersionResponse() {
// full package names used here only to make it more obvious what's going on
// since the class names aren't distinct enough
String hl7ValidatorVersion = org.hl7.fhir.validation.cli.utils.VersionUtil.getVersion();
String wrapperVersion = org.mitre.inferno.Version.getVersion();

Map<String, String> versions = new HashMap<>();
versions.put("org.hl7.fhir.validation", hl7ValidatorVersion);
versions.put("inferno-framework/fhir-validator-wrapper", wrapperVersion);
return versions;
}
}

0 comments on commit 74ccd94

Please sign in to comment.