use of org.hl7.fhir.r4.model.codesystems.V3ActCode.IMP in project pathling by aehrc.
the class MemberOfFunctionTest method memberOfCoding.
@Test
void memberOfCoding() {
final Coding coding1 = new Coding(MY_VALUE_SET_URL, "AMB", "ambulatory");
final Coding coding2 = new Coding(MY_VALUE_SET_URL, "EMER", null);
final Coding coding3 = new Coding(MY_VALUE_SET_URL, "IMP", "inpatient encounter");
final Coding coding4 = new Coding(MY_VALUE_SET_URL, "IMP", null);
final Coding coding5 = new Coding(MY_VALUE_SET_URL, "ACUTE", "inpatient acute");
final Optional<ElementDefinition> optionalDefinition = FhirHelpers.getChildOfResource(fhirContext, "Encounter", "class");
assertTrue(optionalDefinition.isPresent());
final ElementDefinition definition = optionalDefinition.get();
final Dataset<Row> inputDataset = new DatasetBuilder(spark).withIdColumn().withEidColumn().withStructTypeColumns(codingStructType()).withRow("encounter-1", makeEid(1), rowFromCoding(coding1)).withRow("encounter-1", makeEid(0), rowFromCoding(coding5)).withRow("encounter-2", makeEid(0), rowFromCoding(coding2)).withRow("encounter-3", makeEid(0), rowFromCoding(coding3)).withRow("encounter-4", makeEid(0), rowFromCoding(coding4)).withRow("encounter-5", makeEid(0), rowFromCoding(coding5)).withRow("encounter-6", null, null).buildWithStructValue();
final CodingPath inputExpression = (CodingPath) new ElementPathBuilder(spark).dataset(inputDataset).idAndEidAndValueColumns().expression("Encounter.class").singular(false).definition(definition).buildDefined();
final StringLiteralPath argumentExpression = StringLiteralPath.fromString("'" + MY_VALUE_SET_URL + "'", inputExpression);
// Setup mocks
when(terminologyService.intersect(any(), any())).thenReturn(setOfSimpleFrom(coding2, coding5));
// Prepare the inputs to the function.
final ParserContext parserContext = new ParserContextBuilder(spark, fhirContext).idColumn(inputExpression.getIdColumn()).terminologyClientFactory(terminologyServiceFactory).build();
final NamedFunctionInput memberOfInput = new NamedFunctionInput(parserContext, inputExpression, Collections.singletonList(argumentExpression));
// Invoke the function.
final FhirPath result = new MemberOfFunction().invoke(memberOfInput);
// The outcome is somehow random with regard to the sequence passed to MemberOfMapperAnswerer.
final Dataset<Row> expectedResult = new DatasetBuilder(spark).withIdColumn().withEidColumn().withColumn(DataTypes.BooleanType).withRow("encounter-1", makeEid(0), true).withRow("encounter-1", makeEid(1), false).withRow("encounter-2", makeEid(0), true).withRow("encounter-3", makeEid(0), false).withRow("encounter-4", makeEid(0), false).withRow("encounter-5", makeEid(0), true).withRow("encounter-6", null, null).build();
// Check the result.
assertThat(result).hasExpression("Encounter.class.memberOf('" + MY_VALUE_SET_URL + "')").isElementPath(BooleanPath.class).hasFhirType(FHIRDefinedType.BOOLEAN).isNotSingular().selectOrderedResultWithEid().hasRows(expectedResult);
verify(terminologyService).intersect(eq(MY_VALUE_SET_URL), eq(setOfSimpleFrom(coding1, coding2, coding3, coding4, coding5)));
verifyNoMoreInteractions(terminologyService);
}
use of org.hl7.fhir.r4.model.codesystems.V3ActCode.IMP in project org.hl7.fhir.core by hapifhir.
the class StructureMapUtilities method determineTypeFromSourceType.
private String determineTypeFromSourceType(StructureMap map, StructureMapGroupComponent source, Base base, String[] types) throws FHIRException {
String type = base.fhirType();
String kn = "type^" + type;
if (source.hasUserData(kn))
return source.getUserString(kn);
ResolvedGroup res = new ResolvedGroup();
res.targetMap = null;
res.target = null;
for (StructureMapGroupComponent grp : map.getGroup()) {
if (matchesByType(map, grp, type)) {
if (res.targetMap == null) {
res.targetMap = map;
res.target = grp;
} else
throw new FHIRException("Multiple possible matches looking for default rule for '" + type + "'");
}
}
if (res.targetMap != null) {
String result = getActualType(res.targetMap, res.target.getInput().get(1).getType());
source.setUserData(kn, result);
return result;
}
for (UriType imp : map.getImport()) {
List<StructureMap> impMapList = findMatchingMaps(imp.getValue());
if (impMapList.size() == 0)
throw new FHIRException("Unable to find map(s) for " + imp.getValue());
for (StructureMap impMap : impMapList) {
if (!impMap.getUrl().equals(map.getUrl())) {
for (StructureMapGroupComponent grp : impMap.getGroup()) {
if (matchesByType(impMap, grp, type)) {
if (res.targetMap == null) {
res.targetMap = impMap;
res.target = grp;
} else
throw new FHIRException("Multiple possible matches for default rule for '" + type + "' in " + res.targetMap.getUrl() + " (" + res.target.getName() + ") and " + impMap.getUrl() + " (" + grp.getName() + ")");
}
}
}
}
}
if (res.target == null)
throw new FHIRException("No matches found for default rule for '" + type + "' from " + map.getUrl());
// should be .getType, but R2...
String result = getActualType(res.targetMap, res.target.getInput().get(1).getType());
source.setUserData(kn, result);
return result;
}
use of org.hl7.fhir.r4.model.codesystems.V3ActCode.IMP in project org.hl7.fhir.core by hapifhir.
the class StructureMapUtilities method resolveGroupReference.
private ResolvedGroup resolveGroupReference(StructureMap map, StructureMapGroupComponent source, String name) throws FHIRException {
String kn = "ref^" + name;
if (source.hasUserData(kn))
return (ResolvedGroup) source.getUserData(kn);
ResolvedGroup res = new ResolvedGroup();
res.targetMap = null;
res.target = null;
for (StructureMapGroupComponent grp : map.getGroup()) {
if (grp.getName().equals(name)) {
if (res.targetMap == null) {
res.targetMap = map;
res.target = grp;
} else
throw new FHIRException("Multiple possible matches for rule '" + name + "'");
}
}
if (res.targetMap != null) {
source.setUserData(kn, res);
return res;
}
for (UriType imp : map.getImport()) {
List<StructureMap> impMapList = findMatchingMaps(imp.getValue());
if (impMapList.size() == 0)
throw new FHIRException("Unable to find map(s) for " + imp.getValue());
for (StructureMap impMap : impMapList) {
if (!impMap.getUrl().equals(map.getUrl())) {
for (StructureMapGroupComponent grp : impMap.getGroup()) {
if (grp.getName().equals(name)) {
if (res.targetMap == null) {
res.targetMap = impMap;
res.target = grp;
} else
throw new FHIRException("Multiple possible matches for rule '" + name + "' in " + res.targetMap.getUrl() + " and " + impMap.getUrl());
}
}
}
}
}
if (res.target == null)
throw new FHIRException("No matches found for rule '" + name + "'. Reference found in " + map.getUrl());
source.setUserData(kn, res);
return res;
}
use of org.hl7.fhir.r4.model.codesystems.V3ActCode.IMP in project org.hl7.fhir.core by hapifhir.
the class StructureMapUtilities method resolveGroupByTypes.
private ResolvedGroup resolveGroupByTypes(StructureMap map, String ruleid, StructureMapGroupComponent source, String srcType, String tgtType) throws FHIRException {
String kn = "types^" + srcType + ":" + tgtType;
if (source.hasUserData(kn))
return (ResolvedGroup) source.getUserData(kn);
ResolvedGroup res = new ResolvedGroup();
res.targetMap = null;
res.target = null;
for (StructureMapGroupComponent grp : map.getGroup()) {
if (matchesByType(map, grp, srcType, tgtType)) {
if (res.targetMap == null) {
res.targetMap = map;
res.target = grp;
} else
throw new FHIRException("Multiple possible matches looking for rule for '" + srcType + "/" + tgtType + "', from rule '" + ruleid + "'");
}
}
if (res.targetMap != null) {
source.setUserData(kn, res);
return res;
}
for (UriType imp : map.getImport()) {
List<StructureMap> impMapList = findMatchingMaps(imp.getValue());
if (impMapList.size() == 0)
throw new FHIRException("Unable to find map(s) for " + imp.getValue());
for (StructureMap impMap : impMapList) {
if (!impMap.getUrl().equals(map.getUrl())) {
for (StructureMapGroupComponent grp : impMap.getGroup()) {
if (matchesByType(impMap, grp, srcType, tgtType)) {
if (res.targetMap == null) {
res.targetMap = impMap;
res.target = grp;
} else
throw new FHIRException("Multiple possible matches for rule for '" + srcType + "/" + tgtType + "' in " + res.targetMap.getUrl() + " and " + impMap.getUrl() + ", from rule '" + ruleid + "'");
}
}
}
}
}
if (res.target == null)
throw new FHIRException("No matches found for rule for '" + srcType + "/" + tgtType + "' from " + map.getUrl() + ", from rule '" + ruleid + "'");
source.setUserData(kn, res);
return res;
}
use of org.hl7.fhir.r4.model.codesystems.V3ActCode.IMP in project org.hl7.fhir.core by hapifhir.
the class StructureMapUtilities method determineTypeFromSourceType.
private String determineTypeFromSourceType(StructureMap map, StructureMapGroupComponent source, Base base, String[] types) throws FHIRException {
String type = base.fhirType();
String kn = "type^" + type;
if (source.hasUserData(kn))
return source.getUserString(kn);
ResolvedGroup res = new ResolvedGroup();
res.targetMap = null;
res.target = null;
for (StructureMapGroupComponent grp : map.getGroup()) {
if (matchesByType(map, grp, type)) {
if (res.targetMap == null) {
res.targetMap = map;
res.target = grp;
} else
throw new FHIRException("Multiple possible matches looking for default rule for '" + type + "'");
}
}
if (res.targetMap != null) {
String result = getActualType(res.targetMap, res.target.getInput().get(1).getType());
source.setUserData(kn, result);
return result;
}
for (UriType imp : map.getImport()) {
List<StructureMap> impMapList = findMatchingMaps(imp.getValue());
if (impMapList.size() == 0)
throw new FHIRException("Unable to find map(s) for " + imp.getValue());
for (StructureMap impMap : impMapList) {
if (!impMap.getUrl().equals(map.getUrl())) {
for (StructureMapGroupComponent grp : impMap.getGroup()) {
if (matchesByType(impMap, grp, type)) {
if (res.targetMap == null) {
res.targetMap = impMap;
res.target = grp;
} else
throw new FHIRException("Multiple possible matches for default rule for '" + type + "' in " + res.targetMap.getUrl() + " (" + res.target.getName() + ") and " + impMap.getUrl() + " (" + grp.getName() + ")");
}
}
}
}
}
if (res.target == null)
throw new FHIRException("No matches found for default rule for '" + type + "' from " + map.getUrl());
// should be .getType, but R2...
String result = getActualType(res.targetMap, res.target.getInput().get(1).getType());
source.setUserData(kn, result);
return result;
}
Aggregations