private List<StructureMap> findMatchingMaps(String value) { List<StructureMap> res = new ArrayList<StructureMap>(); if (value.contains("*")) { for (StructureMap sm : worker.listTransforms()) { if (urlMatches(value, sm.getUrl())) { res.add(sm); } } } else { StructureMap sm = worker.getTransform(value); if (sm != null) res.add(sm); } Set<String> check = new HashSet<String>(); for (StructureMap sm : res) { if (check.contains(sm.getUrl())) throw new Error("duplicate"); else check.add(sm.getUrl()); } return res; }
public static String render(StructureMap map) { StringBuilder b = new StringBuilder(); b.append("map \""); b.append(map.getUrl()); b.append("\" = \""); b.append(Utilities.escapeJson(map.getName())); b.append("\"\r\n\r\n"); renderConceptMaps(b, map); renderUses(b, map); renderImports(b, map); for (StructureMapGroupComponent g : map.getGroup()) renderGroup(b, g); return b.toString(); }
public StructureDefinition getTargetType(StructureMap map) throws FHIRException { boolean found = false; StructureDefinition res = null; for (StructureMapStructureComponent uses : map.getStructure()) { if (uses.getMode() == StructureMapModelMode.TARGET) { if (found) throw new FHIRException("Multiple targets found in map "+map.getUrl()); found = true; res = worker.fetchResource(StructureDefinition.class, uses.getUrl()); if (res == null) throw new FHIRException("Unable to find "+uses.getUrl()+" referenced from map "+map.getUrl()); } } if (res == null) throw new FHIRException("No targets found in map "+map.getUrl()); return res; }
throw new FHIRException("Unable to find map(s) for "+imp.getValue()); for (StructureMap impMap : impMapList) { if (!impMap.getUrl().equals(map.getUrl())) { for (StructureMapGroupComponent grp : impMap.getGroup()) { if (matchesByType(impMap, grp, srcType, tgtType)) { res.target = grp; } else throw new FHIRException("Multiple possible matches for rule for '"+srcType+"/"+tgtType+"' in "+res.targetMap.getUrl()+" and "+impMap.getUrl()+", from rule '"+ruleid+"'"); throw new FHIRException("No matches found for rule for '"+srcType+" to "+tgtType+"' from "+map.getUrl()+", from rule '"+ruleid+"'"); source.setUserData(kn, res); return res;
throw new FHIRException("Unable to find map(s) for "+imp.getValue()); for (StructureMap impMap : impMapList) { if (!impMap.getUrl().equals(map.getUrl())) { for (StructureMapGroupComponent grp : impMap.getGroup()) { if (grp.getName().equals(name)) { } else throw new FHIRException("Multiple possible matches for rule group '"+name+"' in "+ res.targetMap.getUrl()+"#"+res.target.getName()+" and "+ impMap.getUrl()+"#"+grp.getName()); throw new FHIRException("No matches found for rule '"+name+"'. Reference found in "+map.getUrl()); source.setUserData(kn, res); return res;
public void transform(Object appInfo, Base source, StructureMap map, Base target) throws FHIRException { TransformContext context = new TransformContext(appInfo); log("Start Transform "+map.getUrl()); StructureMapGroupComponent g = map.getGroup().get(0); Variables vars = new Variables(); vars.add(VariableMode.INPUT, getInputName(g, StructureMapInputMode.SOURCE, "source"), source); if (target != null) vars.add(VariableMode.OUTPUT, getInputName(g, StructureMapInputMode.TARGET, "target"), target); executeGroup("", context, map, vars, g, true); if (target instanceof Element) ((Element) target).sort(); }
throw new FHIRException("Unable to find map(s) for "+imp.getValue()); for (StructureMap impMap : impMapList) { if (!impMap.getUrl().equals(map.getUrl())) { for (StructureMapGroupComponent grp : impMap.getGroup()) { if (matchesByType(impMap, grp, type)) { res.target = grp; } else throw new FHIRException("Multiple possible matches for default rule for '"+type+"' in "+res.targetMap.getUrl()+" ("+res.target.getName()+") and "+impMap.getUrl()+" ("+grp.getName()+")"); throw new FHIRException("No matches found for default rule for '"+type+"' from "+map.getUrl()); String result = getActualType(res.targetMap, res.target.getInput().get(1).getType()); // should be .getType, but R2... source.setUserData(kn, result);
public StructureMap generateMapFromMappings(StructureDefinition sd) throws IOException, FHIRException { String id = getLogicalMappingId(sd); if (id == null) return null; String prefix = ToolingExtensions.readStringExtension(sd, ToolingExtensions.EXT_MAPPING_PREFIX); String suffix = ToolingExtensions.readStringExtension(sd, ToolingExtensions.EXT_MAPPING_SUFFIX); if (prefix == null || suffix == null) return null; // we build this by text. Any element that has a mapping, we put it's mappings inside it.... StringBuilder b = new StringBuilder(); b.append(prefix); ElementDefinition root = sd.getSnapshot().getElementFirstRep(); String m = getMapping(root, id); if (m != null) b.append(m+"\r\n"); addChildMappings(b, id, "", sd, root, false); b.append("\r\n"); b.append(suffix); b.append("\r\n"); StructureMap map = parse(b.toString(), sd.getUrl()); map.setId(tail(map.getUrl())); if (!map.hasStatus()) map.setStatus(PublicationStatus.DRAFT); map.getText().setStatus(NarrativeStatus.GENERATED); map.getText().setDiv(new XhtmlNode(NodeType.Element, "div")); map.getText().getDiv().addTag("pre").addText(render(map)); return map; }
if (r instanceof ConceptMap && ((ConceptMap) r).getId().equals(conceptMapUrl.substring(1))) { cmap = (ConceptMap) r; su = map.getUrl()+"#"+conceptMapUrl;
profile.setBaseDefinition(prop.getBaseProperty().getStructure().getUrl()); profile.setName("Profile for "+profile.getType()+" for "+sliceName); profile.setUrl(map.getUrl().replace("StructureMap", "StructureDefinition")+"-"+profile.getType()+suffix); ctxt.setUserData("profile", profile.getUrl()); // then we can easily assign this profile url for validation later when we actually transform profile.setId(map.getId()+"-"+profile.getType()+suffix);
if (rule.getSource().size() != 1) throw new FHIRException("Rule \""+rule.getName()+"\": not handled yet"); List<Variables> source = processSource(rule.getName(), context, srcVars, rule.getSource().get(0), map.getUrl(), indent); if (source != null) { for (Variables v : source) {
private List<StructureMap> findMatchingMaps(String value) { List<StructureMap> res = new ArrayList<StructureMap>(); if (value.contains("*")) { for (StructureMap sm : worker.listTransforms()) { if (urlMatches(value, sm.getUrl())) { res.add(sm); } } } else { StructureMap sm = worker.getTransform(value); if (sm != null) res.add(sm); } Set<String> check = new HashSet<String>(); for (StructureMap sm : res) { if (check.contains(sm.getUrl())) throw new Error("duplicate"); else check.add(sm.getUrl()); } return res; }
public static String render(StructureMap map) { StringBuilder b = new StringBuilder(); b.append("map \""); b.append(map.getUrl()); b.append("\" = \""); b.append(Utilities.escapeJson(map.getName())); b.append("\"\r\n\r\n"); renderConceptMaps(b, map); renderUses(b, map); renderImports(b, map); for (StructureMapGroupComponent g : map.getGroup()) renderGroup(b, g); return b.toString(); }
public StructureDefinition getTargetType(StructureMap map) throws FHIRException { boolean found = false; StructureDefinition res = null; for (StructureMapStructureComponent uses : map.getStructure()) { if (uses.getMode() == StructureMapModelMode.TARGET) { if (found) throw new FHIRException("Multiple targets found in map "+map.getUrl()); found = true; res = worker.fetchResource(StructureDefinition.class, uses.getUrl()); if (res == null) throw new FHIRException("Unable to find "+uses.getUrl()+" referenced from map "+map.getUrl()); } } if (res == null) throw new FHIRException("No targets found in map "+map.getUrl()); return res; }
throw new FHIRException("Unable to find map(s) for "+imp.getValue()); for (StructureMap impMap : impMapList) { if (!impMap.getUrl().equals(map.getUrl())) { for (StructureMapGroupComponent grp : impMap.getGroup()) { if (grp.getName().equals(name)) { } else throw new FHIRException("Multiple possible matches for rule group '"+name+"' in "+ res.targetMap.getUrl()+"#"+res.target.getName()+" and "+ impMap.getUrl()+"#"+grp.getName()); throw new FHIRException("No matches found for rule '"+name+"'. Reference found in "+map.getUrl()); source.setUserData(kn, res); return res;
throw new FHIRException("Unable to find map(s) for "+imp.getValue()); for (StructureMap impMap : impMapList) { if (!impMap.getUrl().equals(map.getUrl())) { for (StructureMapGroupComponent grp : impMap.getGroup()) { if (matchesByType(impMap, grp, srcType, tgtType)) { res.target = grp; } else throw new FHIRException("Multiple possible matches for rule for '"+srcType+"/"+tgtType+"' in "+res.targetMap.getUrl()+" and "+impMap.getUrl()+", from rule '"+ruleid+"'"); throw new FHIRException("No matches found for rule for '"+srcType+" to "+tgtType+"' from "+map.getUrl()+", from rule '"+ruleid+"'"); source.setUserData(kn, res); return res;
public void transform(Object appInfo, Base source, StructureMap map, Base target) throws FHIRException { TransformContext context = new TransformContext(appInfo); log("Start Transform "+map.getUrl()); StructureMapGroupComponent g = map.getGroup().get(0); Variables vars = new Variables(); vars.add(VariableMode.INPUT, getInputName(g, StructureMapInputMode.SOURCE, "source"), source); if (target != null) vars.add(VariableMode.OUTPUT, getInputName(g, StructureMapInputMode.TARGET, "target"), target); executeGroup("", context, map, vars, g, true); if (target instanceof Element) ((Element) target).sort(); }
org.hl7.fhir.dstu2016may.model.StructureMap tgt = new org.hl7.fhir.dstu2016may.model.StructureMap(); copyDomainResource(src, tgt); tgt.setUrl(src.getUrl()); if (src.hasVersion()) tgt.setVersion(src.getVersion());
public StructureMap generateMapFromMappings(StructureDefinition sd) throws IOException, FHIRException { String id = getLogicalMappingId(sd); if (id == null) return null; String prefix = ToolingExtensions.readStringExtension(sd, ToolingExtensions.EXT_MAPPING_PREFIX); String suffix = ToolingExtensions.readStringExtension(sd, ToolingExtensions.EXT_MAPPING_SUFFIX); if (prefix == null || suffix == null) return null; // we build this by text. Any element that has a mapping, we put it's mappings inside it.... StringBuilder b = new StringBuilder(); b.append(prefix); ElementDefinition root = sd.getSnapshot().getElementFirstRep(); String m = getMapping(root, id); if (m != null) b.append(m+"\r\n"); addChildMappings(b, id, "", sd, root, false); b.append("\r\n"); b.append(suffix); b.append("\r\n"); StructureMap map = parse(b.toString(), sd.getUrl()); map.setId(tail(map.getUrl())); if (!map.hasStatus()) map.setStatus(PublicationStatus.DRAFT); map.getText().setStatus(NarrativeStatus.GENERATED); map.getText().setDiv(new XhtmlNode(NodeType.Element, "div")); map.getText().getDiv().addTag("pre").addText(render(map)); return map; }
if (rule.getSource().size() != 1) throw new FHIRException("Rule \""+rule.getName()+"\": not handled yet"); List<Variables> source = processSource(rule.getName(), context, srcVars, rule.getSource().get(0), map.getUrl(), indent); if (source != null) { for (Variables v : source) {