Search in sources :

Example 36 with Source

use of org.hl7.fhir.utilities.validation.ValidationMessage.Source in project org.hl7.fhir.core by hapifhir.

the class R2R3ConversionManager method main.

public static void main(String[] args) throws IOException, FHIRException {
    if (args.length == 0 || !hasParam(args, "-d2") || !hasParam(args, "-d3") || !hasParam(args, "-maps") || !hasParam(args, "-src") || !hasParam(args, "-dest") || (!hasParam(args, "-r2") && !hasParam(args, "-r3"))) {
        System.out.println("R2 <--> R3 Convertor");
        System.out.println("====================");
        System.out.println();
        System.out.println("parameters: -d2 [r2 definitions] -d3 [r3 definitions] -maps [map source] -src [source] -dest [dest] -r2/3 - fmt [format]");
        System.out.println();
        System.out.println("d2: definitions from http://hl7.org/fhir/DSTU2/downloads.html");
        System.out.println("d3: definitions from http://hl7.org/fhir/STU3/downloads.html");
        System.out.println("maps: R2/R3 maps from http://hl7.org/fhir/r2r3maps.zip");
        System.out.println("src: filename for source to convert");
        System.out.println("dest: filename for destination of conversion");
        System.out.println("-r2: source is r2, convert to r3");
        System.out.println("-r3: source is r3, convert to r2");
        System.out.println("-fmt: xml | json (xml is default)");
    } else {
        R2R3ConversionManager self = new R2R3ConversionManager();
        self.setR2Definitions(getNamedParam(args, "-d2"));
        self.setR3Definitions(getNamedParam(args, "-d3"));
        self.setMappingLibrary(getNamedParam(args, "-maps"));
        FhirFormat fmt = hasParam(args, "-fmt") ? getNamedParam(args, "-fmt").equalsIgnoreCase("json") ? FhirFormat.JSON : FhirFormat.XML : FhirFormat.XML;
        InputStream src = new FileInputStream(getNamedParam(args, "-src"));
        OutputStream dst = new FileOutputStream(getNamedParam(args, "-dest"));
        self.convert(src, dst, hasParam(args, "-r2"), fmt);
    }
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) FhirFormat(org.hl7.fhir.dstu3.elementmodel.Manager.FhirFormat)

Example 37 with Source

use of org.hl7.fhir.utilities.validation.ValidationMessage.Source 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 38 with Source

use of org.hl7.fhir.utilities.validation.ValidationMessage.Source in project org.hl7.fhir.core by hapifhir.

the class PhinVadsImporter method importValueSet.

private ValueSet importValueSet(byte[] source) throws FHIRException, IOException, ParseException {
    // first thing do is split into 2
    List<byte[]> parts = Utilities.splitBytes(source, "\r\n\r\n".getBytes());
    if (parts.size() < 2) {
        TextFile.bytesToFile(source, Utilities.path("[tmp]", "phinvads.txt"));
        throw new FHIRException("Unable to parse phinvads value set: " + parts.size() + " parts found");
    }
    CSVReader rdr = new CSVReader(new ByteArrayInputStream(parts.get(0)));
    rdr.setDelimiter('\t');
    rdr.setMultiline(true);
    rdr.readHeaders();
    rdr.line();
    ValueSet vs = new ValueSet();
    vs.setId(rdr.cell("Value Set OID"));
    vs.setUrl("http://phinvads.cdc.gov/fhir/ValueSet/" + vs.getId());
    vs.getMeta().setSource("https://phinvads.cdc.gov/vads/ViewValueSet.action?oid=" + vs.getId());
    vs.setVersion(rdr.cell("Value Set Version"));
    vs.setTitle(rdr.cell("Value Set Name"));
    vs.setName(rdr.cell("Value Set Code"));
    vs.setDescription(rdr.cell("Value Set Definition"));
    if ("Published".equals(rdr.cell("Value Set Status"))) {
        vs.setStatus(PublicationStatus.ACTIVE);
    } else {
        vs.setStatus(PublicationStatus.DRAFT);
    }
    if (rdr.has("VS Last Updated Date")) {
        vs.setDate(new SimpleDateFormat("mm/dd/yyyy").parse(rdr.cell("VS Last Updated Date")));
    }
    rdr = new CSVReader(new ByteArrayInputStream(parts.get(parts.size() - 1)));
    rdr.setMultiline(true);
    rdr.setDelimiter('\t');
    rdr.readHeaders();
    while (rdr.line()) {
        String code = rdr.cell("Concept Code");
        String display = rdr.cell("Preferred Concept Name");
        String csoid = rdr.cell("Code System OID");
        String csver = rdr.cell("Code System Version");
        String url = context.oid2Uri(csoid);
        if (url == null) {
            url = "urn:oid:" + csoid;
        }
        csver = fixVersionforSystem(url, csver);
        ConceptSetComponent inc = getInclude(vs, url, csver);
        inc.addConcept().setCode(code).setDisplay(display);
    }
    return vs;
}
Also used : ConceptSetComponent(org.hl7.fhir.r5.model.ValueSet.ConceptSetComponent) CSVReader(org.hl7.fhir.utilities.CSVReader) ByteArrayInputStream(java.io.ByteArrayInputStream) FHIRException(org.hl7.fhir.exceptions.FHIRException) ValueSet(org.hl7.fhir.r5.model.ValueSet) SimpleDateFormat(java.text.SimpleDateFormat)

Example 39 with Source

use of org.hl7.fhir.utilities.validation.ValidationMessage.Source 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 40 with Source

use of org.hl7.fhir.utilities.validation.ValidationMessage.Source in project org.hl7.fhir.core by hapifhir.

the class ExamplesPackageBuilder method process.

private void process(String source) throws FHIRFormatError, FileNotFoundException, IOException {
    Set<String> set = new HashSet<>();
    for (File f : new File(source).listFiles()) {
        if (f.getName().endsWith(".json")) {
            JsonObject obj = JsonTrackingParser.parseJson(new FileInputStream(f));
            if (obj.has("resourceType") && obj.has("id")) {
                String type = obj.get("resourceType").getAsString();
                String id = obj.get("id").getAsString();
                byte[] content = TextFile.fileToBytes(f);
                if (type.equals("ConceptMap")) {
                    System.out.println("convert " + f.getName());
                    content = r5ToR4B(content);
                    TextFile.bytesToFile(content, f);
                }
            // TextFile.bytesToFile(content, Utilities.path(dest2, type+"-"+id+".json"));
            // if (!set.contains(type+"/"+id)) {
            // set.add(type+"/"+id);
            // pck.addFile(Category.RESOURCE, type+"-"+id+".json", content);
            // }
            }
        }
    }
// pck.finish();
// 
}
Also used : JsonObject(com.google.gson.JsonObject) File(java.io.File) TextFile(org.hl7.fhir.utilities.TextFile) FileInputStream(java.io.FileInputStream) HashSet(java.util.HashSet)

Aggregations

FHIRException (org.hl7.fhir.exceptions.FHIRException)125 FileInputStream (java.io.FileInputStream)59 FileOutputStream (java.io.FileOutputStream)55 IOException (java.io.IOException)55 ArrayList (java.util.ArrayList)48 File (java.io.File)45 CSFileInputStream (org.hl7.fhir.utilities.CSFileInputStream)45 TextFile (org.hl7.fhir.utilities.TextFile)41 CSFile (org.hl7.fhir.utilities.CSFile)35 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)35 Complex (org.hl7.fhir.r4.utils.formats.Turtle.Complex)30 XmlParser (org.hl7.fhir.r5.formats.XmlParser)28 Date (java.util.Date)27 HashMap (java.util.HashMap)26 Reference (org.hl7.fhir.r4.model.Reference)26 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)24 FHIRFormatError (org.hl7.fhir.exceptions.FHIRFormatError)24 Coding (org.hl7.fhir.r4.model.Coding)24 JsonObject (com.google.gson.JsonObject)22 NotImplementedException (org.apache.commons.lang3.NotImplementedException)22