use of org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionContainsComponent in project org.hl7.fhir.core by hapifhir.
the class ValueSetExpanderSimple method addCode.
private void addCode(String system, String code, String display) {
ValueSetExpansionContainsComponent n = new ValueSet.ValueSetExpansionContainsComponent();
n.setSystem(system);
n.setCode(code);
n.setDisplay(display);
String s = key(n);
if (!map.containsKey(s)) {
codes.add(n);
map.put(s, n);
}
}
use of org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionContainsComponent in project org.hl7.fhir.core by hapifhir.
the class ValueSetExpanderSimple method importValueSet.
private void importValueSet(String value, List<ValueSetExpansionParameterComponent> params) throws ETooCostly, TerminologyServiceException, FileNotFoundException, IOException {
if (value == null)
throw new TerminologyServiceException("unable to find value set with no identity");
ValueSet vs = context.fetchResource(ValueSet.class, value);
if (vs == null)
throw new TerminologyServiceException("Unable to find imported value set " + value);
ValueSetExpansionOutcome vso = factory.getExpander().expand(vs);
if (vso.getService() != null)
throw new TerminologyServiceException("Unable to expand imported value set " + value);
if (vs.hasVersion())
if (!existsInParams(params, "version", new UriType(vs.getUrl() + "?version=" + vs.getVersion())))
params.add(new ValueSetExpansionParameterComponent().setName("version").setValue(new UriType(vs.getUrl() + "?version=" + vs.getVersion())));
for (ValueSetExpansionParameterComponent p : vso.getValueset().getExpansion().getParameter()) {
if (!existsInParams(params, p.getName(), p.getValue()))
params.add(p);
}
for (ValueSetExpansionContainsComponent c : vso.getValueset().getExpansion().getContains()) {
addCode(c.getSystem(), c.getCode(), c.getDisplay());
}
}
use of org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionContainsComponent in project org.hl7.fhir.core by hapifhir.
the class ValueSetExpanderSimple method expand.
@Override
public ValueSetExpansionOutcome expand(ValueSet source) {
try {
focus = source.copy();
focus.setExpansion(new ValueSet.ValueSetExpansionComponent());
focus.getExpansion().setTimestampElement(DateTimeType.now());
focus.getExpansion().setIdentifier(Factory.createUUID());
if (source.hasCompose())
handleCompose(source.getCompose(), focus.getExpansion().getParameter());
for (ValueSetExpansionContainsComponent c : codes) {
if (map.containsKey(key(c))) {
focus.getExpansion().getContains().add(c);
}
}
return new ValueSetExpansionOutcome(focus, null);
} catch (RuntimeException e) {
// it swallows bugs.. what would be expected to be caught there?
throw e;
} catch (Exception e) {
// that might fail too, but it might not, later.
return new ValueSetExpansionOutcome(new ValueSetCheckerSimple(source, factory, context), e.getMessage());
}
}
use of org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionContainsComponent in project org.hl7.fhir.core by hapifhir.
the class ProfileComparer method intersectByExpansion.
private ValueSet intersectByExpansion(ValueSet lvs, ValueSet rvs) {
// this is pretty straight forward - we intersect the lists, and build a compose out of the intersection
ValueSet vs = new ValueSet();
vs.setStatus(PublicationStatus.DRAFT);
Map<String, ValueSetExpansionContainsComponent> left = new HashMap<String, ValueSetExpansionContainsComponent>();
scan(lvs.getExpansion().getContains(), left);
Map<String, ValueSetExpansionContainsComponent> right = new HashMap<String, ValueSetExpansionContainsComponent>();
scan(rvs.getExpansion().getContains(), right);
Map<String, ConceptSetComponent> inc = new HashMap<String, ConceptSetComponent>();
for (String s : left.keySet()) {
if (right.containsKey(s)) {
ValueSetExpansionContainsComponent cc = left.get(s);
ConceptSetComponent c = inc.get(cc.getSystem());
if (c == null) {
c = vs.getCompose().addInclude().setSystem(cc.getSystem());
inc.put(cc.getSystem(), c);
}
c.addConcept().setCode(cc.getCode()).setDisplay(cc.getDisplay());
}
}
return vs;
}
use of org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionContainsComponent in project org.hl7.fhir.core by hapifhir.
the class JavaResourceGenerator method generateEnum.
private void generateEnum(EnumInfo e) throws Exception {
String tn = e.getName();
String tns = tn;
if (tn.startsWith("Enumeration<")) {
tns = tn.substring(tn.indexOf("<") + 1);
tns = tns.substring(0, tns.length() - 1);
} else {
tn = "Enumeration<" + tn + ">";
}
ValueSet vs = e.getValueSet();
ValueSet vse = (ValueSet) vs.getUserData("expansion");
if (vs.hasUserData("shared")) {
return;
}
if (vse == null) {
return;
}
List<ValueSetExpansionContainsComponent> codes = vse.getExpansion().getContains();
String url = vs.getUrl();
CommaSeparatedStringBuilder el = new CommaSeparatedStringBuilder();
write(" public enum " + tns + " {\r\n");
int l = codes.size();
int i = 0;
for (ValueSetExpansionContainsComponent c : codes) {
i++;
String cc = Utilities.camelCase(c.getCode());
cc = makeConst(cc);
el.append(cc);
String definition = definitions.getCodeDefinition(c.getSystem(), c.getCode());
write(" /**\r\n");
write(" * " + Utilities.escapeJava(definition) + "\r\n");
write(" */\r\n");
write(" " + cc.toUpperCase() + ", \r\n");
}
write(" /**\r\n");
write(" * added to help the parsers with the generic types\r\n");
write(" */\r\n");
write(" NULL;\r\n");
el.append("NULL");
write(" public static " + tns + " fromCode(String codeString) throws FHIRException {\r\n");
write(" if (codeString == null || \"\".equals(codeString))\r\n");
write(" return null;\r\n");
for (ValueSetExpansionContainsComponent c : codes) {
String cc = Utilities.camelCase(c.getCode());
cc = makeConst(cc);
write(" if (\"" + c.getCode() + "\".equals(codeString))\r\n");
write(" return " + cc + ";\r\n");
}
write(" if (Configuration.isAcceptInvalidEnums())\r\n");
write(" return null;\r\n");
write(" else\r\n");
write(" throw new FHIRException(\"Unknown " + tns + " code '\"+codeString+\"'\");\r\n");
write(" }\r\n");
write(" public String toCode() {\r\n");
write(" switch (this) {\r\n");
for (ValueSetExpansionContainsComponent c : codes) {
String cc = Utilities.camelCase(c.getCode());
cc = makeConst(cc);
write(" case " + cc + ": return \"" + c.getCode() + "\";\r\n");
}
write(" case NULL: return null;\r\n");
write(" default: return \"?\";\r\n");
write(" }\r\n");
write(" }\r\n");
write(" public String getSystem() {\r\n");
write(" switch (this) {\r\n");
for (ValueSetExpansionContainsComponent c : codes) {
String cc = Utilities.camelCase(c.getCode());
cc = makeConst(cc);
write(" case " + cc + ": return \"" + c.getSystem() + "\";\r\n");
}
write(" case NULL: return null;\r\n");
write(" default: return \"?\";\r\n");
write(" }\r\n");
write(" }\r\n");
write(" public String getDefinition() {\r\n");
write(" switch (this) {\r\n");
for (ValueSetExpansionContainsComponent c : codes) {
String cc = Utilities.camelCase(c.getCode());
cc = makeConst(cc);
String definition = definitions.getCodeDefinition(c.getSystem(), c.getCode());
write(" case " + cc + ": return \"" + Utilities.escapeJava(definition) + "\";\r\n");
}
write(" case NULL: return null;\r\n");
write(" default: return \"?\";\r\n");
write(" }\r\n");
write(" }\r\n");
write(" public String getDisplay() {\r\n");
write(" switch (this) {\r\n");
for (ValueSetExpansionContainsComponent c : codes) {
String cc = Utilities.camelCase(c.getCode());
cc = makeConst(cc);
write(" case " + cc + ": return \"" + Utilities.escapeJava(Utilities.noString(c.getDisplay()) ? c.getCode() : c.getDisplay()) + "\";\r\n");
}
write(" case NULL: return null;\r\n");
write(" default: return \"?\";\r\n");
write(" }\r\n");
write(" }\r\n");
write(" }\r\n");
write("\r\n");
write(" public static class " + tns + "EnumFactory implements EnumFactory<" + tns + "> {\r\n");
write(" public " + tns + " fromCode(String codeString) throws IllegalArgumentException {\r\n");
write(" if (codeString == null || \"\".equals(codeString))\r\n");
write(" if (codeString == null || \"\".equals(codeString))\r\n");
write(" return null;\r\n");
for (ValueSetExpansionContainsComponent c : codes) {
String cc = Utilities.camelCase(c.getCode());
cc = makeConst(cc);
write(" if (\"" + c.getCode() + "\".equals(codeString))\r\n");
write(" return " + tns + "." + cc + ";\r\n");
}
write(" throw new IllegalArgumentException(\"Unknown " + tns + " code '\"+codeString+\"'\");\r\n");
write(" }\r\n");
write(" public Enumeration<" + tns + "> fromType(Base code) throws FHIRException {\r\n");
write(" if (code == null)\r\n");
write(" return null;\r\n");
write(" if (code.isEmpty())\r\n");
write(" return new Enumeration<" + tns + ">(this);\r\n");
write(" String codeString = ((PrimitiveType) code).asStringValue();\r\n");
write(" if (codeString == null || \"\".equals(codeString))\r\n");
write(" return null;\r\n");
for (ValueSetExpansionContainsComponent c : codes) {
String cc = Utilities.camelCase(c.getCode());
cc = makeConst(cc);
write(" if (\"" + c.getCode() + "\".equals(codeString))\r\n");
write(" return new Enumeration<" + tns + ">(this, " + tns + "." + cc + ");\r\n");
}
write(" throw new FHIRException(\"Unknown " + tns + " code '\"+codeString+\"'\");\r\n");
write(" }\r\n");
write(" public String toCode(" + tns + " code) {\r\n");
for (ValueSetExpansionContainsComponent c : codes) {
String cc = Utilities.camelCase(c.getCode());
cc = makeConst(cc);
write(" if (code == " + tns + "." + cc + ")\r\n return \"" + c.getCode() + "\";\r\n");
}
write(" return \"?\";\r\n");
write(" }\r\n");
write(" public String toSystem(" + tns + " code) {\r\n");
write(" return code.getSystem();\r\n");
write(" }\r\n");
write(" }\r\n");
write("\r\n");
// enumInfo.put("org.hl7.fhir."+jid+".model."+name+"."+tns, url+"|"+el.toString());
}
Aggregations