commit
f9bff78a6e
|
@ -39,6 +39,16 @@ public enum PaxExamOptions {
|
|||
.versionAsInProject(),
|
||||
"wrap")
|
||||
),
|
||||
HAPI_FHIR_CLIENT(
|
||||
features(
|
||||
maven()
|
||||
.groupId("ca.uhn.hapi.fhir.karaf")
|
||||
.artifactId("hapi-fhir")
|
||||
.type("xml")
|
||||
.classifier("features")
|
||||
.versionAsInProject(),
|
||||
"hapi-fhir-client")
|
||||
),
|
||||
HAPI_FHIR_HL7ORG_DSTU2(
|
||||
features(
|
||||
maven()
|
||||
|
|
|
@ -1,18 +1,12 @@
|
|||
package ca.uhn.fhir.tests.integration.karaf.r4;
|
||||
package ca.uhn.fhir.tests.integration.karaf.client;
|
||||
|
||||
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 ca.uhn.fhir.rest.api.MethodOutcome;
|
||||
import ca.uhn.fhir.rest.api.PreferReturnEnum;
|
||||
import ca.uhn.fhir.rest.client.api.IGenericClient;
|
||||
import org.hl7.fhir.dstu3.model.Patient;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.ops4j.pax.exam.Configuration;
|
||||
|
@ -21,12 +15,10 @@ 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.HAPI_FHIR_CLIENT;
|
||||
import static ca.uhn.fhir.tests.integration.karaf.PaxExamOptions.HAPI_FHIR_DSTU3;
|
||||
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;
|
||||
|
@ -37,17 +29,19 @@ import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.debugConf
|
|||
*/
|
||||
@RunWith(PaxExam.class)
|
||||
@ExamReactorStrategy(PerClass.class)
|
||||
public class FhirInstanceValidatorR4Test {
|
||||
@Ignore(value = "Relies on external service being up and running")
|
||||
public class FhirClientTest {
|
||||
|
||||
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);
|
||||
private FhirContext fhirContext = FhirContext.forDstu3();
|
||||
private IGenericClient client = fhirContext.newRestfulGenericClient("http://fhirtest.uhn.ca/baseDstu3");
|
||||
private final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirClientTest.class);
|
||||
|
||||
@Configuration
|
||||
public Option[] config() throws IOException {
|
||||
return options(
|
||||
KARAF.option(),
|
||||
HAPI_FHIR_VALIDATION_R4.option(),
|
||||
HAPI_FHIR_CLIENT.option(),
|
||||
HAPI_FHIR_DSTU3.option(),
|
||||
mavenBundle().groupId("org.apache.servicemix.bundles").artifactId("org.apache.servicemix.bundles.hamcrest").versionAsInProject(),
|
||||
WRAP.option(),
|
||||
when(false)
|
||||
|
@ -57,58 +51,13 @@ public class FhirInstanceValidatorR4Test {
|
|||
}
|
||||
|
||||
@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 {
|
||||
public void createPatient() throws Exception {
|
||||
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);
|
||||
patient.setId("PATIENTID");
|
||||
patient.getMeta().addProfile("http://BAR");
|
||||
patient.addName().addGiven("GIVEN");
|
||||
MethodOutcome execute = client.create().resource(patient).prefer(PreferReturnEnum.REPRESENTATION).execute();
|
||||
ourLog.info(execute.toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue