Search in sources :

Example 66 with StructureMap

use of org.hl7.fhir.r5.model.StructureMap in project org.hl7.fhir.core by hapifhir.

the class R3R4ConversionTests method loadLib.

private void loadLib(String dir) throws FileNotFoundException, IOException {
    StructureMapUtilities smu = new StructureMapUtilities(contextR4);
    for (String s : new File(dir).list()) {
        String map = TextFile.fileToString(Utilities.path(dir, s));
        try {
            StructureMap sm = smu.parse(map, s);
            contextR3.cacheResource(sm);
            contextR4.cacheResource(sm);
            for (Resource r : sm.getContained()) {
                if (r instanceof MetadataResource) {
                    MetadataResource mr = (MetadataResource) r.copy();
                    mr.setUrl(sm.getUrl() + "#" + r.getId());
                    contextR3.cacheResource(mr);
                    contextR4.cacheResource(mr);
                }
            }
        } catch (FHIRException e) {
            System.out.println("Unable to load " + Utilities.path(dir, s) + ": " + e.getMessage());
            loadErrors.put(s, e);
        // e.printStackTrace();
        }
    }
}
Also used : MetadataResource(org.hl7.fhir.r4.model.MetadataResource) StructureMap(org.hl7.fhir.r4.model.StructureMap) Resource(org.hl7.fhir.r4.model.Resource) MetadataResource(org.hl7.fhir.r4.model.MetadataResource) IniFile(org.hl7.fhir.utilities.IniFile) File(java.io.File) TextFile(org.hl7.fhir.utilities.TextFile) FHIRException(org.hl7.fhir.exceptions.FHIRException) StructureMapUtilities(org.hl7.fhir.r4.utils.StructureMapUtilities)

Example 67 with StructureMap

use of org.hl7.fhir.r5.model.StructureMap in project org.hl7.fhir.core by hapifhir.

the class TurtleTests method test_structuremap_example.

@Test
public void test_structuremap_example() throws FileNotFoundException, IOException, Exception {
    System.out.println("structuremap-example.ttl");
    new Turtle().parse(TextFile.fileToString("C:\\work\\org.hl7.fhir\\build\\publish\\structuremap-example.ttl"));
}
Also used : Turtle(org.hl7.fhir.dstu3.utils.formats.Turtle) Test(org.junit.jupiter.api.Test)

Example 68 with StructureMap

use of org.hl7.fhir.r5.model.StructureMap in project org.hl7.fhir.core by hapifhir.

the class SimpleWorkerContext method findTransformsforSource.

public List<StructureMap> findTransformsforSource(String url) {
    List<StructureMap> res = new ArrayList<StructureMap>();
    for (StructureMap map : listTransforms()) {
        boolean match = false;
        boolean ok = true;
        for (StructureMapStructureComponent t : map.getStructure()) {
            if (t.getMode() == StructureMapModelMode.SOURCE) {
                match = match || t.getUrl().equals(url);
                ok = ok && t.getUrl().equals(url);
            }
        }
        if (match && ok)
            res.add(map);
    }
    return res;
}
Also used : StructureMap(org.hl7.fhir.r4.model.StructureMap) StructureMapStructureComponent(org.hl7.fhir.r4.model.StructureMap.StructureMapStructureComponent) ArrayList(java.util.ArrayList)

Example 69 with StructureMap

use of org.hl7.fhir.r5.model.StructureMap in project org.hl7.fhir.core by hapifhir.

the class StructureMapUtilities method createProfile.

private PropertyWithType createProfile(StructureMap map, List<StructureDefinition> profiles, PropertyWithType prop, String sliceName, Base ctxt) throws FHIRException {
    if (prop.getBaseProperty().getDefinition().getPath().contains("."))
        throw new DefinitionException("Unable to process entry point");
    String type = prop.getBaseProperty().getDefinition().getPath();
    String suffix = "";
    if (ids.containsKey(type)) {
        int id = ids.get(type);
        id++;
        ids.put(type, id);
        suffix = "-" + Integer.toString(id);
    } else
        ids.put(type, 0);
    StructureDefinition profile = new StructureDefinition();
    profiles.add(profile);
    profile.setDerivation(TypeDerivationRule.CONSTRAINT);
    profile.setType(type);
    profile.setBaseDefinition(prop.getBaseProperty().getStructure().getUrl());
    profile.setName("Profile for " + profile.getType() + " for " + sliceName);
    profile.setUrl(map.getUrl().replace("StructureMap", "StructureDefinition") + "-" + profile.getType() + suffix);
    // then we can easily assign this profile url for validation later when we actually transform
    ctxt.setUserData("profile", profile.getUrl());
    profile.setId(map.getId() + "-" + profile.getType() + suffix);
    profile.setStatus(map.getStatus());
    profile.setExperimental(map.getExperimental());
    profile.setDescription("Generated automatically from the mapping by the Java Reference Implementation");
    for (ContactDetail c : map.getContact()) {
        ContactDetail p = profile.addContact();
        p.setName(c.getName());
        for (ContactPoint cc : c.getTelecom()) p.addTelecom(cc);
    }
    profile.setDate(map.getDate());
    profile.setCopyright(map.getCopyright());
    profile.setFhirVersion(FHIRVersion.fromCode(Constants.VERSION));
    profile.setKind(prop.getBaseProperty().getStructure().getKind());
    profile.setAbstract(false);
    ElementDefinition ed = profile.getDifferential().addElement();
    ed.setPath(profile.getType());
    prop.profileProperty = new Property(worker, ed, profile);
    return prop;
}
Also used : ContactDetail(org.hl7.fhir.r4.model.ContactDetail) ContactPoint(org.hl7.fhir.r4.model.ContactPoint) StructureDefinition(org.hl7.fhir.r4.model.StructureDefinition) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) ElementDefinition(org.hl7.fhir.r4.model.ElementDefinition) Property(org.hl7.fhir.r4.elementmodel.Property) ContactPoint(org.hl7.fhir.r4.model.ContactPoint)

Example 70 with StructureMap

use of org.hl7.fhir.r5.model.StructureMap in project org.hl7.fhir.core by hapifhir.

the class StructureMapUtilities method parseGroup.

private void parseGroup(StructureMap result, FHIRLexer lexer) throws FHIRException {
    lexer.token("group");
    StructureMapGroupComponent group = result.addGroup();
    boolean newFmt = false;
    if (lexer.hasToken("for")) {
        lexer.token("for");
        if ("type".equals(lexer.getCurrent())) {
            lexer.token("type");
            lexer.token("+");
            lexer.token("types");
            group.setTypeMode(StructureMapGroupTypeMode.TYPEANDTYPES);
        } else {
            lexer.token("types");
            group.setTypeMode(StructureMapGroupTypeMode.TYPES);
        }
    } else
        group.setTypeMode(StructureMapGroupTypeMode.NONE);
    group.setName(lexer.take());
    if (lexer.hasToken("(")) {
        newFmt = true;
        lexer.take();
        while (!lexer.hasToken(")")) {
            parseInput(group, lexer, true);
            if (lexer.hasToken(","))
                lexer.token(",");
        }
        lexer.take();
    }
    if (lexer.hasToken("extends")) {
        lexer.next();
        group.setExtends(lexer.take());
    }
    if (newFmt) {
        group.setTypeMode(StructureMapGroupTypeMode.NONE);
        if (lexer.hasToken("<")) {
            lexer.token("<");
            lexer.token("<");
            if (lexer.hasToken("types")) {
                group.setTypeMode(StructureMapGroupTypeMode.TYPES);
                lexer.token("types");
            } else {
                lexer.token("type");
                lexer.token("+");
                group.setTypeMode(StructureMapGroupTypeMode.TYPEANDTYPES);
            }
            lexer.token(">");
            lexer.token(">");
        }
        lexer.token("{");
    }
    lexer.skipComments();
    if (newFmt) {
        while (!lexer.hasToken("}")) {
            if (lexer.done())
                throw lexer.error("premature termination expecting 'endgroup'");
            parseRule(result, group.getRule(), lexer, true);
        }
    } else {
        while (lexer.hasToken("input")) parseInput(group, lexer, false);
        while (!lexer.hasToken("endgroup")) {
            if (lexer.done())
                throw lexer.error("premature termination expecting 'endgroup'");
            parseRule(result, group.getRule(), lexer, false);
        }
    }
    lexer.next();
    if (newFmt && lexer.hasToken(";"))
        lexer.next();
    lexer.skipComments();
}
Also used : StructureMapGroupComponent(org.hl7.fhir.r4.model.StructureMap.StructureMapGroupComponent)

Aggregations

FHIRException (org.hl7.fhir.exceptions.FHIRException)69 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)23 FHIRFormatError (org.hl7.fhir.exceptions.FHIRFormatError)17 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)16 StructureMap (org.hl7.fhir.r4b.model.StructureMap)13 StructureMap (org.hl7.fhir.r5.model.StructureMap)13 IOException (java.io.IOException)11 ArrayList (java.util.ArrayList)11 StructureMap (org.hl7.fhir.r4.model.StructureMap)11 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)11 Complex (org.hl7.fhir.dstu2016may.formats.RdfGenerator.Complex)10 Complex (org.hl7.fhir.dstu3.utils.formats.Turtle.Complex)9 Complex (org.hl7.fhir.r4.utils.formats.Turtle.Complex)9 StructureMap (org.hl7.fhir.dstu3.model.StructureMap)8 File (java.io.File)7 UriType (org.hl7.fhir.r4.model.UriType)7 Test (org.junit.jupiter.api.Test)7 Base (org.hl7.fhir.dstu3.model.Base)6 TextFile (org.hl7.fhir.utilities.TextFile)6 FileOutputStream (java.io.FileOutputStream)5