use of org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionContainsComponent in project org.hl7.fhir.core by hapifhir.
the class TerminologyCache method generateExpandToken.
public CacheToken generateExpandToken(ValueSet vs, boolean heirarchical) {
CacheToken ct = new CacheToken();
ValueSet vsc = getVSEssense(vs);
for (ConceptSetComponent inc : vs.getCompose().getInclude()) if (inc.hasSystem())
ct.setName(getNameForSystem(inc.getSystem()));
for (ConceptSetComponent inc : vs.getCompose().getExclude()) if (inc.hasSystem())
ct.setName(getNameForSystem(inc.getSystem()));
for (ValueSetExpansionContainsComponent inc : vs.getExpansion().getContains()) if (inc.hasSystem())
ct.setName(getNameForSystem(inc.getSystem()));
JsonParser json = new JsonParser();
json.setOutputStyle(OutputStyle.PRETTY);
try {
ct.request = "{\"hierarchical\" : " + (heirarchical ? "true" : "false") + ", \"valueSet\" :" + extracted(json, vsc) + "}\r\n";
} catch (IOException e) {
throw new Error(e);
}
ct.key = String.valueOf(hashNWS(ct.request));
return ct;
}
use of org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionContainsComponent in project org.hl7.fhir.core by hapifhir.
the class Element method getAsICoding.
public ICoding getAsICoding() throws FHIRException {
if ("code".equals(fhirType())) {
if (property.getDefinition().getBinding().getStrength() != BindingStrength.REQUIRED)
return null;
ICodingImpl c = new ICodingImpl(true, true, false, false);
c.code = primitiveValue();
ValueSetExpansionOutcome vse = property.getContext().expandVS(property.getDefinition().getBinding(), true, false);
if (vse.getValueset() == null)
return null;
for (ValueSetExpansionContainsComponent cc : vse.getValueset().getExpansion().getContains()) {
if (cc.getCode().equals(c.code)) {
c.system = cc.getSystem();
if (cc.hasVersion()) {
c.doesVersion = true;
c.version = cc.getVersion();
}
if (cc.hasDisplay()) {
c.doesDisplay = true;
c.display = cc.getDisplay();
}
}
}
if (c.system == null)
return null;
return c;
} else if ("Coding".equals(fhirType())) {
ICodingImpl c = new ICodingImpl(true, true, true, true);
c.system = getNamedChildValue("system");
c.code = getNamedChildValue("code");
c.display = getNamedChildValue("display");
c.version = getNamedChildValue("version");
return c;
} else if ("Quantity".equals(fhirType())) {
ICodingImpl c = new ICodingImpl(true, true, false, false);
c.system = getNamedChildValue("system");
c.code = getNamedChildValue("code");
return c;
} else
return null;
}
use of org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionContainsComponent in project org.hl7.fhir.core by hapifhir.
the class QuestionnaireBuilder method makeTypeList.
private ValueSet makeTypeList(StructureDefinition profile, List<TypeRefComponent> types, String path) {
ValueSet vs = new ValueSet();
vs.setName("Type options for " + path);
vs.setDescription(vs.present());
vs.setStatus(PublicationStatus.ACTIVE);
vs.setExpansion(new ValueSetExpansionComponent());
vs.getExpansion().setIdentifier(Factory.createUUID());
vs.getExpansion().setTimestampElement(DateTimeType.now());
for (TypeRefComponent t : types) {
if (t.hasTarget()) {
for (UriType u : t.getTargetProfile()) {
if (u.getValue().startsWith("http://hl7.org/fhir/StructureDefinition/")) {
ValueSetExpansionContainsComponent cc = vs.getExpansion().addContains();
cc.setCode(u.getValue().substring(40));
cc.setSystem("http://hl7.org/fhir/resource-types");
cc.setDisplay(cc.getCode());
}
}
} else if (!t.hasProfile()) {
ValueSetExpansionContainsComponent cc = vs.getExpansion().addContains();
cc.setCode(t.getWorkingCode());
cc.setDisplay(t.getWorkingCode());
cc.setSystem("http://hl7.org/fhir/data-types");
} else
for (UriType u : t.getProfile()) {
ProfileUtilities pu = new ProfileUtilities(context, null, null);
StructureDefinition ps = pu.getProfile(profile, u.getValue());
if (ps != null) {
ValueSetExpansionContainsComponent cc = vs.getExpansion().addContains();
cc.setCode(u.getValue());
cc.setDisplay(ps.getType());
cc.setSystem("http://hl7.org/fhir/resource-types");
}
}
}
return vs;
}
use of org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionContainsComponent in project org.hl7.fhir.core by hapifhir.
the class StructureMapUtilities method buildCoding.
private Coding buildCoding(String uri, String code) throws FHIRException {
// if we can get this as a valueSet, we will
String system = null;
String display = null;
String version = null;
ValueSet vs = Utilities.noString(uri) ? null : worker.fetchResourceWithException(ValueSet.class, uri);
if (vs != null) {
ValueSetExpansionOutcome vse = worker.expandVS(vs, true, false);
if (vse.getError() != null)
throw new FHIRException(vse.getError());
CommaSeparatedStringBuilder b = new CommaSeparatedStringBuilder();
for (ValueSetExpansionContainsComponent t : vse.getValueset().getExpansion().getContains()) {
if (t.hasCode())
b.append(t.getCode());
if (code.equals(t.getCode()) && t.hasSystem()) {
system = t.getSystem();
version = t.getVersion();
display = t.getDisplay();
break;
}
if (code.equalsIgnoreCase(t.getDisplay()) && t.hasSystem()) {
system = t.getSystem();
version = t.getVersion();
display = t.getDisplay();
break;
}
}
if (system == null)
throw new FHIRException("The code '" + code + "' is not in the value set '" + uri + "' (valid codes: " + b.toString() + "; also checked displays)");
} else {
system = uri;
}
ValidationResult vr = worker.validateCode(terminologyServiceOptions.setVersionFlexible(true), system, version, code, null);
if (vr != null && vr.getDisplay() != null)
display = vr.getDisplay();
return new Coding().setSystem(system).setCode(code).setDisplay(display);
}
use of org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionContainsComponent in project org.hl7.fhir.core by hapifhir.
the class TerminologyCache method nameCacheToken.
public void nameCacheToken(ValueSet vs, CacheToken ct) {
if (vs != null) {
for (ConceptSetComponent inc : vs.getCompose().getInclude()) {
if (inc.hasSystem()) {
ct.setName(getNameForSystem(inc.getSystem()));
ct.hasVersion = inc.hasVersion();
}
}
for (ConceptSetComponent inc : vs.getCompose().getExclude()) {
if (inc.hasSystem()) {
ct.setName(getNameForSystem(inc.getSystem()));
ct.hasVersion = inc.hasVersion();
}
}
for (ValueSetExpansionContainsComponent inc : vs.getExpansion().getContains()) {
if (inc.hasSystem()) {
ct.setName(getNameForSystem(inc.getSystem()));
ct.hasVersion = inc.hasVersion();
}
}
}
}
Aggregations