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);
}
use of org.hl7.fhir.r4.model.CodeType in project elexis-server by elexis.
the class ObservationResourceProvider method filterCode.
private List<Observation> filterCode(List<Observation> observations, CodeType code) {
ArrayList<Observation> ret = new ArrayList<>();
String systemString = CodeTypeUtil.getSystem(code).orElse("");
String codeString = CodeTypeUtil.getCode(code).orElse("");
for (Observation observation : observations) {
if (systemString.equals(CodingSystem.ELEXIS_LOCAL_LABORATORY_VITOLABKEY.getSystem())) {
if (CodeTypeUtil.isVitoLabkey(modelService, observation, codeString)) {
ret.add(observation);
}
} else if (CodeTypeUtil.isCodeInConcept(observation.getCode(), systemString, codeString)) {
ret.add(observation);
}
}
return ret;
}
use of org.hl7.fhir.r4.model.CodeType in project elexis-server by elexis.
the class MedicationRequestTest method updateMedicationRequest.
@Test
public void updateMedicationRequest() {
// load existing order
Bundle results = client.search().forResource(MedicationRequest.class).where(MedicationRequest.PATIENT.hasId(patient.getId())).returnBundle(Bundle.class).execute();
assertNotNull(results);
List<BundleEntryComponent> entries = results.getEntry();
assertFalse(entries.isEmpty());
Optional<MedicationRequest> activeOrder = getActiveOrderWithDosage(entries);
assertTrue(activeOrder.isPresent());
MedicationRequest updateOrder = activeOrder.get();
updateOrder.getDosageInstruction().get(0).setText("test");
List<Extension> entryTypes = updateOrder.getExtensionsByUrl("www.elexis.info/extensions/prescription/entrytype");
assertEquals(EntryType.FIXED_MEDICATION.name(), ((CodeType) entryTypes.get(0).getValue()).getValue());
entryTypes.get(0).setValue(new CodeType(EntryType.SYMPTOMATIC_MEDICATION.name()));
// update the medication
MethodOutcome outcome = client.update().resource(updateOrder).execute();
// read and validate change
MedicationRequest oldOrder = client.read().resource(MedicationRequest.class).withId(activeOrder.get().getId()).execute();
assertNotNull(oldOrder);
MedicationRequest newOrder = client.read().resource(MedicationRequest.class).withId(outcome.getId()).execute();
assertNotNull(newOrder);
assertEquals(MedicationRequestStatus.COMPLETED, oldOrder.getStatus());
assertEquals(MedicationRequestStatus.ACTIVE, newOrder.getStatus());
assertEquals("test", newOrder.getDosageInstruction().get(0).getText());
entryTypes = newOrder.getExtensionsByUrl("www.elexis.info/extensions/prescription/entrytype");
assertEquals(EntryType.SYMPTOMATIC_MEDICATION.name(), ((CodeType) entryTypes.get(0).getValue()).getValue());
}
Aggregations