use of org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionComponent in project org.hl7.fhir.core by hapifhir.
the class ValueSetRenderer method generateContentModeNotice.
private void generateContentModeNotice(XhtmlNode x, ValueSetExpansionComponent expansion, String mode, String text) {
Multimap<String, String> versions = HashMultimap.create();
for (ValueSetExpansionParameterComponent p : expansion.getParameter()) {
if (p.getName().equals(mode)) {
String[] parts = ((PrimitiveType) p.getValue()).asStringValue().split("\\|");
if (parts.length == 2)
versions.put(parts[0], parts[1]);
}
}
if (versions.size() > 0) {
XhtmlNode div = null;
XhtmlNode ul = null;
boolean first = true;
for (String s : versions.keySet()) {
if (versions.size() == 1 && versions.get(s).size() == 1) {
for (String v : versions.get(s)) {
// though there'll only be one
XhtmlNode p = x.para().style("border: black 1px dotted; background-color: #ffcccc; padding: 8px; margin-bottom: 8px");
p.tx(text + " ");
expRef(p, s, v);
}
} else {
for (String v : versions.get(s)) {
if (first) {
div = x.div().style("border: black 1px dotted; background-color: #EEEEEE; padding: 8px; margin-bottom: 8px");
div.para().tx(text + "s: ");
ul = div.ul();
first = false;
}
expRef(ul.li(), s, v);
}
}
}
}
}
use of org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionComponent in project org.hl7.fhir.core by hapifhir.
the class ValueSetRenderer method generateVersionNotice.
@SuppressWarnings("rawtypes")
private void generateVersionNotice(XhtmlNode x, ValueSetExpansionComponent expansion) {
Multimap<String, String> versions = HashMultimap.create();
for (ValueSetExpansionParameterComponent p : expansion.getParameter()) {
if (p.getName().equals("version")) {
String[] parts = ((PrimitiveType) p.getValue()).asStringValue().split("\\|");
if (parts.length == 2)
versions.put(parts[0], parts[1]);
}
}
if (versions.size() > 0) {
XhtmlNode div = null;
XhtmlNode ul = null;
boolean first = true;
for (String s : versions.keySet()) {
if (versions.size() == 1 && versions.get(s).size() == 1) {
for (String v : versions.get(s)) {
// though there'll only be one
XhtmlNode p = x.para().style("border: black 1px dotted; background-color: #EEEEEE; padding: 8px; margin-bottom: 8px");
p.tx("Expansion based on ");
expRef(p, s, v);
}
} else {
for (String v : versions.get(s)) {
if (first) {
div = x.div().style("border: black 1px dotted; background-color: #EEEEEE; padding: 8px; margin-bottom: 8px");
div.para().tx("Expansion based on: ");
ul = div.ul();
first = false;
}
expRef(ul.li(), s, v);
}
}
}
}
}
use of org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionComponent in project org.hl7.fhir.core by hapifhir.
the class ValueSetRenderer method getConceptsForCodes.
private Map<String, ConceptDefinitionComponent> getConceptsForCodes(CodeSystem e, ConceptSetComponent inc) {
if (e == null) {
e = getContext().getWorker().fetchCodeSystem(inc.getSystem());
}
ValueSetExpansionComponent vse = null;
if (!context.isNoSlowLookup() && !getContext().getWorker().hasCache()) {
try {
ValueSetExpansionOutcome vso = getContext().getWorker().expandVS(inc, false, false);
ValueSet valueset = vso.getValueset();
if (valueset == null)
throw new TerminologyServiceException("Error Expanding ValueSet: " + vso.getError());
vse = valueset.getExpansion();
} catch (TerminologyServiceException e1) {
return null;
}
}
Map<String, ConceptDefinitionComponent> results = new HashMap<>();
List<CodingValidationRequest> serverList = new ArrayList<>();
// 1st pass, anything we can resolve internally
for (ConceptReferenceComponent cc : inc.getConcept()) {
String code = cc.getCode();
ConceptDefinitionComponent v = null;
if (e != null) {
v = getConceptForCode(e.getConcept(), code);
}
if (v == null && vse != null) {
v = getConceptForCodeFromExpansion(vse.getContains(), code);
}
if (v != null) {
results.put(code, v);
} else {
serverList.add(new CodingValidationRequest(new Coding(inc.getSystem(), code, null)));
}
}
if (!context.isNoSlowLookup() && !serverList.isEmpty()) {
getContext().getWorker().validateCodeBatch(getContext().getTerminologyServiceOptions(), serverList, null);
for (CodingValidationRequest vr : serverList) {
ConceptDefinitionComponent v = vr.getResult().asConceptDefinition();
if (v != null) {
results.put(vr.getCoding().getCode(), v);
}
}
}
return results;
}
use of org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionComponent 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.getName());
vs.setStatus(PublicationStatus.ACTIVE);
vs.setExpansion(new ValueSetExpansionComponent());
vs.getExpansion().setIdentifier(Factory.createUUID());
vs.getExpansion().setTimestampElement(DateTimeType.now());
for (TypeRefComponent t : types) {
ValueSetExpansionContainsComponent cc = vs.getExpansion().addContains();
if (t.getCode().equals("Reference") && (t.hasTargetProfile() && t.getTargetProfile().startsWith("http://hl7.org/fhir/StructureDefinition/"))) {
cc.setCode(t.getTargetProfile().substring(40));
cc.setSystem("http://hl7.org/fhir/resource-types");
cc.setDisplay(cc.getCode());
} else {
ProfileUtilities pu = new ProfileUtilities(context, null, null);
StructureDefinition ps = null;
if (t.hasTargetProfile())
ps = pu.getProfile(profile, t.getTargetProfile());
else if (t.hasProfile())
ps = pu.getProfile(profile, t.getProfile());
if (ps != null) {
cc.setCode(t.getTargetProfile());
cc.setDisplay(ps.getType());
cc.setSystem("http://hl7.org/fhir/resource-types");
} else {
cc.setCode(t.getCode());
cc.setDisplay(t.getCode());
cc.setSystem("http://hl7.org/fhir/data-types");
}
}
t.setUserData("text", cc.getCode());
}
return vs;
}
use of org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionComponent in project org.hl7.fhir.core by hapifhir.
the class NarrativeGenerator method getConceptForCode.
private ConceptDefinitionComponent getConceptForCode(CodeSystem e, String code, ConceptSetComponent inc) {
// first, look in the code systems
if (e == null)
e = context.fetchCodeSystem(inc.getSystem());
if (e != null) {
ConceptDefinitionComponent v = getConceptForCode(e.getConcept(), code);
if (v != null)
return v;
}
if (!context.hasCache()) {
ValueSetExpansionComponent vse;
try {
ValueSetExpansionOutcome vso = context.expandVS(inc, false);
ValueSet valueset = vso.getValueset();
if (valueset == null)
throw new TerminologyServiceException("Error Expanding ValueSet: " + vso.getError());
vse = valueset.getExpansion();
} catch (TerminologyServiceException e1) {
return null;
}
if (vse != null) {
ConceptDefinitionComponent v = getConceptForCodeFromExpansion(vse.getContains(), code);
if (v != null)
return v;
}
}
return context.validateCode(terminologyServiceOptions, inc.getSystem(), code, null).asConceptDefinition();
}
Aggregations