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();
}
}
}
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"));
}
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;
}
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;
}
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();
}
Aggregations