Remove dependency on ServletInputStream

This commit is contained in:
James Agnew 2015-06-11 14:24:40 -04:00
parent 09d97106d3
commit f40955c2cb
25 changed files with 1775 additions and 395 deletions

View File

@ -0,0 +1,89 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir</artifactId>
<version>1.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>hapi-fhir-base-testmindeps-client</artifactId>
<packaging>jar</packaging>
<name>HAPI FHIR - Minimal Dependency Test - Client</name>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit_version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.7</version>
</dependency>
<dependency>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-base</artifactId>
<version>1.1-SNAPSHOT</version>
<exclusions>
<exclusion>
<artifactId>woodstox-core-asl</artifactId>
<groupId>org.codehaus.woodstox</groupId>
</exclusion>
<exclusion>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-structures-dstu</artifactId>
<version>1.1-SNAPSHOT</version>
<exclusions>
<exclusion>
<artifactId>woodstox-core-asl</artifactId>
<groupId>org.codehaus.woodstox</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-structures-dstu2</artifactId>
<version>1.1-SNAPSHOT</version>
<exclusions>
<exclusion>
<artifactId>woodstox-core-asl</artifactId>
<groupId>org.codehaus.woodstox</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>java-hamcrest</artifactId>
<version>${hamcrest_version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,32 @@
package ca.uhn.fhir.rest.client;
import static org.junit.Assert.fail;
import org.junit.Test;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.model.api.Bundle;
import ca.uhn.fhir.model.dstu.resource.Patient;
import ca.uhn.fhir.rest.client.exceptions.FhirClientConnectionException;
import ca.uhn.fhir.rest.gclient.ITransactionTyped;
public class ClientTest {
private static final FhirContext ctx = FhirContext.forDstu1();
@Test
public void testTransaction() {
Bundle bundle = new Bundle();
bundle.addEntry().setResource(new Patient().setId("Patient/unit_test_patient"));
IGenericClient client = ctx.newRestfulGenericClient("http://this_is_an_invalid_host_name_yes_it_is/fhir"); // won't connect
ITransactionTyped<Bundle> transaction = client.transaction().withBundle(bundle);
try {
Bundle result = transaction.encodedJson().execute();
fail();
} catch (FhirClientConnectionException e) {
// good
}
}
}

View File

@ -9,18 +9,12 @@
<relativePath>../../pom.xml</relativePath>
</parent>
<artifactId>hapi-fhir-base-testmindeps</artifactId>
<artifactId>hapi-fhir-base-testmindeps-server</artifactId>
<packaging>jar</packaging>
<name>HAPI FHIR - Minimal Dependency Test</name>
<name>HAPI FHIR - Minimal Dependency Test - Server</name>
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
@ -46,6 +40,10 @@
<artifactId>woodstox-core-asl</artifactId>
<groupId>org.codehaus.woodstox</groupId>
</exclusion>
<exclusion>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>

View File

@ -0,0 +1,32 @@
package ca.uhn.fhir.rest.client;
import static org.junit.Assert.fail;
import org.junit.Test;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.model.api.Bundle;
import ca.uhn.fhir.model.dstu.resource.Patient;
import ca.uhn.fhir.rest.client.exceptions.FhirClientConnectionException;
import ca.uhn.fhir.rest.gclient.ITransactionTyped;
public class ClientTest {
private static final FhirContext ctx = FhirContext.forDstu1();
@Test
public void testTransaction() {
Bundle bundle = new Bundle();
bundle.addEntry().setResource(new Patient().setId("Patient/unit_test_patient"));
IGenericClient client = ctx.newRestfulGenericClient("http://fhirtest.uhn.ca/baseDstu1");
ITransactionTyped<Bundle> transaction = client.transaction().withBundle(bundle);
try {
Bundle result = transaction.encodedJson().execute();
fail();
} catch (FhirClientConnectionException e) {
// good
}
}
}

View File

@ -2025,7 +2025,7 @@ class ParserState<T> {
}
} else {
definition = myContext.getResourceDefinition(myResourceType);
if (!StringUtils.equals(theLocalPart, definition.getName())) {
if (!StringUtils.equals(theLocalPart, definition.getName())) {
if (myRequireResourceType) {
throw new DataFormatException(myContext.getLocalizer().getMessage(ParserState.class, "wrongResourceTypeFound", definition.getName(), theLocalPart));
}

View File

@ -23,6 +23,7 @@ package ca.uhn.fhir.rest.method;
import static org.apache.commons.lang3.StringUtils.*;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
@ -33,6 +34,8 @@ import java.util.List;
import java.util.Set;
import java.util.TreeSet;
import javax.servlet.ServletInputStream;
import org.apache.commons.io.IOUtils;
import org.hl7.fhir.instance.model.api.IBaseResource;
@ -264,7 +267,29 @@ public abstract class BaseMethodBinding<T> implements IClientResponseHandler<T>
}
protected byte[] loadRequestContents(RequestDetails theRequest) throws IOException {
byte[] requestContents = IOUtils.toByteArray(theRequest.getServletRequest().getInputStream());
IRequestReader reader = ourRequestReader;
if (reader == null) {
try {
Class.forName("javax.servlet.ServletInputStream");
String className = BaseMethodBinding.class.getName() + "." + "ActiveRequestReader";
try {
reader = (IRequestReader) Class.forName(className).newInstance();
} catch (Exception e1) {
throw new ConfigurationException("Failed to instantiate class " + className, e1);
}
} catch (ClassNotFoundException e) {
String className = BaseMethodBinding.class.getName() + "." + "InactiveRequestReader";
try {
reader = (IRequestReader) Class.forName(className).newInstance();
} catch (Exception e1) {
throw new ConfigurationException("Failed to instantiate class " + className, e1);
}
}
ourRequestReader = reader;
}
InputStream inputStream = reader.getInputStream(theRequest);
byte[] requestContents = IOUtils.toByteArray(inputStream);
return requestContents;
}
@ -554,5 +579,39 @@ public abstract class BaseMethodBinding<T> implements IClientResponseHandler<T>
}
return true;
}
/**
* @see BaseMethodBinding#loadRequestContents(RequestDetails)
*/
private static volatile IRequestReader ourRequestReader;
/**
* @see BaseMethodBinding#loadRequestContents(RequestDetails)
*/
private static interface IRequestReader {
InputStream getInputStream(RequestDetails theRequestDetails) throws IOException;
}
/**
* @see BaseMethodBinding#loadRequestContents(RequestDetails)
*/
@SuppressWarnings("unused")
private static class ActiveRequestReader implements IRequestReader {
@Override
public InputStream getInputStream(RequestDetails theRequestDetails) throws IOException {
return theRequestDetails.getServletRequest().getInputStream();
}
}
/**
* @see BaseMethodBinding#loadRequestContents(RequestDetails)
*/
@SuppressWarnings("unused")
private static class InactiveRequestReader implements IRequestReader {
@Override
public InputStream getInputStream(RequestDetails theRequestDetails) {
throw new IllegalStateException("The servlet-api JAR is not found on the classpath. Please check that this library is available.");
}
}
}

View File

@ -1,27 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry combineaccessrules="false" kind="src" path="/hapi-fhir-base"/>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>

View File

@ -1,23 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>hapi-fhir-base-examples</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>

View File

@ -1,47 +0,0 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir</artifactId>
<version>0.6-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<artifactId>hapi-fhir-base-examples</artifactId>
<packaging>jar</packaging>
<name>HAPI FHIR - Examples (for site)</name>
<dependencies>
<dependency>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-base</artifactId>
<version>0.6-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit_version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -49,6 +49,7 @@ import ca.uhn.fhir.model.dstu2.valueset.HTTPVerbEnum;
import ca.uhn.fhir.model.dstu2.valueset.IssueSeverityEnum;
import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.model.primitive.InstantDt;
import ca.uhn.fhir.parser.DataFormatException;
import ca.uhn.fhir.rest.server.Constants;
import ca.uhn.fhir.rest.server.IBundleProvider;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
@ -101,7 +102,13 @@ public class FhirSystemDaoDstu2 extends BaseFhirSystemDao<Bundle> {
}
}
RuntimeResourceDefinition resType = getContext().getResourceDefinition(retVal.getResourceType());
RuntimeResourceDefinition resType;
try {
resType = getContext().getResourceDefinition(retVal.getResourceType());
} catch (DataFormatException e) {
String msg = getContext().getLocalizer().getMessage(BaseFhirSystemDao.class, "transactionInvalidUrl", theAction, theUrl);
throw new InvalidRequestException(msg);
}
IFhirResourceDao<? extends IResource> dao = null;
if (resType != null) {
dao = getDao(resType.getImplementingClass());

View File

@ -11,6 +11,7 @@ import java.util.Date;
import java.util.List;
import java.util.Map;
import org.apache.commons.io.IOUtils;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IIdType;
import org.junit.AfterClass;
@ -20,7 +21,9 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.jpa.entity.TagTypeEnum;
import ca.uhn.fhir.jpa.provider.SystemProviderDstu2Test;
import ca.uhn.fhir.model.api.Bundle;
import ca.uhn.fhir.model.api.BundleEntry;
import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.model.api.ResourceMetadataKeyEnum;
import ca.uhn.fhir.model.api.TagList;
@ -29,6 +32,7 @@ import ca.uhn.fhir.model.dstu.composite.ResourceReferenceDt;
import ca.uhn.fhir.model.dstu.resource.Location;
import ca.uhn.fhir.model.dstu.resource.Observation;
import ca.uhn.fhir.model.dstu.resource.Patient;
import ca.uhn.fhir.model.dstu2.resource.Bundle.Entry;
import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.model.primitive.InstantDt;
import ca.uhn.fhir.rest.param.TokenParam;
@ -37,381 +41,396 @@ import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
public class FhirSystemDaoDstu1Test {
private static ClassPathXmlApplicationContext ourCtx;
private static FhirContext ourFhirContext;
private static IFhirResourceDao<Location> ourLocationDao;
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirSystemDaoDstu1Test.class);
private static IFhirResourceDao<Observation> ourObservationDao;
private static IFhirResourceDao<Patient> ourPatientDao;
private static IFhirSystemDao<List<IResource>> ourSystemDao;
private static ClassPathXmlApplicationContext ourCtx;
private static FhirContext ourFhirContext;
private static IFhirResourceDao<Location> ourLocationDao;
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirSystemDaoDstu1Test.class);
private static IFhirResourceDao<Observation> ourObservationDao;
private static IFhirResourceDao<Patient> ourPatientDao;
private static IFhirSystemDao<List<IResource>> ourSystemDao;
@Test
public void testGetResourceCounts() {
Observation obs = new Observation();
obs.getName().addCoding().setSystem("urn:system").setCode("testGetResourceCountsO01");
ourObservationDao.create(obs);
@Test
public void testGetResourceCounts() {
Observation obs = new Observation();
obs.getName().addCoding().setSystem("urn:system").setCode("testGetResourceCountsO01");
ourObservationDao.create(obs);
Map<String, Long> oldCounts = ourSystemDao.getResourceCounts();
Map<String, Long> oldCounts = ourSystemDao.getResourceCounts();
Patient patient = new Patient();
patient.addIdentifier().setSystem("urn:system").setValue("testGetResourceCountsP01");
patient.addName().addFamily("Tester").addGiven("Joe");
ourPatientDao.create(patient);
Patient patient = new Patient();
patient.addIdentifier().setSystem("urn:system").setValue("testGetResourceCountsP01");
patient.addName().addFamily("Tester").addGiven("Joe");
ourPatientDao.create(patient);
Map<String, Long> newCounts = ourSystemDao.getResourceCounts();
Map<String, Long> newCounts = ourSystemDao.getResourceCounts();
if (oldCounts.containsKey("Patient")) {
assertEquals(oldCounts.get("Patient") + 1, (long) newCounts.get("Patient"));
} else {
assertEquals(1L, (long) newCounts.get("Patient"));
}
if (oldCounts.containsKey("Patient")) {
assertEquals(oldCounts.get("Patient") + 1, (long) newCounts.get("Patient"));
} else {
assertEquals(1L, (long) newCounts.get("Patient"));
}
assertEquals((long) oldCounts.get("Observation"), (long) newCounts.get("Observation"));
assertEquals((long) oldCounts.get("Observation"), (long) newCounts.get("Observation"));
}
}
@Test
public void testHistory() throws Exception {
Date start = new Date();
Thread.sleep(10);
@Test
public void testHistory() throws Exception {
Date start = new Date();
Thread.sleep(10);
Patient patient = new Patient();
patient.addIdentifier().setSystem("urn:system").setValue("testHistory");
patient.addName().addFamily("Tester").addGiven("Joe");
IdDt pid = ourPatientDao.create(patient).getId().toVersionless();
Patient patient = new Patient();
patient.addIdentifier().setSystem("urn:system").setValue("testHistory");
patient.addName().addFamily("Tester").addGiven("Joe");
IdDt pid = ourPatientDao.create(patient).getId().toVersionless();
Thread.sleep(10);
patient.setId(pid);
IdDt newpid = ourPatientDao.update(patient).getId();
Thread.sleep(10);
patient.setId(pid);
IdDt newpid = ourPatientDao.update(patient).getId();
Thread.sleep(10);
patient.setId(pid);
IdDt newpid2 = ourPatientDao.update(patient).getId();
Thread.sleep(10);
patient.setId(pid);
IdDt newpid2 = ourPatientDao.update(patient).getId();
Thread.sleep(10);
patient.setId(pid);
IdDt newpid3 = ourPatientDao.update(patient).getId();
Thread.sleep(10);
patient.setId(pid);
IdDt newpid3 = ourPatientDao.update(patient).getId();
IBundleProvider values = ourSystemDao.history(start);
assertEquals(4, values.size());
IBundleProvider values = ourSystemDao.history(start);
assertEquals(4, values.size());
List<IBaseResource> res = values.getResources(0, 4);
assertEquals(newpid3, res.get(0).getIdElement());
assertEquals(newpid2, res.get(1).getIdElement());
assertEquals(newpid, res.get(2).getIdElement());
assertEquals(pid.toUnqualifiedVersionless(), res.get(3).getIdElement().toUnqualifiedVersionless());
List<IBaseResource> res = values.getResources(0, 4);
assertEquals(newpid3, res.get(0).getIdElement());
assertEquals(newpid2, res.get(1).getIdElement());
assertEquals(newpid, res.get(2).getIdElement());
assertEquals(pid.toUnqualifiedVersionless(), res.get(3).getIdElement().toUnqualifiedVersionless());
Location loc = new Location();
loc.getAddress().addLine("AAA");
IdDt lid = ourLocationDao.create(loc).getId();
Location loc = new Location();
loc.getAddress().addLine("AAA");
IdDt lid = ourLocationDao.create(loc).getId();
Location loc2 = new Location();
loc2.getAddress().addLine("AAA");
ourLocationDao.create(loc2).getId();
Location loc2 = new Location();
loc2.getAddress().addLine("AAA");
ourLocationDao.create(loc2).getId();
Thread.sleep(2000);
Thread.sleep(2000);
values = ourLocationDao.history(start);
assertEquals(2, values.size());
values = ourLocationDao.history(start);
assertEquals(2, values.size());
values = ourLocationDao.history(lid.getIdPartAsLong(), start);
assertEquals(1, values.size());
values = ourLocationDao.history(lid.getIdPartAsLong(), start);
assertEquals(1, values.size());
}
}
@Test
public void testPersistWithSimpleLink() {
Patient patient = new Patient();
patient.setId(new IdDt("Patient/testPersistWithSimpleLinkP01"));
patient.addIdentifier().setSystem("urn:system").setValue("testPersistWithSimpleLinkP01");
patient.addName().addFamily("Tester").addGiven("Joe");
@Test
public void testPersistWithSimpleLink() {
Patient patient = new Patient();
patient.setId(new IdDt("Patient/testPersistWithSimpleLinkP01"));
patient.addIdentifier().setSystem("urn:system").setValue("testPersistWithSimpleLinkP01");
patient.addName().addFamily("Tester").addGiven("Joe");
Observation obs = new Observation();
obs.getName().addCoding().setSystem("urn:system").setCode("testPersistWithSimpleLinkO01");
obs.setSubject(new ResourceReferenceDt("Patient/testPersistWithSimpleLinkP01"));
Observation obs = new Observation();
obs.getName().addCoding().setSystem("urn:system").setCode("testPersistWithSimpleLinkO01");
obs.setSubject(new ResourceReferenceDt("Patient/testPersistWithSimpleLinkP01"));
ourSystemDao.transaction(Arrays.asList((IResource) patient, obs));
ourSystemDao.transaction(Arrays.asList((IResource) patient, obs));
String patientId = (patient.getId().getIdPart());
String obsId = (obs.getId().getIdPart());
String patientId = (patient.getId().getIdPart());
String obsId = (obs.getId().getIdPart());
// assertThat(patientId, greaterThan(0L));
// assertEquals(patientVersion, 1L);
// assertThat(obsId, greaterThan(patientId));
// assertEquals(obsVersion, 1L);
// assertThat(patientId, greaterThan(0L));
// assertEquals(patientVersion, 1L);
// assertThat(obsId, greaterThan(patientId));
// assertEquals(obsVersion, 1L);
// Try to search
// Try to search
IBundleProvider obsResults = ourObservationDao.search(Observation.SP_NAME, new IdentifierDt("urn:system", "testPersistWithSimpleLinkO01"));
assertEquals(1, obsResults.size());
IBundleProvider obsResults = ourObservationDao.search(Observation.SP_NAME, new IdentifierDt("urn:system", "testPersistWithSimpleLinkO01"));
assertEquals(1, obsResults.size());
IBundleProvider patResults = ourPatientDao.search(Patient.SP_IDENTIFIER, new IdentifierDt("urn:system", "testPersistWithSimpleLinkP01"));
assertEquals(1, obsResults.size());
IBundleProvider patResults = ourPatientDao.search(Patient.SP_IDENTIFIER, new IdentifierDt("urn:system", "testPersistWithSimpleLinkP01"));
assertEquals(1, obsResults.size());
IIdType foundPatientId = patResults.getResources(0, 1).get(0).getIdElement();
ResourceReferenceDt subject = obs.getSubject();
assertEquals(foundPatientId.getIdPart(), subject.getReference().getIdPart());
IIdType foundPatientId = patResults.getResources(0, 1).get(0).getIdElement();
ResourceReferenceDt subject = obs.getSubject();
assertEquals(foundPatientId.getIdPart(), subject.getReference().getIdPart());
// Update
// Update
patient = (Patient) patResults.getResources(0, 1).get(0);
obs = (Observation) obsResults.getResources(0, 1).get(0);
patient.addIdentifier().setSystem("urn:system").setValue("testPersistWithSimpleLinkP02");
obs.getName().addCoding().setSystem("urn:system").setCode("testPersistWithSimpleLinkO02");
patient = (Patient) patResults.getResources(0, 1).get(0);
obs = (Observation) obsResults.getResources(0, 1).get(0);
patient.addIdentifier().setSystem("urn:system").setValue("testPersistWithSimpleLinkP02");
obs.getName().addCoding().setSystem("urn:system").setCode("testPersistWithSimpleLinkO02");
ourSystemDao.transaction(Arrays.asList((IResource) patient, obs));
ourSystemDao.transaction(Arrays.asList((IResource) patient, obs));
String patientId2 = (patient.getId().getIdPart());
String patientVersion2 = (patient.getId().getVersionIdPart());
String obsId2 = (obs.getId().getIdPart());
String obsVersion2 = (obs.getId().getVersionIdPart());
String patientId2 = (patient.getId().getIdPart());
String patientVersion2 = (patient.getId().getVersionIdPart());
String obsId2 = (obs.getId().getIdPart());
String obsVersion2 = (obs.getId().getVersionIdPart());
assertEquals(patientId, patientId2);
assertEquals(patientVersion2, "2");
assertEquals(obsId, obsId2);
assertEquals(obsVersion2, "2");
assertEquals(patientId, patientId2);
assertEquals(patientVersion2, "2");
assertEquals(obsId, obsId2);
assertEquals(obsVersion2, "2");
}
}
@Test
public void testPersistWithUnknownId() {
Observation obs = new Observation();
obs.getName().addCoding().setSystem("urn:system").setCode("testPersistWithSimpleLinkO01");
obs.setSubject(new ResourceReferenceDt("Patient/999998888888"));
@Test
public void testPersistWithUnknownId() {
Observation obs = new Observation();
obs.getName().addCoding().setSystem("urn:system").setCode("testPersistWithSimpleLinkO01");
obs.setSubject(new ResourceReferenceDt("Patient/999998888888"));
try {
ourSystemDao.transaction(Arrays.asList((IResource) obs));
} catch (InvalidRequestException e) {
assertThat(e.getMessage(), containsString("Resource Patient/999998888888 not found, specified in path: Observation.subject"));
}
try {
ourSystemDao.transaction(Arrays.asList((IResource) obs));
} catch (InvalidRequestException e) {
assertThat(e.getMessage(), containsString("Resource Patient/999998888888 not found, specified in path: Observation.subject"));
}
obs = new Observation();
obs.getName().addCoding().setSystem("urn:system").setCode("testPersistWithSimpleLinkO01");
obs.setSubject(new ResourceReferenceDt("Patient/1.2.3.4"));
obs = new Observation();
obs.getName().addCoding().setSystem("urn:system").setCode("testPersistWithSimpleLinkO01");
obs.setSubject(new ResourceReferenceDt("Patient/1.2.3.4"));
try {
ourSystemDao.transaction(Arrays.asList((IResource) obs));
} catch (InvalidRequestException e) {
assertThat(e.getMessage(), containsString("Resource Patient/1.2.3.4 not found, specified in path: Observation.subject"));
}
try {
ourSystemDao.transaction(Arrays.asList((IResource) obs));
} catch (InvalidRequestException e) {
assertThat(e.getMessage(), containsString("Resource Patient/1.2.3.4 not found, specified in path: Observation.subject"));
}
}
}
@Test
public void testTagOperationss() throws Exception {
@Test
public void testTagOperationss() throws Exception {
TagList preSystemTl = ourSystemDao.getAllTags();
TagList preSystemTl = ourSystemDao.getAllTags();
TagList tl1 = new TagList();
tl1.addTag("testGetAllTagsScheme1", "testGetAllTagsTerm1", "testGetAllTagsLabel1");
Patient p1 = new Patient();
p1.addIdentifier().setSystem("foo").setValue("testGetAllTags01");
ResourceMetadataKeyEnum.TAG_LIST.put(p1, tl1);
ourPatientDao.create(p1);
TagList tl1 = new TagList();
tl1.addTag("testGetAllTagsScheme1", "testGetAllTagsTerm1", "testGetAllTagsLabel1");
Patient p1 = new Patient();
p1.addIdentifier().setSystem("foo").setValue("testGetAllTags01");
ResourceMetadataKeyEnum.TAG_LIST.put(p1, tl1);
ourPatientDao.create(p1);
TagList tl2 = new TagList();
tl2.addTag("testGetAllTagsScheme2", "testGetAllTagsTerm2", "testGetAllTagsLabel2");
Observation o1 = new Observation();
o1.getName().setText("testGetAllTags02");
ResourceMetadataKeyEnum.TAG_LIST.put(o1, tl2);
IdDt o1id = ourObservationDao.create(o1).getId();
assertTrue(o1id.getVersionIdPart() != null);
TagList tl2 = new TagList();
tl2.addTag("testGetAllTagsScheme2", "testGetAllTagsTerm2", "testGetAllTagsLabel2");
Observation o1 = new Observation();
o1.getName().setText("testGetAllTags02");
ResourceMetadataKeyEnum.TAG_LIST.put(o1, tl2);
IdDt o1id = ourObservationDao.create(o1).getId();
assertTrue(o1id.getVersionIdPart() != null);
TagList postSystemTl = ourSystemDao.getAllTags();
assertEquals(preSystemTl.size() + 2, postSystemTl.size());
assertEquals("testGetAllTagsLabel1", postSystemTl.getTag("testGetAllTagsScheme1", "testGetAllTagsTerm1").getLabel());
TagList postSystemTl = ourSystemDao.getAllTags();
assertEquals(preSystemTl.size() + 2, postSystemTl.size());
assertEquals("testGetAllTagsLabel1", postSystemTl.getTag("testGetAllTagsScheme1", "testGetAllTagsTerm1").getLabel());
TagList tags = ourPatientDao.getAllResourceTags();
assertEquals("testGetAllTagsLabel1", tags.getTag("testGetAllTagsScheme1", "testGetAllTagsTerm1").getLabel());
assertNull(tags.getTag("testGetAllTagsScheme2", "testGetAllTagsTerm2"));
TagList tags = ourPatientDao.getAllResourceTags();
assertEquals("testGetAllTagsLabel1", tags.getTag("testGetAllTagsScheme1", "testGetAllTagsTerm1").getLabel());
assertNull(tags.getTag("testGetAllTagsScheme2", "testGetAllTagsTerm2"));
TagList tags2 = ourObservationDao.getTags(o1id);
assertNull(tags2.getTag("testGetAllTagsScheme1", "testGetAllTagsTerm1"));
assertEquals("testGetAllTagsLabel2", tags2.getTag("testGetAllTagsScheme2", "testGetAllTagsTerm2").getLabel());
TagList tags2 = ourObservationDao.getTags(o1id);
assertNull(tags2.getTag("testGetAllTagsScheme1", "testGetAllTagsTerm1"));
assertEquals("testGetAllTagsLabel2", tags2.getTag("testGetAllTagsScheme2", "testGetAllTagsTerm2").getLabel());
o1.getResourceMetadata().remove(ResourceMetadataKeyEnum.TAG_LIST);
o1.setId(o1id);
IdDt o1id2 = ourObservationDao.update(o1).getId();
assertTrue(o1id2.getVersionIdPart() != null);
o1.getResourceMetadata().remove(ResourceMetadataKeyEnum.TAG_LIST);
o1.setId(o1id);
IdDt o1id2 = ourObservationDao.update(o1).getId();
assertTrue(o1id2.getVersionIdPart() != null);
tags2 = ourObservationDao.getTags(o1id);
assertNull(tags2.getTag("testGetAllTagsScheme1", "testGetAllTagsTerm1"));
assertEquals("testGetAllTagsLabel2", tags2.getTag("testGetAllTagsScheme2", "testGetAllTagsTerm2").getLabel());
tags2 = ourObservationDao.getTags(o1id);
assertNull(tags2.getTag("testGetAllTagsScheme1", "testGetAllTagsTerm1"));
assertEquals("testGetAllTagsLabel2", tags2.getTag("testGetAllTagsScheme2", "testGetAllTagsTerm2").getLabel());
tags2 = ourObservationDao.getTags(o1id2);
assertNull(tags2.getTag("testGetAllTagsScheme1", "testGetAllTagsTerm1"));
assertNotNull(tags2.getTag("testGetAllTagsScheme2", "testGetAllTagsTerm2"));
tags2 = ourObservationDao.getTags(o1id2);
assertNull(tags2.getTag("testGetAllTagsScheme1", "testGetAllTagsTerm1"));
assertNotNull(tags2.getTag("testGetAllTagsScheme2", "testGetAllTagsTerm2"));
/*
* Remove a tag from a version
* Remove a tag from a version
*/
ourObservationDao.removeTag(o1id2, TagTypeEnum.TAG, "testGetAllTagsScheme2", "testGetAllTagsTerm2");
tags2 = ourObservationDao.getTags(o1id2);
assertNull(tags2.getTag("testGetAllTagsScheme1", "testGetAllTagsTerm1"));
assertNull(tags2.getTag("testGetAllTagsScheme2", "testGetAllTagsTerm2"));
ourObservationDao.removeTag(o1id2, TagTypeEnum.TAG, "testGetAllTagsScheme2", "testGetAllTagsTerm2");
tags2 = ourObservationDao.getTags(o1id2);
assertNull(tags2.getTag("testGetAllTagsScheme1", "testGetAllTagsTerm1"));
assertNull(tags2.getTag("testGetAllTagsScheme2", "testGetAllTagsTerm2"));
tags2 = ourObservationDao.getTags(o1id);
assertNull(tags2.getTag("testGetAllTagsScheme1", "testGetAllTagsTerm1"));
assertNotNull(tags2.getTag("testGetAllTagsScheme2", "testGetAllTagsTerm2"));
tags2 = ourObservationDao.getTags(o1id);
assertNull(tags2.getTag("testGetAllTagsScheme1", "testGetAllTagsTerm1"));
assertNotNull(tags2.getTag("testGetAllTagsScheme2", "testGetAllTagsTerm2"));
/*
* Add a tag
*/
ourObservationDao.addTag(o1id2, TagTypeEnum.TAG, "testGetAllTagsScheme3", "testGetAllTagsTerm3", "testGetAllTagsLabel3");
tags2 = ourObservationDao.getTags(o1id2);
assertNull(tags2.getTag("testGetAllTagsScheme1", "testGetAllTagsTerm1"));
assertNull(tags2.getTag("testGetAllTagsScheme2", "testGetAllTagsTerm2"));
assertNotNull(tags2.getTag("testGetAllTagsScheme3", "testGetAllTagsTerm3"));
assertEquals("testGetAllTagsLabel3", tags2.getTag("testGetAllTagsScheme3", "testGetAllTagsTerm3").getLabel());
ourObservationDao.addTag(o1id2, TagTypeEnum.TAG, "testGetAllTagsScheme3", "testGetAllTagsTerm3", "testGetAllTagsLabel3");
tags2 = ourObservationDao.getTags(o1id2);
assertNull(tags2.getTag("testGetAllTagsScheme1", "testGetAllTagsTerm1"));
assertNull(tags2.getTag("testGetAllTagsScheme2", "testGetAllTagsTerm2"));
assertNotNull(tags2.getTag("testGetAllTagsScheme3", "testGetAllTagsTerm3"));
assertEquals("testGetAllTagsLabel3", tags2.getTag("testGetAllTagsScheme3", "testGetAllTagsTerm3").getLabel());
tags2 = ourObservationDao.getTags(o1id);
assertNull(tags2.getTag("testGetAllTagsScheme1", "testGetAllTagsTerm1"));
assertNotNull(tags2.getTag("testGetAllTagsScheme2", "testGetAllTagsTerm2"));
tags2 = ourObservationDao.getTags(o1id);
assertNull(tags2.getTag("testGetAllTagsScheme1", "testGetAllTagsTerm1"));
assertNotNull(tags2.getTag("testGetAllTagsScheme2", "testGetAllTagsTerm2"));
}
}
@Test(expected = InvalidRequestException.class)
public void testTransactionFailsWithDuplicateIds() {
Patient patient1 = new Patient();
patient1.setId(new IdDt("Patient/testTransactionFailsWithDusplicateIds"));
patient1.addIdentifier().setSystem("urn:system").setValue("testPersistWithSimpleLinkP01");
@Test(expected = InvalidRequestException.class)
public void testTransactionFailsWithDuplicateIds() {
Patient patient1 = new Patient();
patient1.setId(new IdDt("Patient/testTransactionFailsWithDusplicateIds"));
patient1.addIdentifier().setSystem("urn:system").setValue("testPersistWithSimpleLinkP01");
Patient patient2 = new Patient();
patient2.setId(new IdDt("Patient/testTransactionFailsWithDusplicateIds"));
patient2.addIdentifier().setSystem("urn:system").setValue("testPersistWithSimpleLinkP02");
Patient patient2 = new Patient();
patient2.setId(new IdDt("Patient/testTransactionFailsWithDusplicateIds"));
patient2.addIdentifier().setSystem("urn:system").setValue("testPersistWithSimpleLinkP02");
ourSystemDao.transaction(Arrays.asList((IResource) patient1, patient2));
}
ourSystemDao.transaction(Arrays.asList((IResource) patient1, patient2));
}
@Test
public void testTransactionFromBundle() throws Exception {
@Test
public void testTransactionFromBundle() throws Exception {
InputStream bundleRes = FhirSystemDaoDstu1Test.class.getResourceAsStream("/bundle-dstu1.xml");
Bundle bundle = ourFhirContext.newXmlParser().parseBundle(new InputStreamReader(bundleRes));
List<IResource> res = bundle.toListOfResources();
InputStream bundleRes = FhirSystemDaoDstu1Test.class.getResourceAsStream("/bundle-dstu1.xml");
Bundle bundle = ourFhirContext.newXmlParser().parseBundle(new InputStreamReader(bundleRes));
List<IResource> res = bundle.toListOfResources();
ourSystemDao.transaction(res);
ourSystemDao.transaction(res);
Patient p1 = (Patient) res.get(0);
String id = p1.getId().getValue();
ourLog.info("ID: {}", id);
assertThat(id, not(equalToIgnoringCase("74635")));
assertThat(id, not(equalToIgnoringCase("")));
}
Patient p1 = (Patient) res.get(0);
String id = p1.getId().getValue();
ourLog.info("ID: {}", id);
assertThat(id, not(equalToIgnoringCase("74635")));
assertThat(id, not(equalToIgnoringCase("")));
}
/**
* Issue #55
*/
@Test
public void testTransactionWithCidIds() throws Exception {
List<IResource> res = new ArrayList<IResource>();
Patient p1 = new Patient();
p1.setId("cid:patient1");
p1.addIdentifier().setSystem("system").setValue("testTransactionWithCidIds01");
res.add(p1);
/**
* Issue #55
*/
@Test
public void testTransactionWithCidIds() throws Exception {
List<IResource> res = new ArrayList<IResource>();
Observation o1 = new Observation();
o1.setId("cid:observation1");
o1.getIdentifier().setSystem("system").setValue("testTransactionWithCidIds02");
o1.setSubject(new ResourceReferenceDt("Patient/cid:patient1"));
res.add(o1);
Patient p1 = new Patient();
p1.setId("cid:patient1");
p1.addIdentifier().setSystem("system").setValue("testTransactionWithCidIds01");
res.add(p1);
Observation o2 = new Observation();
o2.setId("cid:observation2");
o2.getIdentifier().setSystem("system").setValue("testTransactionWithCidIds03");
o2.setSubject(new ResourceReferenceDt("Patient/cid:patient1"));
res.add(o2);
Observation o1 = new Observation();
o1.setId("cid:observation1");
o1.getIdentifier().setSystem("system").setValue("testTransactionWithCidIds02");
o1.setSubject(new ResourceReferenceDt("Patient/cid:patient1"));
res.add(o1);
ourSystemDao.transaction(res);
Observation o2 = new Observation();
o2.setId("cid:observation2");
o2.getIdentifier().setSystem("system").setValue("testTransactionWithCidIds03");
o2.setSubject(new ResourceReferenceDt("Patient/cid:patient1"));
res.add(o2);
assertTrue(p1.getId().getValue(), p1.getId().getIdPart().matches("^[0-9]+$"));
assertTrue(o1.getId().getValue(), o1.getId().getIdPart().matches("^[0-9]+$"));
assertTrue(o2.getId().getValue(), o2.getId().getIdPart().matches("^[0-9]+$"));
ourSystemDao.transaction(res);
assertThat(o1.getSubject().getReference().getValue(), endsWith("Patient/" + p1.getId().getIdPart()));
assertThat(o2.getSubject().getReference().getValue(), endsWith("Patient/" + p1.getId().getIdPart()));
assertTrue(p1.getId().getValue(), p1.getId().getIdPart().matches("^[0-9]+$"));
assertTrue(o1.getId().getValue(), o1.getId().getIdPart().matches("^[0-9]+$"));
assertTrue(o2.getId().getValue(), o2.getId().getIdPart().matches("^[0-9]+$"));
}
assertThat(o1.getSubject().getReference().getValue(), endsWith("Patient/" + p1.getId().getIdPart()));
assertThat(o2.getSubject().getReference().getValue(), endsWith("Patient/" + p1.getId().getIdPart()));
@Test
public void testTransactionWithCidIds2() throws Exception {
InputStream bundleRes = SystemProviderDstu2Test.class.getResourceAsStream("/dstu1_bundle.xml");
String bundleStr = IOUtils.toString(bundleRes);
Bundle bundle = ourFhirContext.newXmlParser().parseBundle(bundleStr);
List<IResource> res = new ArrayList<IResource>();
for (BundleEntry next : bundle.getEntries()) {
res.add(next.getResource());
}
List<IResource> response = ourSystemDao.transaction(res);
ourLog.info(ourFhirContext.newXmlParser().setPrettyPrint(true).encodeResourceToString(response.get(0)));
}
}
@Test
public void testTransactionWithDelete() throws Exception {
@Test
public void testTransactionWithDelete() throws Exception {
/*
* Create 3
*/
List<IResource> res;
res = new ArrayList<IResource>();
List<IResource> res;
res = new ArrayList<IResource>();
Patient p1 = new Patient();
p1.addIdentifier().setSystem("urn:system").setValue("testTransactionWithDelete");
res.add(p1);
Patient p1 = new Patient();
p1.addIdentifier().setSystem("urn:system").setValue("testTransactionWithDelete");
res.add(p1);
Patient p2 = new Patient();
p2.addIdentifier().setSystem("urn:system").setValue("testTransactionWithDelete");
res.add(p2);
Patient p2 = new Patient();
p2.addIdentifier().setSystem("urn:system").setValue("testTransactionWithDelete");
res.add(p2);
Patient p3 = new Patient();
p3.addIdentifier().setSystem("urn:system").setValue("testTransactionWithDelete");
res.add(p3);
Patient p3 = new Patient();
p3.addIdentifier().setSystem("urn:system").setValue("testTransactionWithDelete");
res.add(p3);
ourSystemDao.transaction(res);
ourSystemDao.transaction(res);
/*
* Verify
*/
IBundleProvider results = ourPatientDao.search(Patient.SP_IDENTIFIER, new TokenParam("urn:system", "testTransactionWithDelete"));
assertEquals(3, results.size());
IBundleProvider results = ourPatientDao.search(Patient.SP_IDENTIFIER, new TokenParam("urn:system", "testTransactionWithDelete"));
assertEquals(3, results.size());
/*
* Now delete 2
*/
res = new ArrayList<IResource>();
List<IBaseResource> existing = results.getResources(0, 3);
res = new ArrayList<IResource>();
List<IBaseResource> existing = results.getResources(0, 3);
p1 = new Patient();
p1.setId(existing.get(0).getIdElement());
ResourceMetadataKeyEnum.DELETED_AT.put(p1, InstantDt.withCurrentTime());
res.add(p1);
p1 = new Patient();
p1.setId(existing.get(0).getIdElement());
ResourceMetadataKeyEnum.DELETED_AT.put(p1, InstantDt.withCurrentTime());
res.add(p1);
p2 = new Patient();
p2.setId(existing.get(1).getIdElement());
ResourceMetadataKeyEnum.DELETED_AT.put(p2, InstantDt.withCurrentTime());
res.add(p2);
p2 = new Patient();
p2.setId(existing.get(1).getIdElement());
ResourceMetadataKeyEnum.DELETED_AT.put(p2, InstantDt.withCurrentTime());
res.add(p2);
ourSystemDao.transaction(res);
ourSystemDao.transaction(res);
/*
* Verify
*/
IBundleProvider results2 = ourPatientDao.search(Patient.SP_IDENTIFIER, new TokenParam("urn:system", "testTransactionWithDelete"));
assertEquals(1, results2.size());
List<IBaseResource> existing2 = results2.getResources(0, 1);
assertEquals(existing2.get(0).getIdElement(), existing.get(2).getIdElement());
IBundleProvider results2 = ourPatientDao.search(Patient.SP_IDENTIFIER, new TokenParam("urn:system", "testTransactionWithDelete"));
assertEquals(1, results2.size());
List<IBaseResource> existing2 = results2.getResources(0, 1);
assertEquals(existing2.get(0).getIdElement(), existing.get(2).getIdElement());
}
}
@AfterClass
public static void afterClass() {
ourCtx.close();
}
@AfterClass
public static void afterClass() {
ourCtx.close();
}
@SuppressWarnings("unchecked")
@BeforeClass
public static void beforeClass() {
ourCtx = new ClassPathXmlApplicationContext("hapi-fhir-server-resourceproviders-dstu1.xml", "fhir-jpabase-spring-test-config.xml");
ourFhirContext = ourCtx.getBean(FhirContext.class);
ourPatientDao = ourCtx.getBean("myPatientDaoDstu1", IFhirResourceDao.class);
ourObservationDao = ourCtx.getBean("myObservationDaoDstu1", IFhirResourceDao.class);
ourLocationDao = ourCtx.getBean("myLocationDaoDstu1", IFhirResourceDao.class);
ourSystemDao = ourCtx.getBean("mySystemDaoDstu1", IFhirSystemDao.class);
}
@SuppressWarnings("unchecked")
@BeforeClass
public static void beforeClass() {
ourCtx = new ClassPathXmlApplicationContext("hapi-fhir-server-resourceproviders-dstu1.xml", "fhir-jpabase-spring-test-config.xml");
ourFhirContext = ourCtx.getBean(FhirContext.class);
ourPatientDao = ourCtx.getBean("myPatientDaoDstu1", IFhirResourceDao.class);
ourObservationDao = ourCtx.getBean("myObservationDaoDstu1", IFhirResourceDao.class);
ourLocationDao = ourCtx.getBean("myLocationDaoDstu1", IFhirResourceDao.class);
ourSystemDao = ourCtx.getBean("mySystemDaoDstu1", IFhirSystemDao.class);
}
}

View File

@ -160,6 +160,21 @@ public class FhirSystemDaoDstu2Test {
assertEquals("Patient/temp6789", p.getLink().get(0).getOther().getReference().getValue());
}
@Test
public void testTransactionFromBundle2() throws Exception {
InputStream bundleRes = SystemProviderDstu2Test.class.getResourceAsStream("/brokenbundle_dstu2.json");
String bundleStr = IOUtils.toString(bundleRes);
Bundle bundle = ourFhirContext.newJsonParser().parseResource(Bundle.class, bundleStr);
try {
ourSystemDao.transaction(bundle);
fail();
} catch (InvalidRequestException e) {
assertThat(e.getMessage(), containsString("Unable to perform PUT, URL provided is invalid: RWB_COMP_1"));
}
}
@Test

View File

@ -58,6 +58,7 @@ import ca.uhn.fhir.model.dstu2.composite.ResourceReferenceDt;
import ca.uhn.fhir.model.dstu2.resource.Bundle.Entry;
import ca.uhn.fhir.model.dstu2.resource.Condition;
import ca.uhn.fhir.model.dstu2.resource.DiagnosticOrder;
import ca.uhn.fhir.model.dstu2.resource.DiagnosticReport;
import ca.uhn.fhir.model.dstu2.resource.DocumentManifest;
import ca.uhn.fhir.model.dstu2.resource.DocumentReference;
import ca.uhn.fhir.model.dstu2.resource.Encounter;
@ -182,6 +183,33 @@ public class ResourceProviderDstu2Test {
}
@Test
public void testCreateResourceWithInvalidData() throws IOException {
String methodName = "testCreateResourceWithInvalidData";
DiagnosticReport diagRept = new DiagnosticReport();
diagRept.getResult().get(0).getReference().isEmpty();
Patient pt = new Patient();
pt.addName().addFamily(methodName);
pt.setBirthDate(new DateDt("2011-01-01"));
String resource = ourFhirCtx.newXmlParser().encodeResourceToString(pt);
HttpPost post = new HttpPost(ourServerBase + "/Patient");
post.setEntity(new StringEntity(resource, ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
CloseableHttpResponse response = ourHttpClient.execute(post);
IdDt id;
try {
assertEquals(201, response.getStatusLine().getStatusCode());
String newIdString = response.getFirstHeader(Constants.HEADER_LOCATION_LC).getValue();
assertThat(newIdString, startsWith(ourServerBase + "/Patient/"));
id = new IdDt(newIdString);
} finally {
response.close();
}
}
@Test
public void testCreateResourceWithNumericId() throws IOException {
String resource = "<Patient xmlns=\"http://hl7.org/fhir\"></Patient>";

View File

@ -0,0 +1,129 @@
{
"resourceType":"Bundle",
"id":"RWB_DS_BUNDLE",
"type":"transaction",
"entry":[
{
"resource":{
"resourceType":"Composition",
"id":"RWB_COMP_1",
"date":"2015-06-09T13:18:58-04:00",
"type":{
"coding":[
{
"system":"http://loinc.org",
"code":"18842-5"
}
]
},
"title":"TCLHIN Discharge Summary",
"status":"final",
"confidentiality":"N",
"subject":{
"reference":"Patient/DS-PAT1"
},
"custodian":{
"reference":"Location/LOC_RWB_TGH"
},
"encounter":{
"reference":"Encounter/VISIT_RWB_1"
}
},
"transaction":{
"method":"PUT",
"url":"RWB_COMP_1"
}
},
{
"resource":{
"resourceType":"MedicationStatement",
"contained":[
{
"resourceType":"Medication",
"id":"1",
"name":"Tylenol"
}
],
"status":"in-progress",
"medication":{
"reference":"#1"
},
"dosage":[
{
"text":"Twice a day, every day. 60% of the time, every time.",
"schedule":{
"code":{
"coding":[
{
"system":"http://hl7.org/fhir/v3/vs/GTSAbbreviation",
"code":"BID"
}
]
}
}
}
]
},
"transaction":{
"method":"PUT"
}
},
{
"resource":{
"resourceType":"Observation",
"code":{
"coding":[
{
"system":"urn:oid:1.3.6.1.4.1.12201.101.1",
"code":"SUMMARY"
}
]
},
"valueString":"Patient was seen and left because they are okay now. Everyting's fine. How are you?"
},
"transaction":{
"method":"PUT"
}
},
{
"resource":{
"resourceType":"Procedure",
"type":{
"coding":[
{
"system":"http://snomed.info/sct",
"code":"177820006"
}
]
}
},
"transaction":{
"method":"PUT"
}
},
{
"resource":{
"resourceType":"CarePlan",
"id":"RWB_CAREPLAN_1",
"status":"planned",
"notes":"This is a care plan. You should get healthy. Seriously. Get healthy."
},
"transaction":{
"method":"PUT",
"url":"RWB_CAREPLAN_1"
}
},
{
"resource":{
"resourceType":"ReferralRequest",
"id":"RWB_REFERRAL_REQUEST_1",
"status":"draft",
"description":"I need you to look at this guy's belly. Not for anything serious; it's just hilarious."
},
"transaction":{
"method":"PUT",
"url":"RWB_REFERRAL_REQUEST_1"
}
}
]
}

File diff suppressed because it is too large Load Diff

View File

@ -142,23 +142,6 @@
</span>
</div>
<!-- Includes -->
<div class="row-fluid">
<h4>Reverse Includes <small>Also include resources which reference to the search results</small></h4>
</div>
<div class="row-fluid">
<span class="includeCheckCheck">
<input type="checkbox" th:value="'*'" th:id="'revinc_STAR'" />
</span>
<span class="includeCheckName" th:text="'*'"/>
<span th:each="include : ${revincludes}" class="includeCheckContainer">
<span class="includeCheckCheck">
<input type="checkbox" th:value="${include}" th:id="'revinc_' + ${include}" />
</span>
<span class="includeCheckName" th:text="${include}"/>
</span>
</div>
<!-- Results Sorting -->
<div class="row-fluid">
<h4>Sort Results</h4>
@ -217,7 +200,23 @@
</div>
</div>
<br clear="all"/>
<!-- Reverse Includes -->
<div class="row-fluid">
<h4>Reverse Includes <small>Also include resources which reference to the search results</small></h4>
</div>
<div class="row-fluid">
<span class="includeCheckCheck">
<input type="checkbox" th:value="'*'" th:id="'revinc_STAR'" />
</span>
<span class="includeCheckName" th:text="'*'"/>
<span th:each="include : ${revincludes}" class="includeCheckContainer">
<span class="includeCheckCheck">
<input type="checkbox" th:value="${include}" th:id="'revinc_' + ${include}" />
</span>
<span class="includeCheckName" th:text="${include}"/>
</span>
</div>
</div>
</div>

View File

@ -886,7 +886,8 @@
<module>hapi-deployable-pom</module>
<module>hapi-fhir-base</module>
<!--<module>hapi-fhir-oauth2</module>-->
<module>hapi-fhir-base/testmindeps</module>
<module>hapi-fhir-base-test-mindeps-client</module>
<module>hapi-fhir-base-test-mindeps-server</module>
<module>hapi-tinder-plugin</module>
<module>hapi-tinder-test</module>
<module>hapi-fhir-structures-dstu</module>