Skip to content

Commit

Permalink
Manage FhirRequestBuilders via ManagedWebAccess (#1788)
Browse files Browse the repository at this point in the history
* WIP start moving FhirRequestBuilder to ManagedWebAccess

* Update PECodeGenerator.java

* WIP keep moving FhirRequestBuilder to ManagedWebAccess + fix some tests

* WIP move logging, retry, timeout and proxy

* WIP move accept to parameter

* WIP some HTTP Header refactoring, rename FhirRequest to HTTPRequest

* WIP fix removed import

* Tidy up code

***NO_CI***

* Fix for renamed class

* Change mem settings for build

* Adjust pipeline mem again

* Apply changes to r4b

* Actually add headers from HTTPRequest to OkHttp request

* Use ManagedFhirWebAccess in r4

* Removing leftover okttp usage

* Remove unused classes and okhttp usages and add tests for r4

* Make dstu3 use ManagedFhirWebAccess

* Make sure we get response headers

* Add test coverage (some failing) for DSTU2 ClientUtils

* Add FHIRToolingClient tests

* Use ManagedFhirWebAccess for DSTU2

* WIP restore format header tests - turns out they break

* Fix format header issues

* Switch to static fhirBuilder for all FhirRequestBuilders

+ Fix null user agent issue
+ Load ManagedWebAccess from FHIR settings
+ Add terminology servers to FhirSettings

* fix slicing by type and profile to allow multiple options per slice

* List measure choices when a match by version can't be found

* Validate fhirpath expression in slice discriminators

* Remove conflicting authorization header setting methods

* fix VSAC importer for changes to ManagedWebAccess

* Tests 1

* Rename ...AccessBuilder classes to ...Accessor

* Fix api-key token mixup, more tests

* Resolve all deletions enclosed in FIXME + fix headers in dstu2 postfeed

* More TODO erasures. Plus found missing functionality

* Move tests to utilities. Clarify missing functionality

* Clean up comments and JavaDoc

* Final rename

* update vsac access code

* Fix get bytes for -1 or chunked content

---------

Co-authored-by: Jens Kristian Villadsen <jenskristianvilladsen@gmail.com>
Co-authored-by: Grahame Grieve <grahameg@gmail.com>
Co-authored-by: Grahame Grieve <grahameg@gmail.ccom>
  • Loading branch information
4 people authored Nov 8, 2024
1 parent 3dd7203 commit 59fe0c6
Show file tree
Hide file tree
Showing 81 changed files with 3,871 additions and 2,983 deletions.
3 changes: 3 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
* Fix problem validating json-property-key value pairs
* Fix special case r5 loading of terminology to fix validation error on ExampleScenario
* Improve handling of JSON format errors
* Fix slicing by type and profile to allow multiple options per slice
* List measure choices when a match by version can't be found
* Validate fhirpath expression in slice discriminators

## Other code changes

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.hl7.fhir.convertors.misc;

import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Date;
import java.util.HashSet;
Expand Down Expand Up @@ -395,7 +394,7 @@ private CodeSystem makeEntityCodeSystem() {


private JsonObject fetchJson(String source) throws IOException {
HTTPResult res = ManagedWebAccess.builder().withAccept("application/json").withHeader("API-Version", "v2").withHeader("Accept-Language", "en").get(source);
HTTPResult res = ManagedWebAccess.accessor().withHeader("API-Version", "v2").withHeader("Accept-Language", "en").get(source,"application/json");
res.checkThrowException();
return JsonParser.parseObject(res.getContent());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.hl7.fhir.utilities.CSVReader;
import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.utilities.filesystem.ManagedFileAccess;
import org.hl7.fhir.utilities.http.ManagedWebAccess;
import org.hl7.fhir.utilities.json.model.JsonArray;
import org.hl7.fhir.utilities.json.model.JsonObject;
import org.hl7.fhir.utilities.json.model.JsonProperty;
Expand All @@ -45,17 +46,16 @@ public VSACImporter() throws FHIRException, IOException {

public static void main(String[] args) throws FHIRException, IOException, ParseException, URISyntaxException {
VSACImporter self = new VSACImporter();
self.process(args[0], args[1], args[2], "true".equals(args[3]), "true".equals(args[4]));
self.process(args[0], args[1], "true".equals(args[2]), "true".equals(args[3]));
}

private void process(String source, String dest, String apiKey, boolean onlyNew, boolean onlyActive) throws FHIRException, IOException, URISyntaxException {
private void process(String source, String dest, boolean onlyNew, boolean onlyActive) throws FHIRException, IOException, URISyntaxException {
CSVReader csv = new CSVReader(ManagedFileAccess.inStream(source));
csv.readHeaders();
Map<String, String> errs = new HashMap<>();

ManagedWebAccess.loadFromFHIRSettings();
FHIRToolingClient fhirToolingClient = new FHIRToolingClient("https://cts.nlm.nih.gov/fhir", "fhir/vsac");
fhirToolingClient.setUsername("apikey");
fhirToolingClient.setPassword(apiKey);
fhirToolingClient.setTimeoutNormal(30000);
fhirToolingClient.setTimeoutExpand(30000);

Expand Down Expand Up @@ -121,6 +121,7 @@ private void process(String source, String dest, String apiKey, boolean onlyNew,
oo.addIssue().setSeverity(IssueSeverity.ERROR).setCode(IssueType.EXCEPTION).setDiagnostics(errs.get(oid)).addLocation(oid);
}
new JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(ManagedFileAccess.outStream(Utilities.path(dest, "other", "OperationOutcome-vsac-errors.json")), oo);
System.out.println();
System.out.println("Done. " + i + " ValueSets in "+Utilities.describeDuration(System.currentTimeMillis() - tt));
}

Expand Down
24 changes: 24 additions & 0 deletions org.hl7.fhir.dstu2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@
<artifactId>org.hl7.fhir.utilities</artifactId>
</dependency>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>

<!-- UCUM -->
<dependency>
<groupId>org.fhir</groupId>
Expand Down Expand Up @@ -81,6 +87,24 @@
</dependency>

<!-- Test dependencies -->
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>mockwebserver</artifactId>
<optional>true</optional>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.squareup.okio</groupId>
<artifactId>okio</artifactId>
<optional>true</optional>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
Expand Down
Loading

0 comments on commit 59fe0c6

Please sign in to comment.