Search in sources :

Example 21 with JsonParser

use of org.hl7.fhir.r4b.formats.JsonParser in project org.hl7.fhir.core by hapifhir.

the class PhinVadsImporter method process.

private void process(String source, String dest) {
    for (File f : new File(source).listFiles()) {
        try {
            System.out.println("Process " + f.getName());
            ValueSet vs = importValueSet(TextFile.fileToBytes(f));
            if (vs.getId() != null) {
                new JsonParser().compose(new FileOutputStream(Utilities.path(dest, "ValueSet-" + vs.getId() + ".json")), vs);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) File(java.io.File) TextFile(org.hl7.fhir.utilities.TextFile) ValueSet(org.hl7.fhir.r5.model.ValueSet) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException) ParseException(java.text.ParseException) JsonParser(org.hl7.fhir.r5.formats.JsonParser)

Example 22 with JsonParser

use of org.hl7.fhir.r4b.formats.JsonParser 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 23 with JsonParser

use of org.hl7.fhir.r4b.formats.JsonParser in project org.hl7.fhir.core by hapifhir.

the class Convertor_Factory_40_50Test method convertBundleContainingAccountsToTestPathing.

@Test
void convertBundleContainingAccountsToTestPathing() throws IOException {
    JsonParser r4parser = new JsonParser();
    org.hl7.fhir.r5.formats.JsonParser r5parser = new org.hl7.fhir.r5.formats.JsonParser();
    InputStream accountr4InputStream = this.getClass().getResourceAsStream("/bundle_of_accounts_path_test_r4.json");
    org.hl7.fhir.r4.model.Bundle bundle_r4 = (org.hl7.fhir.r4.model.Bundle) r4parser.parse(accountr4InputStream);
    Resource account_r5 = VersionConvertorFactory_40_50.convertResource(bundle_r4);
    System.out.println(r5parser.composeString(account_r5));
}
Also used : InputStream(java.io.InputStream) org.hl7.fhir.r5.model(org.hl7.fhir.r5.model) JsonParser(org.hl7.fhir.r4.formats.JsonParser) Test(org.junit.jupiter.api.Test)

Example 24 with JsonParser

use of org.hl7.fhir.r4b.formats.JsonParser in project org.hl7.fhir.core by hapifhir.

the class Convertor_Factory_40_50Test method convertResource.

@Test
void convertResource() throws IOException {
    JsonParser r4parser = new JsonParser();
    org.hl7.fhir.r5.formats.JsonParser r5parser = new org.hl7.fhir.r5.formats.JsonParser();
    InputStream accountr4InputStream = this.getClass().getResourceAsStream("/account_r4.json");
    org.hl7.fhir.r4.model.Account account_r4 = (org.hl7.fhir.r4.model.Account) r4parser.parse(accountr4InputStream);
    Resource account_r5 = VersionConvertorFactory_40_50.convertResource(account_r4);
    System.out.println(r5parser.composeString(account_r5));
}
Also used : InputStream(java.io.InputStream) org.hl7.fhir.r5.model(org.hl7.fhir.r5.model) JsonParser(org.hl7.fhir.r4.formats.JsonParser) Test(org.junit.jupiter.api.Test)

Example 25 with JsonParser

use of org.hl7.fhir.r4b.formats.JsonParser in project org.hl7.fhir.core by hapifhir.

the class UTGCaseSensitivePopulator method scanFolders.

private void scanFolders(File folder, Bundle bundle) throws FileNotFoundException, IOException {
    Calendar today = Calendar.getInstance();
    Date dt = today.getTime();
    today.set(Calendar.HOUR_OF_DAY, 0);
    Date d = today.getTime();
    System.out.println("Scan " + folder.getAbsolutePath());
    for (File f : folder.listFiles()) {
        if (f.isDirectory() && !f.getName().equals("retired")) {
            scanFolders(f, bundle);
        } else if (f.getName().endsWith(".xml")) {
            processFile(f, bundle, new XmlParser(), d, dt);
        } else if (f.getName().endsWith(".json")) {
            processFile(f, bundle, new JsonParser(), d, dt);
        }
    }
}
Also used : XmlParser(org.hl7.fhir.r4.formats.XmlParser) Calendar(java.util.Calendar) File(java.io.File) Date(java.util.Date) LocalDate(java.time.LocalDate) JsonParser(org.hl7.fhir.r4.formats.JsonParser)

Aggregations

FileOutputStream (java.io.FileOutputStream)82 JsonParser (org.hl7.fhir.r5.formats.JsonParser)66 FHIRException (org.hl7.fhir.exceptions.FHIRException)58 FileInputStream (java.io.FileInputStream)53 IOException (java.io.IOException)49 XmlParser (org.hl7.fhir.r5.formats.XmlParser)44 ByteArrayOutputStream (java.io.ByteArrayOutputStream)41 File (java.io.File)36 JsonParser (org.hl7.fhir.r4.formats.JsonParser)35 CSFileInputStream (org.hl7.fhir.utilities.CSFileInputStream)29 JsonParser (org.hl7.fhir.dstu3.formats.JsonParser)26 JsonParser (org.hl7.fhir.r4b.formats.JsonParser)26 CSFile (org.hl7.fhir.utilities.CSFile)26 ArrayList (java.util.ArrayList)23 TextFile (org.hl7.fhir.utilities.TextFile)20 InputStream (java.io.InputStream)18 IParser (org.hl7.fhir.r5.formats.IParser)18 Resource (org.hl7.fhir.dstu3.model.Resource)17 FileNotFoundException (java.io.FileNotFoundException)16 Resource (org.hl7.fhir.r4.model.Resource)16