Add OSGI support for HAPI-FHIR client

This commit is contained in:
jpoth 2018-02-28 18:09:30 +01:00
parent 66ebfa0ed3
commit 2c65a6dda7
5 changed files with 137 additions and 2 deletions

View File

@ -73,6 +73,13 @@
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Fragment-Host>
ca.uhn.hapi.fhir.hapi-fhir-base
</Fragment-Host>
</instructions>
</configuration>
</plugin>
</plugins>
</build>

View File

@ -32,6 +32,13 @@
<bundle>mvn:ca.uhn.hapi.fhir/hapi-fhir-base/${project.version}</bundle>
</feature>
<feature name='hapi-fhir-client' version='${project.version}' start-level='50'>
<feature version='${project.version}'>hapi-fhir</feature>
<bundle dependency='true'>mvn:org.apache.httpcomponents/httpcore-osgi/${httpcore_version}</bundle>
<bundle dependency='true'>mvn:org.apache.httpcomponents/httpclient-osgi/${httpclient_version}</bundle>
<bundle>mvn:ca.uhn.hapi.fhir/hapi-fhir-client/${project.version}</bundle>
</feature>
<feature name='hapi-fhir-utilities' version='${project.version}' start-level='50'>
<feature version='${project.version}'>hapi-fhir</feature>
<bundle dependency='true'>mvn:com.google.code.gson/gson/${gson_version}</bundle>

View File

@ -42,6 +42,11 @@
<artifactId>hapi-fhir-base</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-client</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-structures-dstu2</artifactId>

View File

@ -0,0 +1,114 @@
package ca.uhn.fhir.tests.integration.karaf.r4;
import java.io.IOException;
import java.util.List;
import ca.uhn.fhir.context.FhirContext;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.r4.hapi.ctx.DefaultProfileValidationSupport;
import org.hl7.fhir.r4.hapi.ctx.HapiWorkerContext;
import org.hl7.fhir.r4.model.Base;
import org.hl7.fhir.r4.model.BooleanType;
import org.hl7.fhir.r4.model.Observation;
import org.hl7.fhir.r4.model.Patient;
import org.hl7.fhir.r4.model.StringType;
import org.hl7.fhir.r4.model.StructureDefinition;
import org.hl7.fhir.r4.utils.FHIRPathEngine;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.ops4j.pax.exam.Configuration;
import org.ops4j.pax.exam.Option;
import org.ops4j.pax.exam.junit.PaxExam;
import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
import org.ops4j.pax.exam.spi.reactors.PerClass;
import static ca.uhn.fhir.tests.integration.karaf.PaxExamOptions.HAPI_FHIR_VALIDATION_R4;
import static ca.uhn.fhir.tests.integration.karaf.PaxExamOptions.KARAF;
import static ca.uhn.fhir.tests.integration.karaf.PaxExamOptions.WRAP;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
import static org.ops4j.pax.exam.CoreOptions.options;
import static org.ops4j.pax.exam.CoreOptions.when;
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.debugConfiguration;
/**
* Useful docs about this test: https://ops4j1.jira.com/wiki/display/paxexam/FAQ
*/
@RunWith(PaxExam.class)
@ExamReactorStrategy(PerClass.class)
public class FhirInstanceValidatorR4Test {
private FhirContext ourCtx = FhirContext.forR4();
private FHIRPathEngine ourEngine = new FHIRPathEngine(new HapiWorkerContext(ourCtx, new DefaultProfileValidationSupport()));
private final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirInstanceValidatorR4Test.class);
@Configuration
public Option[] config() throws IOException {
return options(
KARAF.option(),
HAPI_FHIR_VALIDATION_R4.option(),
mavenBundle().groupId("org.apache.servicemix.bundles").artifactId("org.apache.servicemix.bundles.hamcrest").versionAsInProject(),
WRAP.option(),
when(false)
.useOptions(
debugConfiguration("5005", true))
);
}
@Test
public void testAs() throws Exception {
Observation obs = new Observation();
obs.setValue(new StringType("FOO"));
List<Base> value = ourEngine.evaluate(obs, "Observation.value.as(String)");
assertEquals(1, value.size());
assertEquals("FOO", ((StringType)value.get(0)).getValue());
}
@Test
public void testExistsWithNoValue() throws FHIRException {
Patient patient = new Patient();
patient.setDeceased(new BooleanType());
List<Base> eval = ourEngine.evaluate(patient, "Patient.deceased.exists()");
ourLog.info(eval.toString());
assertFalse(((BooleanType)eval.get(0)).getValue());
}
@Test
public void testExistsWithValue() throws FHIRException {
Patient patient = new Patient();
patient.setDeceased(new BooleanType(false));
List<Base> eval = ourEngine.evaluate(patient, "Patient.deceased.exists()");
ourLog.info(eval.toString());
assertTrue(((BooleanType)eval.get(0)).getValue());
}
@Test
public void testConcatenation() throws FHIRException {
String exp = "Patient.name.family & '.'";
Patient p = new Patient();
p.addName().setFamily("TEST");
String result = ourEngine.evaluateToString(p, exp);
assertEquals("TEST.", result);
}
@Test
public void testConcatenationFunction() throws FHIRException {
String exp = "element.first().path.startsWith(%resource.type) and element.tail().all(path.startsWith(%resource.type&'.'))";
StructureDefinition sd = new StructureDefinition();
StructureDefinition.StructureDefinitionDifferentialComponent diff = sd.getDifferential();
diff.addElement().setPath("Patient.name");
Patient p = new Patient();
p.addName().setFamily("TEST");
List<Base> result = ourEngine.evaluate(null, p, diff, exp);
ourLog.info(result.toString());
// assertEquals("TEST.", result);
}
}

View File

@ -425,6 +425,8 @@
<hibernate_validator_version>5.4.1.Final</hibernate_validator_version>
<!-- Update lucene version when you update hibernate-search version -->
<hibernate_search_version>5.7.1.Final</hibernate_search_version>
<httpcore_version>4.4.6</httpcore_version>
<httpclient_version>4.5.3</httpclient_version>
<lucene_version>5.5.4</lucene_version>
<maven_assembly_plugin_version>2.5.3</maven_assembly_plugin_version>
<maven_license_plugin_version>1.8</maven_license_plugin_version>
@ -716,7 +718,7 @@
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.3</version>
<version>${httpclient_version}</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
@ -726,7 +728,7 @@
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.4.6</version>
<version>${httpcore_version}</version>
</dependency>
<dependency>
<groupId>org.apache.lucene</groupId>