Search in sources :

Example 1 with CSVReader

use of org.hl7.fhir.utilities.CSVReader 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 2 with CSVReader

use of org.hl7.fhir.utilities.CSVReader 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 3 with CSVReader

use of org.hl7.fhir.utilities.CSVReader in project org.hl7.fhir.core by hapifhir.

the class IEEE11073Convertor method generateLoincMdcMap.

private static ConceptMap generateLoincMdcMap(CodeSystem mdc, String dst, String src) throws IOException, FHIRException {
    ConceptMap cm = new ConceptMap();
    cm.setId("loinc-mdc");
    cm.setUrl("http:/???/fhir/ConceptMap/loinc-mdc");
    cm.setVersion("[todo]");
    cm.setName("LoincMdcCrossMap");
    cm.setTitle("Cross Map between LOINC and MDC");
    cm.setStatus(PublicationStatus.DRAFT);
    cm.setExperimental(true);
    cm.setDateElement(new DateTimeType());
    cm.setPublisher("HL7, Inc");
    ContactDetail cd = cm.addContact();
    cd.setName("LOINC + IEEE");
    ContactPoint cp = cd.addTelecom();
    cp.setSystem(ContactPointSystem.URL);
    cp.setValue("http://loinc.org");
    cm.setDescription("A Cross Map between the LOINC and MDC Code systems");
    cm.setPurpose("To implementers map between medical device codes and LOINC codes");
    cm.setCopyright("This content LOINC \u00ae is copyright \u00a9 1995 Regenstrief Institute, Inc. and the LOINC Committee, and available at no cost under the license at http://loinc.org/terms-of-use");
    cm.setSource(new UriType("http://loinc.org/vs"));
    cm.setTarget(new UriType(MDC_ALL_VALUES));
    ConceptMapGroupComponent g = cm.addGroup();
    g.setSource("urn:iso:std:iso:11073:10101");
    g.setTarget("http://loinc.org");
    CSVReader csv = new CSVReader(new FileInputStream(src));
    csv.readHeaders();
    while (csv.line()) {
        SourceElementComponent e = g.addElement();
        e.setCode(csv.cell("IEEE_CF_CODE10"));
        e.setDisplay(csv.cell("IEEE_DESCRIPTION"));
        TargetElementComponent t = e.addTarget();
        t.setEquivalence(ConceptMapEquivalence.EQUIVALENT);
        t.setCode(csv.cell("LOINC_NUM"));
        t.setDisplay(csv.cell("LOINC_LONG_COMMON_NAME"));
    }
    new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path(dst, "conceptmap-" + cm.getId() + ".xml")), cm);
    System.out.println("Done");
    return cm;
}
Also used : XmlParser(org.hl7.fhir.dstu3.formats.XmlParser) CSVReader(org.hl7.fhir.utilities.CSVReader) FileOutputStream(java.io.FileOutputStream) TargetElementComponent(org.hl7.fhir.dstu3.model.ConceptMap.TargetElementComponent) ConceptMapGroupComponent(org.hl7.fhir.dstu3.model.ConceptMap.ConceptMapGroupComponent) FileInputStream(java.io.FileInputStream) SourceElementComponent(org.hl7.fhir.dstu3.model.ConceptMap.SourceElementComponent)

Example 4 with CSVReader

use of org.hl7.fhir.utilities.CSVReader in project org.hl7.fhir.core by hapifhir.

the class IEEE11073Convertor method generateMDC.

public static CodeSystem generateMDC(String src, String dst, UcumService ucum) throws IOException, FHIRException {
    CSVReader csv = new CSVReader(new FileInputStream(src));
    csv.readHeaders();
    CodeSystem cs = new CodeSystem();
    Map<String, String> ucumIssues = new HashMap<String, String>();
    int errorCount = 0;
    cs.setId("MDC");
    cs.setUrl("urn:iso:std:iso:11073:10101");
    cs.setVersion("[todo]");
    cs.setName("11073:10101 codes for the FHIR community");
    cs.setStatus(PublicationStatus.ACTIVE);
    cs.setExperimental(false);
    cs.setDateElement(new DateTimeType());
    cs.setPublisher("HL7 (FHIR Project)");
    ContactDetail cd = cs.addContact();
    ContactPoint cp = cd.addTelecom();
    cp.setSystem(ContactPointSystem.URL);
    cp.setValue("http://ieee?");
    cs.setDescription("1073 Codes for the FHIR community (generated from the Rosetta data");
    Identifier i = new Identifier();
    cs.setIdentifier(i);
    i.setSystem("urn:ietf:rfc:3986");
    i.setValue("urn:oid:2.16.840.1.113883.6.24");
    cs.setCaseSensitive(false);
    cs.setContent(CodeSystemContentMode.COMPLETE);
    cs.addProperty().setCode("ucum").setDescription("UCUM units associated with Concept").setType(PropertyType.STRING);
    cs.addProperty().setCode("unit").setDescription("MDC units associated with Concept").setType(PropertyType.STRING);
    cs.addProperty().setCode("refid").setDescription("MDC Reference Id for Concept").setType(PropertyType.CODE);
    Set<String> codes = new HashSet<String>();
    while (csv.line()) {
        if (csv.has("CF_CODE10")) {
            String code = csv.cell("CF_CODE10");
            if (codes.contains(code))
                System.out.println("Duplicate Code " + code);
            else {
                codes.add(code);
                ConceptDefinitionComponent c = cs.addConcept();
                c.setCode(code);
                c.setDisplay(csv.cell("Common Term"));
                c.setDefinition(csv.cell("Term Description"));
                String vd = csv.cell("Vendor_Description");
                if (!c.hasDefinition())
                    c.setDefinition(vd);
                if (!c.hasDisplay())
                    c.setDisplay(vd);
                String refid = csv.cell("REFID");
                c.addProperty().setCode("refid").setValue(new CodeType().setValue(refid));
                if (csv.has("Synonym"))
                    c.addDesignation().setValue(csv.cell("Synonym")).setUse(new Coding().setSystem("http://hl7.org/fhir/designation-use").setCode("synonym"));
                if (csv.has("Acronym"))
                    c.addDesignation().setValue(csv.cell("Acronym")).setUse(new Coding().setSystem("http://hl7.org/fhir/designation-use").setDisplay("acronym"));
                if (csv.has("Systematic Name")) {
                    String sysName = csv.cell("Systematic Name");
                    if (!c.hasDefinition())
                        c.setDefinition(sysName);
                    c.addDesignation().setValue(sysName).setUse(new Coding().setSystem("http://hl7.org/fhir/designation-use").setCode("structured-name"));
                }
                if (csv.has("UOM_MDC"))
                    c.addProperty().setCode("unit").setValue(new StringType().setValue(csv.cell("UOM_MDC")));
                if (csv.has("UOM_UCUM")) {
                    CommaSeparatedStringBuilder ul = new CommaSeparatedStringBuilder();
                    for (String u : csv.cell("UOM_UCUM").split(" ")) {
                        String msg = ucum.validate(u);
                        if (msg != null) {
                            errorCount++;
                            ucumIssues.put(u, msg);
                        } else
                            ul.append(u);
                    }
                    if (ul.length() > 0)
                        c.addProperty().setCode("ucum").setValue(new StringType().setValue(ul.toString()));
                }
            }
        }
    }
    csv.close();
    new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path(dst, "codesystem-" + cs.getId() + ".xml")), cs);
    System.out.println(errorCount + "UCUM errors");
    for (String u : sorted(ucumIssues.keySet())) System.out.println("Invalid UCUM code: " + u + " because " + ucumIssues.get(u));
    return cs;
}
Also used : XmlParser(org.hl7.fhir.dstu3.formats.XmlParser) CSVReader(org.hl7.fhir.utilities.CSVReader) CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) FileInputStream(java.io.FileInputStream) ConceptDefinitionComponent(org.hl7.fhir.dstu3.model.CodeSystem.ConceptDefinitionComponent) FileOutputStream(java.io.FileOutputStream)

Example 5 with CSVReader

use of org.hl7.fhir.utilities.CSVReader in project org.hl7.fhir.core by hapifhir.

the class MappingSheetParser method parse.

public void parse(InputStream stream, String name) throws FHIRException, IOException {
    CSVReader csv = new CSVReader(stream);
    checkHeaders1(csv, name);
    checkHeaders2(csv, name);
    while (csv.line()) {
        processRow(csv);
    }
}
Also used : CSVReader(org.hl7.fhir.utilities.CSVReader)

Aggregations

CSVReader (org.hl7.fhir.utilities.CSVReader)8 FileInputStream (java.io.FileInputStream)5 FileOutputStream (java.io.FileOutputStream)4 XmlParser (org.hl7.fhir.dstu3.formats.XmlParser)2 FHIRException (org.hl7.fhir.exceptions.FHIRException)2 JsonParser (org.hl7.fhir.r4.formats.JsonParser)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1 ParseException (java.text.ParseException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ConceptDefinitionComponent (org.hl7.fhir.dstu3.model.CodeSystem.ConceptDefinitionComponent)1 ConceptMapGroupComponent (org.hl7.fhir.dstu3.model.ConceptMap.ConceptMapGroupComponent)1 SourceElementComponent (org.hl7.fhir.dstu3.model.ConceptMap.SourceElementComponent)1 TargetElementComponent (org.hl7.fhir.dstu3.model.ConceptMap.TargetElementComponent)1 CodeSystem (org.hl7.fhir.r4.model.CodeSystem)1 DateTimeType (org.hl7.fhir.r4.model.DateTimeType)1 ValueSet (org.hl7.fhir.r4.model.ValueSet)1 FHIRToolingClient (org.hl7.fhir.r4.utils.client.FHIRToolingClient)1 ValueSet (org.hl7.fhir.r5.model.ValueSet)1