use of org.hl7.fhir.dstu2016may.model.DomainResource in project kindling by HL7.
the class ProfileGenerator method addElementConstraint.
/*
* // resource
// domain resource
for (ElementDefn child : definitions.getBaseResources().get("DomainResource").getRoot().getElements())
defineElement(null, p, p.getSnapshot(), child, r.getRoot().getName()+"."+child.getName(), containedSlices, new ArrayList<ProfileGenerator.SliceHandle>(), SnapShotMode.Resource);
*/
/*
private String registerMapping(ConformancePackage ap, StructureDefinition p, String m) {
for (StructureDefinitionMappingComponent map : p.getMapping()) {
if (map.getUri().equals(m))
return map.getIdentity();
}
StructureDefinitionMappingComponent map = new StructureDefinitionMappingComponent();
MappingSpace space = definitions.getMapTypes().get(m);
if (space != null)
map.setIdentity(space.getId());
else
map.setIdentity("m" + Integer.toString(p.getMapping().size()+1));
map.setUri(m);
String name = ap.metadata(m+"-name");
if (Utilities.noString(name) && space != null)
name = space.getTitle();
if (!Utilities.noString(name))
map.setName(name);
String comments = ap.metadata(m+"-comments");
if (Utilities.noString(comments) && space != null)
comments = space.getPreamble();
if (!Utilities.noString(comments))
map.setComments(comments);
return map.getIdentity();
}
*/
private ElementDefinition addElementConstraint(StructureDefinition sd, ElementDefinition ed) {
if (!ed.getPath().contains(".") && sd.getKind() == StructureDefinitionKind.RESOURCE)
return ed;
if (hasSystemType(ed))
return ed;
if (isResource(ed))
return ed;
if (hasConstraint(ed, "ele-1"))
return ed;
ElementDefinitionConstraintComponent inv = ed.addConstraint();
inv.setKey("ele-1");
inv.setSeverity(ConstraintSeverity.ERROR);
inv.setHuman("All FHIR elements must have a @value or children");
inv.setExpression("hasValue() or (children().count() > id.count())");
inv.setXpath("@value|f:*|h:div");
inv.setSource("http://hl7.org/fhir/StructureDefinition/Element");
return ed;
}
use of org.hl7.fhir.dstu2016may.model.DomainResource in project cqf-ruler by DBCG.
the class PlanDefinitionApplyProviderIT method testPlanDefinitionApplyFormerSmoker.
@Test
public void testPlanDefinitionApplyFormerSmoker() throws Exception {
DomainResource plandefinition = (DomainResource) planDefinitions.get("lcs-cds-patient-view");
// Patient First
uploadTests("test/plandefinition/LungCancerScreening/Former-Smoker/Patient");
Map<String, IBaseResource> resources = uploadTests("test/plandefinition/LungCancerScreening/Former-Smoker");
IBaseResource patient = resources.get("Former-Smoker");
Object isFormerSmoker = planDefinitionApplyProvider.applyPlanDefinition(new SystemRequestDetails(), plandefinition.getIdElement(), patient.getIdElement().getIdPart(), null, null, null, null, null, null, null, null);
assertTrue(isFormerSmoker instanceof CarePlan);
}
use of org.hl7.fhir.dstu2016may.model.DomainResource in project cqf-ruler by DBCG.
the class ExpressionEvaluation method setupContext.
private Context setupContext(DomainResource instance, String cql, String patientId, Boolean aliasedExpression, RequestDetails theRequest) {
JpaFhirDal jpaFhirDal = jpaFhirDalFactory.create(theRequest);
List<CanonicalType> libraries = getLibraryReferences(instance, theRequest);
String fhirVersion = this.fhirContext.getVersion().getVersion().getFhirVersionString();
// Remove LocalLibrary from cache first...
VersionedIdentifier localLibraryIdentifier = new VersionedIdentifier().withId("LocalLibrary");
globalLibraryCache.remove(localLibraryIdentifier);
// temporary LibraryLoader to resolve library dependencies when building
// includes
LibraryLoader tempLibraryLoader = libraryLoaderFactory.create(new ArrayList<LibraryContentProvider>(Arrays.asList(jpaLibraryContentProviderFactory.create(theRequest))));
String source = "";
if (aliasedExpression) {
if (libraries.size() != 1) {
throw new RuntimeException("If an aliased expression is provided, there must be exactly one primary Library");
}
VersionedIdentifier vi = getVersionedIdentifierFromCanonical(libraries.get(0));
// Still not the best way to build include, but at least checks dal for an
// existing library
// Check if id works for LibraryRetrieval
org.cqframework.cql.elm.execution.Library executionLibrary = null;
try {
executionLibrary = tempLibraryLoader.load(vi);
} catch (Exception e) {
// log error
}
if (executionLibrary == null) {
Library library = (Library) jpaFhirDal.read(new IdType("Library", Canonicals.getIdPart(libraries.get(0))));
vi.setId(library.getName());
if (library.getVersion() != null) {
vi.setVersion(library.getVersion());
}
}
source = String.format("library LocalLibrary using FHIR version '" + fhirVersion + "' include FHIRHelpers version '" + fhirVersion + "' called FHIRHelpers %s parameter %s %s parameter \"%%context\" %s define Expression: %s", buildIncludes(tempLibraryLoader, jpaFhirDal, libraries, theRequest), instance.fhirType(), instance.fhirType(), instance.fhirType(), vi.getId() + ".\"" + cql + "\"");
} else {
source = String.format("library LocalLibrary using FHIR version '" + fhirVersion + "' include FHIRHelpers version '" + fhirVersion + "' called FHIRHelpers %s parameter %s %s parameter \"%%context\" %s define Expression: %s", buildIncludes(tempLibraryLoader, jpaFhirDal, libraries, theRequest), instance.fhirType(), instance.fhirType(), instance.fhirType(), cql);
}
LibraryLoader libraryLoader = libraryLoaderFactory.create(new ArrayList<LibraryContentProvider>(Arrays.asList(jpaLibraryContentProviderFactory.create(theRequest), new InMemoryLibraryContentProvider(Arrays.asList(source)))));
// resolve execution context
return setupContext(instance, patientId, libraryLoader, theRequest);
}
use of org.hl7.fhir.dstu2016may.model.DomainResource in project cqf-ruler by DBCG.
the class PlanDefinitionApplyProviderIT method testPlanDefinitionApplyRec10NoScreenings.
@Test
public void testPlanDefinitionApplyRec10NoScreenings() throws Exception {
DomainResource plandefinition = (DomainResource) planDefinitions.get("opioidcds-10");
// Patient First
uploadTests("test/plandefinition/Rec10/Patient");
Map<String, IBaseResource> resources = uploadTests("test/plandefinition/Rec10");
IBaseResource patient = resources.get("example-rec-10-no-screenings");
Object recommendation = planDefinitionApplyProvider.applyPlanDefinition(new SystemRequestDetails(), plandefinition.getIdElement(), patient.getIdElement().getIdPart(), null, null, null, null, null, null, null, null);
assertTrue(recommendation instanceof CarePlan);
}
use of org.hl7.fhir.dstu2016may.model.DomainResource in project cqf-ruler by DBCG.
the class ExpressionEvaluationIT method testOpioidCdsPlanDefinitionDomain.
@Test
public void testOpioidCdsPlanDefinitionDomain() throws Exception {
DomainResource plandefinition = (DomainResource) planDefinitions.get("opioidcds-10");
// Patient First
uploadTests("test/plandefinition/Rec10/Patient");
Map<String, IBaseResource> resources = uploadTests("test/plandefinition/Rec10");
IBaseResource patient = resources.get("example-rec-10-no-screenings");
Object isFormerSmoker = expressionEvaluation.evaluateInContext(plandefinition, "true", false, patient.getIdElement().getIdPart(), new SystemRequestDetails());
assertTrue(isFormerSmoker instanceof Boolean);
assertTrue(((Boolean) isFormerSmoker).booleanValue());
}
Aggregations