use of org.hl7.fhir.dstu3.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");
}
use of org.hl7.fhir.dstu3.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;
}
use of org.hl7.fhir.dstu3.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);
}
}
}
}
use of org.hl7.fhir.dstu3.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;
}
use of org.hl7.fhir.dstu3.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();
}
Aggregations