Search in sources :

Example 96 with ValueSet

use of org.hl7.fhir.dstu2016may.model.ValueSet in project org.hl7.fhir.core by hapifhir.

the class SpecDifferenceEvaluator method compareBindings.

private boolean compareBindings(JsonObject element, ElementDefinitionBindingComponent rev, ElementDefinitionBindingComponent orig) {
    boolean res = false;
    if (rev.getStrength() != orig.getStrength()) {
        element.addProperty("binding-strength-changed", true);
        res = true;
    }
    if (!Base.compareDeep(rev.getValueSet(), orig.getValueSet(), false)) {
        element.addProperty("binding-valueset-changed", true);
        res = true;
    }
    if (!maxValueSetsMatch(rev, orig)) {
        element.addProperty("max-valueset-changed", true);
        res = true;
    }
    if (rev.getStrength() == BindingStrength.REQUIRED && orig.getStrength() == BindingStrength.REQUIRED) {
        JsonArray oa = new JsonArray();
        JsonArray ra = new JsonArray();
        ValueSet vrev = getValueSet(rev.getValueSet(), revision.getExpansions());
        ValueSet vorig = getValueSet(rev.getValueSet(), original.getExpansions());
        if (vrev != null && vorig != null) {
            for (ValueSetExpansionContainsComponent cc : vorig.getExpansion().getContains()) {
                if (!hasCode(vrev, cc))
                    oa.add(new JsonPrimitive(cc.getCode()));
            }
            for (ValueSetExpansionContainsComponent cc : vrev.getExpansion().getContains()) {
                if (!hasCode(vorig, cc))
                    ra.add(new JsonPrimitive(cc.getCode()));
            }
        }
        if (oa.size() > 0 || ra.size() > 0) {
            element.addProperty("binding-codes-changed", true);
            res = true;
        }
        if (oa.size() > 0)
            element.add("removed-codes", oa);
        if (ra.size() > 0)
            element.add("added-codes", ra);
    }
    return res;
}
Also used : JsonArray(com.google.gson.JsonArray) ValueSetExpansionContainsComponent(org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionContainsComponent) JsonPrimitive(com.google.gson.JsonPrimitive)

Example 97 with ValueSet

use of org.hl7.fhir.dstu2016may.model.ValueSet in project org.hl7.fhir.core by hapifhir.

the class PackageMaintainer method check.

private void check(String ver) throws IOException {
    System.out.println("Check " + ver);
    List<String> allIds = listResources(Utilities.path(PATH, "hl7.fhir." + ver + ".examples", "package"));
    List<String> coreIds = listResources(Utilities.path(PATH, "hl7.fhir." + ver + ".core", "package"));
    for (String s : coreIds) {
        if (!allIds.contains(s)) {
            System.out.println("Core contains " + s + " but allIds doesn't");
        }
    }
    for (String s : allIds) {
        if (!coreIds.contains(s)) {
            String c = s.substring(0, s.indexOf("-"));
            if (Utilities.existsInList(c, "CodeSystem", "ValueSet", "ConceptMap", "StructureDefinition", "StructureMap", "NamingSystem", "SearchParameter", "OperationDefinition", "CapabilityStatement", "Conformance"))
                System.out.println("Examples contains " + s + " but core doesn't");
        }
    }
    strip(new File(Utilities.path(PATH, "hl7.fhir." + ver + ".core", "package")));
    strip(new File(Utilities.path(PATH, "hl7.fhir." + ver + ".expansions", "package")));
    if (!ver.equals("r2b"))
        strip(new File(Utilities.path(PATH, "hl7.fhir." + ver + ".elements", "package")));
}
Also used : TextFile(org.hl7.fhir.utilities.TextFile) File(java.io.File)

Example 98 with ValueSet

use of org.hl7.fhir.dstu2016may.model.ValueSet 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 99 with ValueSet

use of org.hl7.fhir.dstu2016may.model.ValueSet 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 100 with ValueSet

use of org.hl7.fhir.dstu2016may.model.ValueSet 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)

Aggregations

ValueSet (org.hl7.fhir.r5.model.ValueSet)159 ValueSet (org.hl7.fhir.r4.model.ValueSet)115 Test (org.junit.jupiter.api.Test)115 ArrayList (java.util.ArrayList)101 FHIRException (org.hl7.fhir.exceptions.FHIRException)100 IOException (java.io.IOException)97 ValueSet (org.hl7.fhir.dstu3.model.ValueSet)59 ValueSet (org.hl7.fhir.r4b.model.ValueSet)59 FileNotFoundException (java.io.FileNotFoundException)58 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)56 TerminologyServiceException (org.hl7.fhir.exceptions.TerminologyServiceException)46 HashMap (java.util.HashMap)45 Test (org.junit.Test)45 CodeSystem (org.hl7.fhir.r5.model.CodeSystem)43 File (java.io.File)36 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)36 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)31 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)29 RestIntegrationTest (org.opencds.cqf.ruler.test.RestIntegrationTest)29 FileInputStream (java.io.FileInputStream)27