Search in sources :

Example 1 with IWorkerContext

use of org.hl7.fhir.dstu2016may.utils.IWorkerContext in project kindling by HL7.

the class TypeParser method convert.

public List<TypeRefComponent> convert(IWorkerContext context, String path, List<TypeRef> types, boolean resource, ElementDefinition ed) throws Exception {
    List<TypeRefComponent> list = new ArrayList<TypeRefComponent>();
    for (TypeRef t : types) {
        // Expand any Resource(A|B|C) references
        if (t.hasParams() && !("Reference".equals(t.getName()) || "canonical".equals(t.getName()))) {
            throw new Exception("Only resource references can specify parameters.  Path " + path);
        }
        if (t.getParams().size() > 0) {
            if (t.getProfile() != null && t.getParams().size() != 1) {
                throw new Exception("Cannot declare profile on a resource reference declaring multiple resource types.  Path " + path);
            }
            if (t.getProfile() != null) {
                TypeRefComponent childType = getTypeComponent(list, t.getName());
                if (t.getVersioning() != null)
                    childType.setVersioning(t.getVersioning());
                if (t.getName().equals("Reference") || t.getName().equals("canonical"))
                    childType.addTargetProfile(t.getProfile());
                else
                    childType.addProfile(t.getProfile());
            } else
                for (String param : t.getParams()) {
                    TypeRefComponent childType = getTypeComponent(list, t.getName());
                    if (t.getVersioning() != null)
                        childType.setVersioning(t.getVersioning());
                    String p = "Any".equals(param) ? "Resource" : param;
                    if (t.getName().equals("Reference") || t.getName().equals("canonical"))
                        childType.addTargetProfile("http://hl7.org/fhir/StructureDefinition/" + p);
                    else
                        childType.addProfile("http://hl7.org/fhir/StructureDefinition/" + p);
                }
        } else if (t.isWildcardType()) {
            // this list is filled out manually because it may be running before the types referred to have been loaded
            for (String n : TypesUtilities.wildcardTypes(version)) {
                TypeRefComponent tc = new TypeRefComponent().setCode(n);
                if (t.getVersioning() != null)
                    tc.setVersioning(t.getVersioning());
                list.add(tc);
            }
        } else if (Utilities.noString(t.getName()) && t.getProfile() != null) {
            StructureDefinition sd = context.fetchResource(StructureDefinition.class, t.getProfile());
            TypeRefComponent tc = getTypeComponent(list, sd != null ? sd.getType() : t.getName());
            if (t.getVersioning() != null)
                tc.setVersioning(t.getVersioning());
            if (t.getName().equals("Reference"))
                tc.addTargetProfile(t.getProfile());
            else
                tc.addProfile(t.getProfile());
        } else if (t.getName().startsWith("=")) {
            if (resource)
                list.add(new TypeRefComponent().setCode("BackboneElement"));
            else
                list.add(new TypeRefComponent().setCode("Element"));
            ToolingExtensions.addStringExtension(ed, "http://hl7.org/fhir/StructureDefinition/structuredefinition-explicit-type-name", t.getName().substring(1));
        } else {
            StructureDefinition sd = context.fetchTypeDefinition(t.getName());
            if (sd == null)
                throw new Exception("Unknown type '" + t.getName() + "'");
            TypeRefComponent tc = getTypeComponent(list, sd.getType());
            if (t.getVersioning() != null)
                tc.setVersioning(t.getVersioning());
            if (t.getName().equals("Reference")) {
                if (t.hasProfile())
                    tc.addTargetProfile(t.getProfile());
            } else if (t.hasProfile())
                tc.addProfile(t.getProfile());
        }
    }
    // no duplicates
    for (TypeRefComponent tr1 : list) {
        for (TypeRefComponent tr2 : list) {
            if (tr1 != tr2) {
                if (tr1.getWorkingCode().equals(tr2.getWorkingCode()))
                    throw new Exception("duplicate code " + tr1.getWorkingCode());
            }
        }
    }
    return list;
}
Also used : StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) TypeRefComponent(org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent) TypeRef(org.hl7.fhir.definitions.model.TypeRef) ArrayList(java.util.ArrayList)

Example 2 with IWorkerContext

use of org.hl7.fhir.dstu2016may.utils.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.dstu2016may.utils.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 3 with IWorkerContext

use of org.hl7.fhir.dstu2016may.utils.IWorkerContext in project org.hl7.fhir.core by hapifhir.

the class ResourceUtilities method representDataElementCollection.

public static String representDataElementCollection(IWorkerContext context, Bundle bundle, boolean profileLink, String linkBase) {
    StringBuilder b = new StringBuilder();
    DataElement common = showDECHeader(b, bundle);
    b.append("<table class=\"grid\">\r\n");
    List<String> cols = chooseColumns(bundle, common, b, profileLink);
    for (BundleEntryComponent e : bundle.getEntry()) {
        DataElement de = (DataElement) e.getResource();
        renderDE(de, cols, b, profileLink, linkBase);
    }
    b.append("</table>\r\n");
    return b.toString();
}
Also used : DataElement(org.hl7.fhir.dstu2.model.DataElement) BundleEntryComponent(org.hl7.fhir.dstu2.model.Bundle.BundleEntryComponent) CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder)

Example 4 with IWorkerContext

use of org.hl7.fhir.dstu2016may.utils.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.r4b.model.StructureDefinition.StructureDefinitionMappingComponent) ElementDefinitionMappingComponent(org.hl7.fhir.r4b.model.ElementDefinition.ElementDefinitionMappingComponent)

Example 5 with IWorkerContext

use of org.hl7.fhir.dstu2016may.utils.IWorkerContext in project org.hl7.fhir.core by hapifhir.

the class ProfileUtilities method makeExtensionForVersionedURL.

public static StructureDefinition makeExtensionForVersionedURL(IWorkerContext context, String url) {
    String epath = url.substring(54);
    if (!epath.contains("."))
        return null;
    String type = epath.substring(0, epath.indexOf("."));
    StructureDefinition sd = context.fetchTypeDefinition(type);
    if (sd == null)
        return null;
    ElementDefinition ed = null;
    for (ElementDefinition t : sd.getSnapshot().getElement()) {
        if (t.getPath().equals(epath)) {
            ed = t;
            break;
        }
    }
    if (ed == null)
        return null;
    if ("Element".equals(ed.typeSummary()) || "BackboneElement".equals(ed.typeSummary())) {
        return null;
    } else {
        StructureDefinition template = context.fetchResource(StructureDefinition.class, "http://fhir-registry.smarthealthit.org/StructureDefinition/capabilities");
        StructureDefinition ext = template.copy();
        ext.setUrl(url);
        ext.setId("extension-" + epath);
        ext.setName("Extension-" + epath);
        ext.setTitle("Extension for r4 " + epath);
        ext.setStatus(sd.getStatus());
        ext.setDate(sd.getDate());
        ext.getContact().clear();
        ext.getContact().addAll(sd.getContact());
        ext.setFhirVersion(sd.getFhirVersion());
        ext.setDescription(ed.getDefinition());
        ext.getContext().clear();
        ext.addContext().setType(ExtensionContextType.ELEMENT).setExpression(epath.substring(0, epath.lastIndexOf(".")));
        ext.getDifferential().getElement().clear();
        ext.getSnapshot().getElement().get(3).setFixed(new UriType(url));
        ext.getSnapshot().getElement().set(4, ed.copy());
        ext.getSnapshot().getElement().get(4).setPath("Extension.value" + Utilities.capitalize(ed.typeSummary()));
        return ext;
    }
}
Also used : StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) ElementDefinition(org.hl7.fhir.r5.model.ElementDefinition) UriType(org.hl7.fhir.r5.model.UriType)

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