Search in sources :

Example 1 with FHIRToolingClient

use of org.hl7.fhir.r4.utils.client.FHIRToolingClient in project org.hl7.fhir.core by hapifhir.

the class VSACImporter method process.

private void process(String source, String dest, String username, String password) throws FHIRException, IOException, URISyntaxException {
    CSVReader csv = new CSVReader(new FileInputStream(source));
    csv.readHeaders();
    FHIRToolingClient fhirToolingClient = new FHIRToolingClient("https://cts.nlm.nih.gov/fhir", "fhir/vsac");
    fhirToolingClient.setUsername(username);
    fhirToolingClient.setPassword(password);
    int i = 0;
    while (csv.line()) {
        String oid = csv.cell("OID");
        try {
            ValueSet vs = fhirToolingClient.read(ValueSet.class, oid);
            new JsonParser().compose(new FileOutputStream(Utilities.path(dest, "ValueSet-" + oid + ".json")), vs);
            i++;
            if (i % 100 == 0) {
                System.out.println(i);
            }
        } catch (Exception e) {
            System.out.println("Unable to fetch OID " + oid + ": " + e.getMessage());
        }
    }
    System.out.println("Done. " + i + " ValueSets");
}
Also used : FHIRToolingClient(org.hl7.fhir.r4.utils.client.FHIRToolingClient) CSVReader(org.hl7.fhir.utilities.CSVReader) FileOutputStream(java.io.FileOutputStream) ValueSet(org.hl7.fhir.r4.model.ValueSet) FileInputStream(java.io.FileInputStream) URISyntaxException(java.net.URISyntaxException) FHIRException(org.hl7.fhir.exceptions.FHIRException) IOException(java.io.IOException) ParseException(java.text.ParseException) JsonParser(org.hl7.fhir.r4.formats.JsonParser)

Example 2 with FHIRToolingClient

use of org.hl7.fhir.r4.utils.client.FHIRToolingClient in project org.hl7.fhir.core by hapifhir.

the class BatchLoader method loadBundle.

private static int loadBundle(String server, Bundle b, int size, int start, int end) throws URISyntaxException {
    System.out.println("Post to " + server + ". size = " + Integer.toString(size) + ", start = " + Integer.toString(start) + ", total = " + Integer.toString(b.getEntry().size()));
    FHIRToolingClient client = new FHIRToolingClient(server, "fhir/batch-loader");
    int c = start;
    if (end == -1)
        end = b.getEntry().size();
    while (c < end) {
        Bundle bt = new Bundle();
        bt.setType(BundleType.BATCH);
        bt.setId(UUID.randomUUID().toString().toLowerCase());
        for (int i = c; i < Math.min(b.getEntry().size(), c + size); i++) {
            BundleEntryComponent be = bt.addEntry();
            be.setResource(b.getEntry().get(i).getResource());
            be.getRequest().setMethod(HTTPVerb.PUT);
            be.getRequest().setUrl(be.getResource().getResourceType().toString() + "/" + be.getResource().getId());
        }
        System.out.print("  posting..");
        long ms = System.currentTimeMillis();
        Bundle resp = client.transaction(bt);
        for (int i = 0; i < resp.getEntry().size(); i++) {
            BundleEntryComponent t = resp.getEntry().get(i);
            if (!t.getResponse().getStatus().startsWith("2")) {
                System.out.println("failed status at " + Integer.toString(i) + ": " + t.getResponse().getStatus());
                return c + i;
            }
        }
        c = c + size;
        System.out.println("  ..done: " + Integer.toString(c) + ". (" + Long.toString(System.currentTimeMillis() - ms) + " ms)");
    }
    System.out.println(" done");
    return c;
}
Also used : FHIRToolingClient(org.hl7.fhir.dstu2.utils.client.FHIRToolingClient) BundleEntryComponent(org.hl7.fhir.dstu2.model.Bundle.BundleEntryComponent) Bundle(org.hl7.fhir.dstu2.model.Bundle)

Example 3 with FHIRToolingClient

use of org.hl7.fhir.r4.utils.client.FHIRToolingClient in project org.hl7.fhir.core by hapifhir.

the class BatchLoader method LoadDirectory.

private static void LoadDirectory(String server, String folder, int size) throws IOException, Exception {
    System.out.print("Connecting to " + server + ".. ");
    FHIRToolingClient client = new FHIRToolingClient(server, "fhir/batch-loader");
    System.out.println("Done");
    IniFile ini = new IniFile(Utilities.path(folder, "batch-load-progress.ini"));
    for (File f : new File(folder).listFiles()) {
        if (f.getName().endsWith(".json") || f.getName().endsWith(".xml")) {
            if (!ini.getBooleanProperty("finished", f.getName())) {
                sendFile(client, f, size, ini);
            }
        }
    }
}
Also used : FHIRToolingClient(org.hl7.fhir.r4.utils.client.FHIRToolingClient) IniFile(org.hl7.fhir.utilities.IniFile) File(java.io.File) IniFile(org.hl7.fhir.utilities.IniFile)

Example 4 with FHIRToolingClient

use of org.hl7.fhir.r4.utils.client.FHIRToolingClient in project org.hl7.fhir.core by hapifhir.

the class BatchLoader method loadBundle.

private static int loadBundle(String server, Bundle b, int size, int start, int end) throws URISyntaxException {
    System.out.println("Post to " + server + ". size = " + Integer.toString(size) + ", start = " + Integer.toString(start) + ", total = " + Integer.toString(b.getEntry().size()));
    FHIRToolingClient client = new FHIRToolingClient(server, "fhir/batch-loader");
    int c = start;
    if (end == -1)
        end = b.getEntry().size();
    while (c < end) {
        Bundle bt = new Bundle();
        bt.setType(BundleType.BATCH);
        bt.setId(UUID.randomUUID().toString().toLowerCase());
        for (int i = c; i < Math.min(b.getEntry().size(), c + size); i++) {
            BundleEntryComponent be = bt.addEntry();
            be.setResource(b.getEntry().get(i).getResource());
            be.getRequest().setMethod(HTTPVerb.PUT);
            be.getRequest().setUrl(be.getResource().getResourceType().toString() + "/" + be.getResource().getId());
        }
        System.out.print("  posting..");
        long ms = System.currentTimeMillis();
        Bundle resp = client.transaction(bt);
        for (int i = 0; i < resp.getEntry().size(); i++) {
            BundleEntryComponent t = resp.getEntry().get(i);
            if (!t.getResponse().getStatus().startsWith("2")) {
                System.out.println("failed status at " + Integer.toString(i) + ": " + t.getResponse().getStatus());
                return c + i;
            }
        }
        c = c + size;
        System.out.println("  ..done: " + Integer.toString(c) + ". (" + Long.toString(System.currentTimeMillis() - ms) + " ms)");
    }
    System.out.println(" done");
    return c;
}
Also used : FHIRToolingClient(org.hl7.fhir.r5.utils.client.FHIRToolingClient) BundleEntryComponent(org.hl7.fhir.r5.model.Bundle.BundleEntryComponent) Bundle(org.hl7.fhir.r5.model.Bundle)

Example 5 with FHIRToolingClient

use of org.hl7.fhir.r4.utils.client.FHIRToolingClient in project org.hl7.fhir.core by hapifhir.

the class SimpleWorkerContext method connectToTSServer.

public String connectToTSServer(String url, String userAgent) throws URISyntaxException {
    txServer = new FHIRToolingClient(url, userAgent);
    txServer.setTimeout(30000);
    return txServer.getCapabilitiesStatementQuick().getSoftware().getVersion();
}
Also used : FHIRToolingClient(org.hl7.fhir.dstu3.utils.client.FHIRToolingClient)

Aggregations

FileInputStream (java.io.FileInputStream)3 File (java.io.File)2 Date (java.util.Date)2 FHIRToolingClient (org.hl7.fhir.dstu3.utils.client.FHIRToolingClient)2 JsonParser (org.hl7.fhir.r4.formats.JsonParser)2 FHIRToolingClient (org.hl7.fhir.r4.utils.client.FHIRToolingClient)2 IniFile (org.hl7.fhir.utilities.IniFile)2 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1 ParseException (java.text.ParseException)1 Bundle (org.hl7.fhir.dstu2.model.Bundle)1 BundleEntryComponent (org.hl7.fhir.dstu2.model.Bundle.BundleEntryComponent)1 FHIRToolingClient (org.hl7.fhir.dstu2.utils.client.FHIRToolingClient)1 Bundle (org.hl7.fhir.dstu2016may.model.Bundle)1 BundleEntryComponent (org.hl7.fhir.dstu2016may.model.Bundle.BundleEntryComponent)1 FHIRToolingClient (org.hl7.fhir.dstu2016may.utils.client.FHIRToolingClient)1 IParser (org.hl7.fhir.dstu3.formats.IParser)1 JsonParser (org.hl7.fhir.dstu3.formats.JsonParser)1 XmlParser (org.hl7.fhir.dstu3.formats.XmlParser)1