Search in sources :

Example 76 with Server

use of org.hl7.gravity.refimpl.sdohexchange.model.Server in project ab2d by CMSgov.

the class CapabilityStatementR4 method populateCS.

public static CapabilityStatement populateCS(String server) {
    SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
    CapabilityStatement cs = new CapabilityStatement();
    cs.setPublisher("Centers for Medicare & Medicaid Services");
    cs.setKind(CapabilityStatement.CapabilityStatementKind.REQUIREMENTS);
    cs.setStatus(Enumerations.PublicationStatus.DRAFT);
    try {
        Date lastUpdated = sdf.parse("02/22/2020 00:00:00");
        cs.setDate(lastUpdated);
    } catch (Exception ex) {
        cs.setDate(new Date());
    }
    cs.setFhirVersion(Enumerations.FHIRVersion._4_0_0);
    cs.setPurpose("Defines FHIR R4 (V2) version of AB2D bulk data download");
    CodeType codeType = new CodeType();
    codeType.setValue(APPLICATION_JSON);
    CodeType codeType2 = new CodeType();
    codeType2.setValue("application/fhir+json");
    cs.setFormat(List.of(codeType, codeType2));
    CapabilityStatement.CapabilityStatementSoftwareComponent cssc = new CapabilityStatement.CapabilityStatementSoftwareComponent();
    cssc.setName("AB2D");
    cssc.setVersion("V2");
    try {
        Date releaseDate = sdf.parse("05/01/2020 00:00:00");
        cssc.setReleaseDate(releaseDate);
    } catch (Exception ex) {
        cssc.setReleaseDate(new Date());
    }
    cs.setSoftware(cssc);
    CapabilityStatement.CapabilityStatementImplementationComponent implementation = new CapabilityStatement.CapabilityStatementImplementationComponent();
    implementation.setDescription("AB2D FHIR R4 Bulk Data Download Implementation");
    implementation.setUrl(server);
    cs.setImplementation(implementation);
    CapabilityStatement.CapabilityStatementRestComponent rest = new CapabilityStatement.CapabilityStatementRestComponent();
    rest.setMode(CapabilityStatement.RestfulCapabilityMode.SERVER);
    CapabilityStatement.CapabilityStatementRestSecurityComponent security = new CapabilityStatement.CapabilityStatementRestSecurityComponent();
    security.setCors(true);
    CodeableConcept codeableConcept = new CodeableConcept();
    Coding coding = new Coding();
    coding.setSystem("http://hl7.org/fhir/ValueSet/restful-security-service");
    coding.setCode("OAuth");
    coding.setDisplay("OAuth");
    codeableConcept.setCoding(List.of(coding));
    codeableConcept.setText("OAuth");
    security.setService(List.of(codeableConcept));
    rest.setSecurity(security);
    List<CapabilityStatement.CapabilityStatementRestResourceOperationComponent> restComponents = new ArrayList<>();
    restComponents.add(createOperation("export", server + "/Patient/$export"));
    restComponents.add(createOperation("export by contract", server + "/Group/{contractNumber}/$export"));
    restComponents.add(createOperation("cancel", server + "/Job/{jobUuid}/$status"));
    restComponents.add(createOperation("status", server + "/Job/{jobUuid}/$status"));
    restComponents.add(createOperation("download", server + "/Job/{jobUuid}/file/{filename}"));
    restComponents.add(createOperation("capability", server + "/metadata"));
    rest.setOperation(restComponents);
    rest.setInteraction(List.of(new CapabilityStatement.SystemInteractionComponent().setCode(CapabilityStatement.SystemRestfulInteraction.BATCH)));
    cs.setRest(List.of(rest));
    return cs;
}
Also used : ArrayList(java.util.ArrayList) Date(java.util.Date) Coding(org.hl7.fhir.r4.model.Coding) CapabilityStatement(org.hl7.fhir.r4.model.CapabilityStatement) CodeType(org.hl7.fhir.r4.model.CodeType) SimpleDateFormat(java.text.SimpleDateFormat) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept)

Example 77 with Server

use of org.hl7.gravity.refimpl.sdohexchange.model.Server in project org.hl7.fhir.core by hapifhir.

the class BatchLoader method LoadZipFile.

private static void LoadZipFile(String server, String file, IParser p, int size, int start, int end) throws IOException, Exception {
    System.out.println("Load Zip file " + file);
    Bundle b = new Bundle();
    b.setType(BundleType.COLLECTION);
    b.setId(UUID.randomUUID().toString().toLowerCase());
    ZipInputStream zip = new ZipInputStream(new FileInputStream(file));
    ZipEntry entry;
    while ((entry = zip.getNextEntry()) != null) {
        try {
            Resource r = p.parse(zip);
            b.addEntry().setResource(r);
        } catch (Exception e) {
            throw new Exception("Error parsing " + entry.getName() + ": " + e.getMessage(), e);
        }
    }
    loadBundle(server, b, size, start, end);
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) Bundle(org.hl7.fhir.dstu2.model.Bundle) ZipEntry(java.util.zip.ZipEntry) Resource(org.hl7.fhir.dstu2.model.Resource) FileInputStream(java.io.FileInputStream) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 78 with Server

use of org.hl7.gravity.refimpl.sdohexchange.model.Server in project org.hl7.fhir.core by hapifhir.

the class BatchLoader method main.

public static void main(String[] args) throws IOException, Exception {
    if (args.length < 4) {
        System.out.println("Batch uploader takes 4 parameters in order: server base url, file/folder to upload, xml/json, and batch size");
    } else {
        String server = args[0];
        String file = args[1];
        // args[2].equals("json") ? new JsonParser() : new XmlParser();
        IParser p = new JsonParser();
        int size = Integer.parseInt(args[3]);
        size = 500;
        if (file.endsWith(".xml")) {
            throw new FHIRException("Unimplemented file type " + file);
        } else if (file.endsWith(".json")) {
            throw new FHIRException("Unimplemented file type " + file);
        } else if (file.endsWith(".zip")) {
            LoadZipFile(server, file, p, size, 0, -1);
        } else if (new File(file).isDirectory()) {
            LoadDirectory(server, file, p, size);
        } else
            throw new FHIRException("Unknown file type " + file);
    }
}
Also used : FHIRException(org.hl7.fhir.exceptions.FHIRException) File(java.io.File) IParser(org.hl7.fhir.dstu2.formats.IParser) JsonParser(org.hl7.fhir.dstu2.formats.JsonParser)

Example 79 with Server

use of org.hl7.gravity.refimpl.sdohexchange.model.Server 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 80 with Server

use of org.hl7.gravity.refimpl.sdohexchange.model.Server in project org.hl7.fhir.core by hapifhir.

the class BatchLoader method LoadZipFile.

private static void LoadZipFile(String server, String file, IParser p, int size, int start, int end) throws IOException, Exception {
    System.out.println("Load Zip file " + file);
    Bundle b = new Bundle();
    b.setType(BundleType.COLLECTION);
    b.setId(UUID.randomUUID().toString().toLowerCase());
    ZipInputStream zip = new ZipInputStream(new FileInputStream(file));
    ZipEntry entry;
    while ((entry = zip.getNextEntry()) != null) {
        try {
            Resource r = p.parse(zip);
            b.addEntry().setResource(r);
        } catch (Exception e) {
            throw new Exception("Error parsing " + entry.getName() + ": " + e.getMessage(), e);
        }
    }
    loadBundle(server, b, size, start, end);
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) Bundle(org.hl7.fhir.dstu2016may.model.Bundle) ZipEntry(java.util.zip.ZipEntry) Resource(org.hl7.fhir.dstu2016may.model.Resource) FileInputStream(java.io.FileInputStream) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Aggregations

Test (org.junit.Test)107 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)100 IOException (java.io.IOException)47 OperationOutcome (org.hl7.fhir.r4.model.OperationOutcome)42 FHIRException (org.hl7.fhir.exceptions.FHIRException)39 OperationOutcome (org.hl7.fhir.dstu3.model.OperationOutcome)38 ArrayList (java.util.ArrayList)25 BaseFhirIntegrationTest (org.openmrs.module.fhir2.BaseFhirIntegrationTest)24 FileNotFoundException (java.io.FileNotFoundException)21 TerminologyServiceException (org.hl7.fhir.exceptions.TerminologyServiceException)19 Date (java.util.Date)18 Bundle (org.hl7.fhir.r4.model.Bundle)17 URISyntaxException (java.net.URISyntaxException)16 HashMap (java.util.HashMap)16 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)16 FhirContext (ca.uhn.fhir.context.FhirContext)14 LocalDate (java.time.LocalDate)14 NoTerminologyServiceException (org.hl7.fhir.exceptions.NoTerminologyServiceException)13 File (java.io.File)12 Header (org.apache.http.Header)11