Search in sources :

Example 11 with IWorkerContext

use of org.hl7.fhir.r4b.context.IWorkerContext in project org.hl7.fhir.core by hapifhir.

the class Tester method main.

public static void main(String[] args) throws Exception {
    IWorkerContext context = SimpleWorkerContext.fromPack(Utilities.path("C:\\work\\org.hl7.fhir\\build\\publish", "validation-min.xml.zip"));
    int t = 0;
    int ok = 0;
    for (String f : new File("C:\\work\\org.hl7.fhir\\build\\publish").list()) {
        if (f.endsWith(".xml") && !f.endsWith(".canonical.xml") && !f.contains("profile") && !f.contains("questionnaire") && new File("C:\\work\\org.hl7.fhir\\build\\publish\\" + Utilities.changeFileExt(f, ".ttl")).exists()) {
            // if (f.equals("account-questionnaire.xml")) {
            System.out.print("convert " + f);
            // Manager.convert(context, new FileInputStream("C:\\work\\org.hl7.fhir\\build\\publish\\"+f), FhirFormat.XML,
            // new FileOutputStream("C:\\work\\org.hl7.fhir\\build\\publish\\"+Utilities.changeFileExt(f, ".mm.json")), FhirFormat.JSON, OutputStyle.PRETTY);
            // String src = normalise(TextFile.fileToString("C:\\work\\org.hl7.fhir\\build\\publish\\"+Utilities.changeFileExt(f, ".mm.json")));
            // String tgt = normalise(TextFile.fileToString("C:\\work\\org.hl7.fhir\\build\\publish\\"+Utilities.changeFileExt(f, ".json")));
            Element e = Manager.parse(context, new FileInputStream("C:\\work\\org.hl7.fhir\\build\\publish\\" + f), FhirFormat.XML);
            Manager.compose(context, e, new FileOutputStream("C:\\work\\org.hl7.fhir\\build\\publish\\" + Utilities.changeFileExt(f, ".mm.ttl")), FhirFormat.TURTLE, OutputStyle.PRETTY, null);
            Manager.compose(context, e, new FileOutputStream(Utilities.path("[tmp]", "resource.xml")), FhirFormat.XML, OutputStyle.PRETTY, null);
            String src = TextFile.fileToString("C:\\work\\org.hl7.fhir\\build\\publish\\" + Utilities.changeFileExt(f, ".mm.ttl"));
            String tgt = TextFile.fileToString("C:\\work\\org.hl7.fhir\\build\\publish\\" + Utilities.changeFileExt(f, ".ttl"));
            t++;
            if (src.equals(tgt)) {
                System.out.println(".. ok");
                ok++;
            } else
                System.out.println(".. fail");
        }
    // }
    }
    System.out.println("done - " + Integer.toString(t) + " files, " + Integer.toString(ok) + " ok");
}
Also used : IWorkerContext(org.hl7.fhir.r4.context.IWorkerContext) JsonElement(com.google.gson.JsonElement) FileOutputStream(java.io.FileOutputStream) File(java.io.File) TextFile(org.hl7.fhir.utilities.TextFile) FileInputStream(java.io.FileInputStream)

Example 12 with IWorkerContext

use of org.hl7.fhir.r4b.context.IWorkerContext in project org.hl7.fhir.core by hapifhir.

the class FhirPathTests method testFuncReplaceParamSize.

@Test
public void testFuncReplaceParamSize() {
    FHIRPathEngine engine = Mockito.spy(new FHIRPathEngine(iWorkerContext));
    ExpressionNode expressionNode = new ExpressionNode(0);
    expressionNode.setKind(ExpressionNode.Kind.Function);
    expressionNode.setFunction(ExpressionNode.Function.Replace);
    ExpressionNode expressionNodeB = new ExpressionNode(1);
    expressionNodeB.setKind(ExpressionNode.Kind.Function);
    expressionNodeB.setFunction(ExpressionNode.Function.Empty);
    ExpressionNode expressionNodeC = new ExpressionNode(2);
    expressionNodeC.setKind(ExpressionNode.Kind.Function);
    expressionNodeC.setFunction(ExpressionNode.Function.Empty);
    expressionNode.getParameters().add(expressionNodeB);
    expressionNode.getParameters().add(expressionNodeC);
    List<Base> result = engine.evaluate(appContext, resource, base, expressionNode);
    assertEquals(1, result.size());
    Base onlyResult = result.get(0);
    assertTrue(onlyResult instanceof StringType);
    assertEquals("base", ((StringType) result.get(0)).asStringValue());
    Mockito.verify(engine, times(2)).convertToString(any());
}
Also used : StringType(org.hl7.fhir.dstu3.model.StringType) ExpressionNode(org.hl7.fhir.dstu3.model.ExpressionNode) Base(org.hl7.fhir.dstu3.model.Base) Test(org.junit.jupiter.api.Test)

Example 13 with IWorkerContext

use of org.hl7.fhir.r4b.context.IWorkerContext in project org.hl7.fhir.core by hapifhir.

the class CSVWriter method processElement.

/*  private void findMapKeys(StructureDefinition def, List<StructureDefinitionMappingComponent> maps, IWorkerContext context) {
  	maps.addAll(def.getMapping());
  	if (def.getBaseDefinition()!=null) {
  	  StructureDefinition base = context.fetchResource(StructureDefinition.class, def.getBaseDefinition());
  	  findMapKeys(base, maps, context);
  	}
  }*/
public void processElement(ElementDefinition ed) throws Exception {
    CSVLine line = new CSVLine();
    lines.add(line);
    line.addString(ed.getPath());
    line.addString(ed.getSliceName());
    line.addString(itemList(ed.getAlias()));
    line.addString(ed.getLabel());
    line.addValue(ed.getMin());
    line.addValue(ed.getMax());
    line.addString(ed.getMustSupport() ? "Y" : "");
    line.addString(ed.getIsModifier() ? "Y" : "");
    line.addString(ed.getIsSummary() ? "Y" : "");
    line.addString(itemList(ed.getType()));
    line.addString(ed.getShort());
    line.addString(ed.getDefinition());
    line.addString(ed.getComment());
    line.addString(ed.getRequirements());
    line.addString(ed.getDefaultValue() != null ? renderType(ed.getDefaultValue()) : "");
    line.addString(ed.getMeaningWhenMissing());
    line.addString(ed.hasFixed() ? renderType(ed.getFixed()) : "");
    line.addString(ed.hasPattern() ? renderType(ed.getPattern()) : "");
    // todo...?
    line.addString(ed.hasExample() ? renderType(ed.getExample().get(0).getValue()) : "");
    line.addString(ed.hasMinValue() ? renderType(ed.getMinValue()) : "");
    line.addString(ed.hasMaxValue() ? renderType(ed.getMaxValue()) : "");
    line.addValue((ed.hasMaxLength() ? Integer.toString(ed.getMaxLength()) : ""));
    if (ed.hasBinding()) {
        line.addString(ed.getBinding().getStrength() != null ? ed.getBinding().getStrength().toCode() : "");
        line.addString(ed.getBinding().getDescription());
        if (ed.getBinding().getValueSet() == null)
            line.addString("");
        else
            line.addString(ed.getBinding().getValueSet());
    } else {
        line.addValue("");
        line.addValue("");
        line.addValue("");
    }
    line.addString(itemList(ed.getCode()));
    if (ed.hasSlicing()) {
        line.addString(itemList(ed.getSlicing().getDiscriminator()));
        line.addString(ed.getSlicing().getDescription());
        line.addBoolean(ed.getSlicing().getOrdered());
        line.addString(ed.getSlicing().getRules() != null ? ed.getSlicing().getRules().toCode() : "");
    } else {
        line.addValue("");
        line.addValue("");
        line.addValue("");
    }
    if (ed.getBase() != null) {
        line.addString(ed.getBase().getPath());
        line.addValue(ed.getBase().getMin());
        line.addValue(ed.getBase().getMax());
    } else {
        line.addValue("");
        line.addValue("");
        line.addValue("");
    }
    line.addString(itemList(ed.getCondition()));
    line.addString(itemList(ed.getConstraint()));
    for (StructureDefinitionMappingComponent mapKey : def.getMapping()) {
        for (ElementDefinitionMappingComponent map : ed.getMapping()) {
            if (map.getIdentity().equals(mapKey.getIdentity()))
                line.addString(map.getMap());
        }
    }
}
Also used : StructureDefinitionMappingComponent(org.hl7.fhir.r4.model.StructureDefinition.StructureDefinitionMappingComponent) ElementDefinitionMappingComponent(org.hl7.fhir.r4.model.ElementDefinition.ElementDefinitionMappingComponent)

Example 14 with IWorkerContext

use of org.hl7.fhir.r4b.context.IWorkerContext in project org.hl7.fhir.core by hapifhir.

the class Tester method main.

public static void main(String[] args) throws Exception {
    IWorkerContext context = SimpleWorkerContext.fromPack(Utilities.path("C:\\work\\org.hl7.fhir\\build\\publish", "validation-min.xml.zip"));
    int t = 0;
    int ok = 0;
    for (String f : new File("C:\\work\\org.hl7.fhir\\build\\publish").list()) {
        if (f.endsWith(".xml") && !f.endsWith(".canonical.xml") && !f.contains("profile") && !f.contains("questionnaire") && new File("C:\\work\\org.hl7.fhir\\build\\publish\\" + Utilities.changeFileExt(f, ".ttl")).exists()) {
            // if (f.equals("account-questionnaire.xml")) {
            System.out.print("convert " + f);
            // Manager.convert(context, new FileInputStream("C:\\work\\org.hl7.fhir\\build\\publish\\"+f), FhirFormat.XML,
            // new FileOutputStream("C:\\work\\org.hl7.fhir\\build\\publish\\"+Utilities.changeFileExt(f, ".mm.json")), FhirFormat.JSON, OutputStyle.PRETTY);
            // String src = normalise(TextFile.fileToString("C:\\work\\org.hl7.fhir\\build\\publish\\"+Utilities.changeFileExt(f, ".mm.json")));
            // String tgt = normalise(TextFile.fileToString("C:\\work\\org.hl7.fhir\\build\\publish\\"+Utilities.changeFileExt(f, ".json")));
            Element e = Manager.parseSingle(context, new FileInputStream("C:\\work\\org.hl7.fhir\\build\\publish\\" + f), FhirFormat.XML);
            Manager.compose(context, e, new FileOutputStream("C:\\work\\org.hl7.fhir\\build\\publish\\" + Utilities.changeFileExt(f, ".mm.ttl")), FhirFormat.TURTLE, OutputStyle.PRETTY, null);
            Manager.compose(context, e, new FileOutputStream(Utilities.path("[tmp]", "resource.xml")), FhirFormat.XML, OutputStyle.PRETTY, null);
            String src = TextFile.fileToString("C:\\work\\org.hl7.fhir\\build\\publish\\" + Utilities.changeFileExt(f, ".mm.ttl"));
            String tgt = TextFile.fileToString("C:\\work\\org.hl7.fhir\\build\\publish\\" + Utilities.changeFileExt(f, ".ttl"));
            t++;
            if (src.equals(tgt)) {
                System.out.println(".. ok");
                ok++;
            } else
                System.out.println(".. fail");
        }
    // }
    }
    System.out.println("done - " + Integer.toString(t) + " files, " + Integer.toString(ok) + " ok");
}
Also used : IWorkerContext(org.hl7.fhir.r4b.context.IWorkerContext) JsonElement(com.google.gson.JsonElement) NamedElement(org.hl7.fhir.r4b.elementmodel.ParserBase.NamedElement) FileOutputStream(java.io.FileOutputStream) File(java.io.File) TextFile(org.hl7.fhir.utilities.TextFile) FileInputStream(java.io.FileInputStream)

Example 15 with IWorkerContext

use of org.hl7.fhir.r4b.context.IWorkerContext in project org.hl7.fhir.core by hapifhir.

the class ValueSetUtilities method markStatus.

public static void markStatus(ValueSet vs, String wg, StandardsStatus status, String pckage, String fmm, IWorkerContext context, String normativeVersion) throws FHIRException {
    if (vs.hasUserData("external.url"))
        return;
    if (wg != null) {
        if (!ToolingExtensions.hasExtension(vs, ToolingExtensions.EXT_WORKGROUP) || (!Utilities.existsInList(ToolingExtensions.readStringExtension(vs, ToolingExtensions.EXT_WORKGROUP), "fhir", "vocab") && Utilities.existsInList(wg, "fhir", "vocab"))) {
            ToolingExtensions.setCodeExtension(vs, ToolingExtensions.EXT_WORKGROUP, wg);
        }
    }
    if (status != null) {
        StandardsStatus ss = ToolingExtensions.getStandardsStatus(vs);
        if (ss == null || ss.isLowerThan(status))
            ToolingExtensions.setStandardsStatus(vs, status, normativeVersion);
        if (pckage != null) {
            if (!vs.hasUserData("ballot.package"))
                vs.setUserData("ballot.package", pckage);
            else if (!pckage.equals(vs.getUserString("ballot.package")))
                if (!"infrastructure".equals(vs.getUserString("ballot.package")))
                    System.out.println("Value Set " + vs.getUrl() + ": ownership clash " + pckage + " vs " + vs.getUserString("ballot.package"));
        }
        if (status == StandardsStatus.NORMATIVE) {
            vs.setExperimental(false);
            vs.setStatus(PublicationStatus.ACTIVE);
        }
    }
    if (fmm != null) {
        String sfmm = ToolingExtensions.readStringExtension(vs, ToolingExtensions.EXT_FMM_LEVEL);
        if (Utilities.noString(sfmm) || Integer.parseInt(sfmm) < Integer.parseInt(fmm)) {
            ToolingExtensions.setIntegerExtension(vs, ToolingExtensions.EXT_FMM_LEVEL, Integer.parseInt(fmm));
        }
        if (Integer.parseInt(fmm) <= 1) {
            vs.setExperimental(true);
        }
    }
    if (vs.hasUserData("cs"))
        CodeSystemUtilities.markStatus((CodeSystem) vs.getUserData("cs"), wg, status, pckage, fmm, normativeVersion);
    else if (status == StandardsStatus.NORMATIVE && context != null) {
        for (ConceptSetComponent csc : vs.getCompose().getInclude()) {
            if (csc.hasSystem()) {
                CodeSystem cs = context.fetchCodeSystem(csc.getSystem());
                if (cs != null) {
                    CodeSystemUtilities.markStatus(cs, wg, status, pckage, fmm, normativeVersion);
                }
            }
        }
    }
}
Also used : ConceptSetComponent(org.hl7.fhir.r4b.model.ValueSet.ConceptSetComponent) StandardsStatus(org.hl7.fhir.utilities.StandardsStatus) CodeSystem(org.hl7.fhir.r4b.model.CodeSystem)

Aggregations

FileInputStream (java.io.FileInputStream)6 FileOutputStream (java.io.FileOutputStream)6 JsonElement (com.google.gson.JsonElement)5 File (java.io.File)5 IWorkerContext (org.hl7.fhir.r5.context.IWorkerContext)5 JsonSyntaxException (com.google.gson.JsonSyntaxException)4 FileNotFoundException (java.io.FileNotFoundException)4 IOException (java.io.IOException)4 UcumEssenceService (org.fhir.ucum.UcumEssenceService)4 TextFile (org.hl7.fhir.utilities.TextFile)4 IWorkerContext (org.hl7.fhir.r4b.context.IWorkerContext)3 FilesystemPackageCacheManager (org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager)3 Row (org.apache.poi.ss.usermodel.Row)2 XSSFRow (org.apache.poi.xssf.usermodel.XSSFRow)2 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)2 ElementDefinitionMappingComponent (org.hl7.fhir.r4.model.ElementDefinition.ElementDefinitionMappingComponent)2 StructureDefinitionMappingComponent (org.hl7.fhir.r4.model.StructureDefinition.StructureDefinitionMappingComponent)2 NamedElement (org.hl7.fhir.r4b.elementmodel.ParserBase.NamedElement)2 ElementDefinitionMappingComponent (org.hl7.fhir.r4b.model.ElementDefinition.ElementDefinitionMappingComponent)2 StructureDefinition (org.hl7.fhir.r4b.model.StructureDefinition)2