use of org.hl7.fhir.r4.model.CodeType in project kindling by HL7.
the class Regenerator method generateInner.
public void generateInner(ResourceDefn r) throws FileNotFoundException, IOException {
String root = Utilities.path(srcFolder, r.getName());
generateSearchParams(root, r);
generateExamples(root, r);
generateOperations(r, root);
generatePacks(r, root);
// private List<Profile> conformancePackages = new ArrayList<Profile>();
// private Profile conformancePack;
StructureDefinition sd = r.getProfile().copy();
sd.setSnapshot(null);
sd.setText(null);
if (r.getEnteredInErrorStatus() != null) {
sd.addExtension(BuildExtensions.EXT_ENTERED_IN_ERROR_STATUS, new CodeType(r.getEnteredInErrorStatus()));
}
if (r.getProposedOrder() != null) {
sd.addExtension(BuildExtensions.EXT_PROPOSED_ORDER, new StringType(r.getProposedOrder()));
}
if (r.getTemplate() != null) {
sd.addExtension(BuildExtensions.EXT_TEMPLATE, new StringType(r.getTemplate().getName()));
}
// now, walk through the elements.
generateElement(root, r.getName(), sd.getDifferential(), r, r.getRoot());
File fn = new File(Utilities.path(root, sd.fhirType().toLowerCase() + "-" + sd.getId() + ".gen.xml"));
new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(fn), sd);
fn.setLastModified(r.getTimestamp());
}
use of org.hl7.fhir.r4.model.CodeType in project kindling by HL7.
the class Regenerator method generateExamples.
private void generateExamples(String root, ResourceDefn r) throws FileNotFoundException, IOException {
ListResource list = new ListResource();
list.setId(r.getName() + "-examples");
list.setStatus(ListStatus.CURRENT);
list.setMode(ListMode.WORKING);
for (Example ex : r.getExamples()) {
ListResourceEntryComponent li = list.addEntry();
li.getItem().setReference(ex.getResourceName() + "/" + ex.getId());
li.getItem().setDisplay(ex.getName());
if (ex.getDescription() != null) {
li.addExtension(BuildExtensions.EXT_DESCRIPTION, new StringType(ex.getDescription()));
}
if (ex.getTitle() != null) {
li.addExtension(BuildExtensions.EXT_TITLE, new StringType(ex.getTitle()));
}
switch(ex.getType()) {
case Container:
li.getFlag().addCoding(BuildExtensions.EXT_EXAMPLE_TYPE, "container", null);
break;
case CsvFile:
li.getFlag().addCoding(BuildExtensions.EXT_EXAMPLE_TYPE, "csv", null);
break;
case Tool:
li.getFlag().addCoding(BuildExtensions.EXT_EXAMPLE_TYPE, "tool", null);
break;
default:
break;
}
if (!ex.isRegistered()) {
li.addExtension(BuildExtensions.EXT_NOT_REGISTERED, new BooleanType(!ex.isRegistered()));
}
if (ex.getIg() != null) {
li.addExtension(BuildExtensions.EXT_IG, new CodeType(ex.getIg()));
}
if (ex.getExampleFor() != null) {
li.addExtension(BuildExtensions.EXT_EXAMPLE_FOR, new StringType(ex.getExampleFor()));
}
}
File fn = new File(Utilities.path(root, list.fhirType().toLowerCase() + "-" + list.getId() + ".gen.xml"));
new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(fn), list);
fn.setLastModified(r.getTimestamp());
}
use of org.hl7.fhir.r4.model.CodeType in project kindling by HL7.
the class ProfileGenerator method makeSearchParam.
public SearchParameter makeSearchParam(StructureDefinition p, String id, String rn, SearchParameterDefn spd, ResourceDefn rd) throws Exception {
boolean shared;
boolean created = true;
SearchParameter sp;
if (definitions.getCommonSearchParameters().containsKey(rn + "::" + spd.getCode())) {
shared = true;
CommonSearchParameter csp = definitions.getCommonSearchParameters().get(rn + "::" + spd.getCode());
if (csp.getDefinition() == null) {
sp = new SearchParameter();
csp.setDefinition(sp);
sp.setId(csp.getId());
} else {
created = false;
sp = csp.getDefinition();
}
} else {
shared = false;
sp = new SearchParameter();
sp.setId(id.replace("[", "").replace("]", ""));
}
spd.setCommonId(sp.getId());
if (created) {
sp.setUrl("http://hl7.org/fhir/SearchParameter/" + sp.getId());
sp.setVersion(version.toCode());
if (context.getSearchParameter(sp.getUrl()) != null)
throw new Exception("Duplicated Search Parameter " + sp.getUrl());
context.cacheResource(sp);
spd.setResource(sp);
definitions.addNs(sp.getUrl(), "Search Parameter: " + sp.getName(), rn.toLowerCase() + ".html#search");
sp.setStatus(spd.getStandardsStatus() == StandardsStatus.NORMATIVE ? PublicationStatus.fromCode("active") : PublicationStatus.fromCode("draft"));
StandardsStatus sst = ToolingExtensions.getStandardsStatus(sp);
if (sst == null || (spd.getStandardsStatus() == null && spd.getStandardsStatus().isLowerThan(sst)))
ToolingExtensions.setStandardsStatus(sp, spd.getStandardsStatus(), spd.getNormativeVersion());
sp.setExperimental(p.getExperimental());
sp.setName(spd.getCode());
sp.setCode(spd.getCode());
sp.setDate(genDate.getTime());
sp.setPublisher(p.getPublisher());
for (ContactDetail tc : p.getContact()) {
ContactDetail t = sp.addContact();
if (tc.hasNameElement())
t.setNameElement(tc.getNameElement().copy());
for (ContactPoint ts : tc.getTelecom()) t.getTelecom().add(ts.copy());
}
if (!definitions.hasResource(p.getType()) && !p.getType().equals("Resource") && !p.getType().equals("DomainResource"))
throw new Exception("unknown resource type " + p.getType());
sp.setType(getSearchParamType(spd.getType()));
if (sp.getType() == SearchParamType.REFERENCE && spd.isHierarchy()) {
sp.addModifier(SearchParameter.SearchModifierCode.BELOW);
sp.addModifier(SearchParameter.SearchModifierCode.ABOVE);
}
if (shared) {
sp.setDescription("Multiple Resources: \r\n\r\n* [" + rn + "](" + rn.toLowerCase() + ".html): " + spd.getDescription() + "\r\n");
} else
sp.setDescription(preProcessMarkdown(spd.getDescription(), "Search Description"));
if (!Utilities.noString(spd.getExpression()))
sp.setExpression(spd.getExpression());
// addModifiers(sp);
addComparators(sp);
String xpath = Utilities.noString(spd.getXPath()) ? new XPathQueryGenerator(this.definitions, null, null).generateXpath(spd.getPaths(), rn) : spd.getXPath();
if (xpath != null) {
if (xpath.contains("[x]"))
xpath = convertToXpath(xpath);
sp.setXpath(xpath);
sp.setXpathUsage(spd.getxPathUsage());
}
if (sp.getType() == SearchParamType.COMPOSITE) {
for (CompositeDefinition cs : spd.getComposites()) {
SearchParameterDefn cspd = findSearchParameter(rd, cs.getDefinition());
if (cspd != null)
sp.addComponent().setExpression(cs.getExpression()).setDefinition(cspd.getUrl());
else
sp.addComponent().setExpression(cs.getExpression()).setDefinition("http://hl7.org/fhir/SearchParameter/" + rn + "-" + cs.getDefinition());
}
sp.setMultipleOr(false);
}
sp.addBase(p.getType());
} else {
if (sp.getType() != getSearchParamType(spd.getType()))
throw new FHIRException("Type mismatch on common parameter: expected " + sp.getType().toCode() + " but found " + getSearchParamType(spd.getType()).toCode());
if (!sp.getDescription().contains("[" + rn + "](" + rn.toLowerCase() + ".html)"))
sp.setDescription(sp.getDescription() + "* [" + rn + "](" + rn.toLowerCase() + ".html): " + spd.getDescription() + "\r\n");
// ext.addExtension("description", new MarkdownType(spd.getDescription()));
if (!Utilities.noString(spd.getExpression()) && !sp.getExpression().contains(spd.getExpression()))
sp.setExpression(sp.getExpression() + " | " + spd.getExpression());
String xpath = new XPathQueryGenerator(this.definitions, null, null).generateXpath(spd.getPaths(), rn);
if (xpath != null) {
if (xpath.contains("[x]"))
xpath = convertToXpath(xpath);
if (sp.getXpath() != null && !sp.getXpath().contains(xpath))
sp.setXpath(sp.getXpath() + " | " + xpath);
if (sp.getXpathUsage() != spd.getxPathUsage())
throw new FHIRException("Usage mismatch on common parameter: expected " + sp.getXpathUsage().toCode() + " but found " + spd.getxPathUsage().toCode());
}
boolean found = false;
for (CodeType ct : sp.getBase()) found = found || p.getType().equals(ct.asStringValue());
if (!found)
sp.addBase(p.getType());
}
spd.setUrl(sp.getUrl());
for (String target : spd.getWorkingTargets()) {
if ("Any".equals(target) == true) {
for (String resourceName : definitions.sortedResourceNames()) {
boolean found = false;
for (CodeType st : sp.getTarget()) found = found || st.asStringValue().equals(resourceName);
if (!found)
sp.addTarget(resourceName);
}
} else {
boolean found = false;
for (CodeType st : sp.getTarget()) found = found || st.asStringValue().equals(target);
if (!found)
sp.addTarget(target);
}
}
return sp;
}
use of org.hl7.fhir.r4.model.CodeType in project quality-measure-and-cohort-service by Alvearie.
the class R4RestFhirTerminologyProvider method lookup.
/**
* This is a small patch to the OSS implementation to use named-parameter lookup on
* the operation response instead of just assuming a positional location.
*/
@Override
public Code lookup(Code code, CodeSystemInfo codeSystem) throws ResourceNotFoundException {
Parameters respParam = fhirClient.operation().onType(CodeSystem.class).named("lookup").withParameter(Parameters.class, "code", new CodeType(code.getCode())).andParameter("system", new UriType(codeSystem.getId())).execute();
StringType display = (StringType) respParam.getParameter("display");
if (display != null) {
code.withDisplay(display.getValue());
}
return code.withSystem(codeSystem.getId());
}
use of org.hl7.fhir.r4.model.CodeType in project quality-measure-and-cohort-service by Alvearie.
the class ValueSetUtilTest method testCorrectValidation.
@Test
public void testCorrectValidation() {
ValueSetArtifact artifact = new ValueSetArtifact();
artifact.setUrl("fakeUrl");
ValueSet fakeValueSet = new ValueSet();
fakeValueSet.setId("fakeId");
fakeValueSet.setVersion("fakeVersion");
ValueSet.ValueSetComposeComponent compose = new ValueSet.ValueSetComposeComponent();
ValueSet.ConceptSetComponent component = new ValueSet.ConceptSetComponent();
component.setConcept(Collections.singletonList(new ValueSet.ConceptReferenceComponent(new CodeType("fakeCode"))));
compose.setInclude(Collections.singletonList(component));
fakeValueSet.setCompose(compose);
artifact.setFhirResource(fakeValueSet);
ValueSetUtil.validateArtifact(artifact);
}
Aggregations