use of org.hl7.fhir.r4b.model.ConceptMap in project org.hl7.fhir.core by hapifhir.
the class MappingSheetParser method readConceptMap.
private void readConceptMap(ConceptMap cm) throws FHIRException {
for (ConceptMapGroupComponent g : cm.getGroup()) {
for (SourceElementComponent e : g.getElement()) {
if (e.hasId() && e.getTarget().size() == 1 && e.hasExtension(ToolingExtensions.EXT_MAPPING_TYPE)) {
TargetElementComponent t = e.getTargetFirstRep();
MappingRow row = new MappingRow();
row.sequence = e.getId();
row.identifier = e.getCode();
row.name = e.getExtensionString(ToolingExtensions.EXT_MAPPING_NAME);
row.dataType = e.getExtensionString(ToolingExtensions.EXT_MAPPING_TYPE);
row.cardinality = e.getExtensionString(ToolingExtensions.EXT_MAPPING_CARD);
if (e.getTargetFirstRep().getEquivalence() == ConceptMapEquivalence.UNMATCHED) {
row.attribute = "N/A";
} else {
OtherElementComponent dep = getDependency(t, "http://hl7.org/fhirpath");
if (dep != null)
row.condition = dep.getValue();
row.attribute = t.getCode();
row.type = t.getExtensionString(ToolingExtensions.EXT_MAPPING_TGTTYPE);
row.minMax = t.getExtensionString(ToolingExtensions.EXT_MAPPING_TGTCARD);
row.dtMapping = t.getExtensionString("http://hl7.org/fhir/StructureDefinition/ConceptMap-type-mapping");
row.vocabMapping = t.getExtensionString("http://hl7.org/fhir/StructureDefinition/ConceptMap-vocab-mapping");
if (t.getProduct().size() > 0) {
row.derived = t.getProductFirstRep().getProperty();
row.derivedMapping = t.getProductFirstRep().getValue();
}
}
row.comments = t.getComment();
rows.add(row);
}
}
}
}
use of org.hl7.fhir.r4b.model.ConceptMap in project org.hl7.fhir.core by hapifhir.
the class StructureMapUtilities method parseConceptMap.
private void parseConceptMap(StructureMap result, FHIRLexer lexer) throws FHIRLexerException {
lexer.token("conceptmap");
ConceptMap map = new ConceptMap();
String id = lexer.readConstant("map id");
if (id.startsWith("#")) {
throw lexer.error("Concept Map identifier must start with #");
}
map.setId(id);
// todo: how to add this to the text format
map.setStatus(PublicationStatus.DRAFT);
result.getContained().add(map);
lexer.token("{");
// lexer.token("source");
// map.setSource(new UriType(lexer.readConstant("source")));
// lexer.token("target");
// map.setSource(new UriType(lexer.readConstant("target")));
Map<String, String> prefixes = new HashMap<String, String>();
while (lexer.hasToken("prefix")) {
lexer.token("prefix");
String n = lexer.take();
lexer.token("=");
String v = lexer.readConstant("prefix url");
prefixes.put(n, v);
}
while (lexer.hasToken("unmapped")) {
lexer.token("unmapped");
lexer.token("for");
String n = readPrefix(prefixes, lexer);
ConceptMapGroupComponent g = getGroup(map, n, null);
lexer.token("=");
String v = lexer.take();
if (v.equals("provided")) {
g.getUnmapped().setMode(ConceptMapGroupUnmappedMode.PROVIDED);
} else {
throw lexer.error("Only unmapped mode PROVIDED is supported at this time");
}
}
while (!lexer.hasToken("}")) {
String srcs = readPrefix(prefixes, lexer);
lexer.token(":");
String sc = lexer.getCurrent().startsWith("\"") ? lexer.readConstant("code") : lexer.take();
ConceptMapEquivalence eq = readEquivalence(lexer);
String tgts = (eq != ConceptMapEquivalence.UNMATCHED) ? readPrefix(prefixes, lexer) : "";
ConceptMapGroupComponent g = getGroup(map, srcs, tgts);
SourceElementComponent e = g.addElement();
e.setCode(sc);
if (e.getCode().startsWith("\"")) {
e.setCode(lexer.processConstant(e.getCode()));
}
TargetElementComponent tgt = e.addTarget();
tgt.setEquivalence(eq);
if (tgt.getEquivalence() != ConceptMapEquivalence.UNMATCHED) {
lexer.token(":");
tgt.setCode(lexer.take());
if (tgt.getCode().startsWith("\"")) {
tgt.setCode(lexer.processConstant(tgt.getCode()));
}
}
tgt.setComment(lexer.getFirstComment());
}
lexer.token("}");
}
use of org.hl7.fhir.r4b.model.ConceptMap in project org.hl7.fhir.core by hapifhir.
the class StructureMapUtilities method produceConceptMap.
private static void produceConceptMap(StringBuilder b, ConceptMap cm) {
b.append("conceptmap \"");
b.append(cm.getId());
b.append("\" {\r\n");
Map<String, String> prefixesSrc = new HashMap<String, String>();
Map<String, String> prefixesTgt = new HashMap<String, String>();
char prefix = 's';
for (ConceptMapGroupComponent cg : cm.getGroup()) {
if (!prefixesSrc.containsKey(cg.getSource())) {
prefixesSrc.put(cg.getSource(), String.valueOf(prefix));
b.append(" prefix ");
b.append(prefix);
b.append(" = \"");
b.append(cg.getSource());
b.append("\"\r\n");
prefix++;
}
if (!prefixesTgt.containsKey(cg.getTarget())) {
prefixesTgt.put(cg.getTarget(), String.valueOf(prefix));
b.append(" prefix ");
b.append(prefix);
b.append(" = \"");
b.append(cg.getTarget());
b.append("\"\r\n");
prefix++;
}
}
b.append("\r\n");
for (ConceptMapGroupComponent cg : cm.getGroup()) {
if (cg.hasUnmapped()) {
b.append(" unmapped for ");
b.append(prefixesSrc.get(cg.getSource()));
b.append(" = ");
b.append(cg.getUnmapped().getMode().toCode());
b.append("\r\n");
}
}
for (ConceptMapGroupComponent cg : cm.getGroup()) {
for (SourceElementComponent ce : cg.getElement()) {
b.append(" ");
b.append(prefixesSrc.get(cg.getSource()));
b.append(":");
if (Utilities.isToken(ce.getCode())) {
b.append(ce.getCode());
} else {
b.append("\"");
b.append(ce.getCode());
b.append("\"");
}
b.append(" ");
b.append(getChar(ce.getTargetFirstRep().getEquivalence()));
b.append(" ");
b.append(prefixesTgt.get(cg.getTarget()));
b.append(":");
if (Utilities.isToken(ce.getTargetFirstRep().getCode())) {
b.append(ce.getTargetFirstRep().getCode());
} else {
b.append("\"");
b.append(ce.getTargetFirstRep().getCode());
b.append("\"");
}
b.append("\r\n");
}
}
b.append("}\r\n\r\n");
}
use of org.hl7.fhir.r4b.model.ConceptMap in project org.hl7.fhir.core by hapifhir.
the class StructureMapUtilities method parse.
public StructureMap parse(String text, String srcName) throws FHIRException {
FHIRLexer lexer = new FHIRLexer(text, srcName);
if (lexer.done())
throw lexer.error("Map Input cannot be empty");
lexer.token("map");
StructureMap result = new StructureMap();
result.setUrl(lexer.readConstant("url"));
lexer.token("=");
result.setName(lexer.readConstant("name"));
result.setDescription(lexer.getAllComments());
while (lexer.hasToken("conceptmap")) parseConceptMap(result, lexer);
while (lexer.hasToken("uses")) parseUses(result, lexer);
while (lexer.hasToken("imports")) parseImports(result, lexer);
while (!lexer.done()) {
parseGroup(result, lexer);
}
return result;
}
use of org.hl7.fhir.r4b.model.ConceptMap in project org.hl7.fhir.core by hapifhir.
the class BaseWorkerContext method fetchResourceWithException.
@SuppressWarnings("unchecked")
public <T extends Resource> T fetchResourceWithException(String cls, String uri, CanonicalResource source) throws FHIRException {
if (uri == null) {
return null;
}
if ("StructureDefinition".equals(cls)) {
uri = ProfileUtilities.sdNs(uri, getOverrideVersionNs());
}
synchronized (lock) {
String version = null;
if (uri.contains("|")) {
version = uri.substring(uri.lastIndexOf("|") + 1);
uri = uri.substring(0, uri.lastIndexOf("|"));
}
if (uri.contains("#")) {
uri = uri.substring(0, uri.indexOf("#"));
}
if (cls == null || "Resource".equals(cls)) {
if (structures.has(uri)) {
return (T) structures.get(uri, version);
}
if (guides.has(uri)) {
return (T) guides.get(uri, version);
}
if (capstmts.has(uri)) {
return (T) capstmts.get(uri, version);
}
if (measures.has(uri)) {
return (T) measures.get(uri, version);
}
if (libraries.has(uri)) {
return (T) libraries.get(uri, version);
}
if (valueSets.has(uri)) {
return (T) valueSets.get(uri, version);
}
if (codeSystems.has(uri)) {
return (T) codeSystems.get(uri, version);
}
if (operations.has(uri)) {
return (T) operations.get(uri, version);
}
if (searchParameters.has(uri)) {
return (T) searchParameters.get(uri, version);
}
if (plans.has(uri)) {
return (T) plans.get(uri, version);
}
if (maps.has(uri)) {
return (T) maps.get(uri, version);
}
if (transforms.has(uri)) {
return (T) transforms.get(uri, version);
}
if (questionnaires.has(uri)) {
return (T) questionnaires.get(uri, version);
}
for (Map<String, ResourceProxy> rt : allResourcesById.values()) {
for (ResourceProxy r : rt.values()) {
if (uri.equals(r.getUrl())) {
return (T) r.getResource();
}
}
}
} else if ("ImplementationGuide".equals(cls)) {
return (T) guides.get(uri, version);
} else if ("CapabilityStatement".equals(cls)) {
return (T) capstmts.get(uri, version);
} else if ("Measure".equals(cls)) {
return (T) measures.get(uri, version);
} else if ("Library".equals(cls)) {
return (T) libraries.get(uri, version);
} else if ("StructureDefinition".equals(cls)) {
return (T) structures.get(uri, version);
} else if ("StructureMap".equals(cls)) {
return (T) transforms.get(uri, version);
} else if ("ValueSet".equals(cls)) {
return (T) valueSets.get(uri, version);
} else if ("CodeSystem".equals(cls)) {
return (T) codeSystems.get(uri, version);
} else if ("ConceptMap".equals(cls)) {
return (T) maps.get(uri, version);
} else if ("PlanDefinition".equals(cls)) {
return (T) plans.get(uri, version);
} else if ("OperationDefinition".equals(cls)) {
OperationDefinition od = operations.get(uri, version);
return (T) od;
} else if ("Questionnaire.class".equals(cls)) {
return (T) questionnaires.get(uri, version);
} else if ("SearchParameter.class".equals(cls)) {
SearchParameter res = searchParameters.get(uri, version);
return (T) res;
}
if ("CodeSystem".equals(cls) && codeSystems.has(uri)) {
return (T) codeSystems.get(uri, version);
}
if ("ValueSet".equals(cls) && valueSets.has(uri)) {
return (T) valueSets.get(uri, version);
}
if ("Questionnaire".equals(cls)) {
return (T) questionnaires.get(uri, version);
}
if (cls == null) {
if (uri.matches(Constants.URI_REGEX) && !uri.contains("ValueSet")) {
return null;
}
// it might be a special URL.
if (Utilities.isAbsoluteUrl(uri) || uri.startsWith("ValueSet/")) {
// findTxValueSet(uri);
Resource res = null;
if (res != null) {
return (T) res;
}
}
return null;
}
if (supportedCodeSystems.contains(uri)) {
return null;
}
throw new FHIRException(formatMessage(I18nConstants.NOT_DONE_YET_CANT_FETCH_, uri));
}
}
Aggregations