JPA demo enhancements and site work
This commit is contained in:
parent
009815786f
commit
9a9501c53f
|
@ -1,5 +1,25 @@
|
|||
package ca.uhn.fhir.rest.annotation;
|
||||
|
||||
/*
|
||||
* #%L
|
||||
* HAPI FHIR - Core Library
|
||||
* %%
|
||||
* Copyright (C) 2014 - 2015 University Health Network
|
||||
* %%
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
|
|
@ -372,7 +372,8 @@ public class RestfulServerUtils {
|
|||
writer.append("<hr/>");
|
||||
}
|
||||
} else {
|
||||
RestfulServerUtils.getNewParser(theServer.getFhirContext(), responseEncoding, thePrettyPrint, theNarrativeMode).encodeBundleToWriter(bundle, writer);
|
||||
IParser newParser = RestfulServerUtils.getNewParser(theServer.getFhirContext(), responseEncoding, thePrettyPrint, theNarrativeMode);
|
||||
newParser.encodeBundleToWriter(bundle, writer);
|
||||
}
|
||||
} finally {
|
||||
writer.close();
|
||||
|
|
|
@ -1,5 +1,25 @@
|
|||
package ca.uhn.fhir.jpa.dao;
|
||||
|
||||
/*
|
||||
* #%L
|
||||
* HAPI FHIR JPA Server
|
||||
* %%
|
||||
* Copyright (C) 2014 - 2015 University Health Network
|
||||
* %%
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ public class JpaServerDemo extends RestfulServer {
|
|||
*
|
||||
* If you want to use DSTU1 instead, change the following line, and change the 2 occurrences of dstu2 in web.xml to dstu1
|
||||
*/
|
||||
FhirVersionEnum fhirVersion = FhirVersionEnum.DSTU1;
|
||||
FhirVersionEnum fhirVersion = FhirVersionEnum.DSTU2;
|
||||
setFhirContext(new FhirContext(fhirVersion));
|
||||
|
||||
// Get the spring context from the web container (it's declared in web.xml)
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
<param-name>contextConfigLocation</param-name>
|
||||
<param-value>
|
||||
classpath:hapi-fhir-server-resourceproviders-dstu1.xml
|
||||
classpath:hapi-fhir-server-resourceproviders-dstu2.xml
|
||||
/WEB-INF/hapi-fhir-server-database-config.xml
|
||||
/WEB-INF/hapi-fhir-server-config.xml
|
||||
/WEB-INF/hapi-fhir-tester-application-context.xml
|
||||
|
|
|
@ -51,6 +51,7 @@ import ca.uhn.fhir.model.dstu.resource.Conformance;
|
|||
import ca.uhn.fhir.model.dstu.resource.Conformance.RestResource;
|
||||
import ca.uhn.fhir.model.dstu.resource.DiagnosticReport;
|
||||
import ca.uhn.fhir.model.dstu.resource.ListResource;
|
||||
import ca.uhn.fhir.model.dstu.resource.Location;
|
||||
import ca.uhn.fhir.model.dstu.resource.Observation;
|
||||
import ca.uhn.fhir.model.dstu.resource.Organization;
|
||||
import ca.uhn.fhir.model.dstu.resource.Patient;
|
||||
|
@ -99,6 +100,22 @@ public class JsonParserTest {
|
|||
assertThat(out, containsString("<xhtml:div xmlns:xhtml=\\\"http://www.w3.org/1999/xhtml\\\">hello</xhtml:div>"));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecimalPrecisionPreserved() {
|
||||
String number = "52.3779939997090374535378485873776474764643249869328698436986235758587";
|
||||
|
||||
Location loc = new Location();
|
||||
// This is far more precision than is realistic, but let's see if we preserve it
|
||||
loc.getPosition().setLatitude(new DecimalDt(number));
|
||||
|
||||
String encoded = ourCtx.newJsonParser().encodeResourceToString(loc);
|
||||
Location parsed = ourCtx.newJsonParser().parseResource(Location.class, encoded);
|
||||
|
||||
assertEquals(number, parsed.getPosition().getLatitude().getValueAsString());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeAndParseExtensions() throws Exception {
|
||||
|
|
|
@ -111,7 +111,6 @@ public class SearchTest {
|
|||
|
||||
Encounter encounter = found.get(0);
|
||||
assertNotNull(encounter.getSubject().getResource());
|
||||
|
||||
}
|
||||
|
||||
private interface ITestClient extends IBasicClient {
|
||||
|
|
|
@ -34,6 +34,7 @@ import ca.uhn.fhir.model.api.IResource;
|
|||
import ca.uhn.fhir.model.api.ResourceMetadataKeyEnum;
|
||||
import ca.uhn.fhir.model.base.composite.BaseCodingDt;
|
||||
import ca.uhn.fhir.model.dstu.composite.CodingDt;
|
||||
import ca.uhn.fhir.model.dstu.resource.BaseResource;
|
||||
import ca.uhn.fhir.model.dstu.resource.Observation;
|
||||
import ca.uhn.fhir.model.dstu.resource.Patient;
|
||||
import ca.uhn.fhir.model.primitive.IdDt;
|
||||
|
@ -42,6 +43,7 @@ import ca.uhn.fhir.rest.annotation.IdParam;
|
|||
import ca.uhn.fhir.rest.annotation.OptionalParam;
|
||||
import ca.uhn.fhir.rest.annotation.RequiredParam;
|
||||
import ca.uhn.fhir.rest.annotation.Search;
|
||||
import ca.uhn.fhir.rest.client.IGenericClient;
|
||||
import ca.uhn.fhir.rest.param.ReferenceParam;
|
||||
import ca.uhn.fhir.rest.param.StringOrListParam;
|
||||
import ca.uhn.fhir.rest.param.StringParam;
|
||||
|
@ -111,6 +113,19 @@ public class SearchTest {
|
|||
assertEquals("IDAAA (identifier123)", bundle.getEntries().get(0).getTitle().getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearchByIdUsingClient() throws Exception {
|
||||
IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort);
|
||||
|
||||
Bundle bundle = client.search().forResource("Patient").where(BaseResource.RES_ID.matches().value("aaa")).execute();
|
||||
assertEquals(1, bundle.getEntries().size());
|
||||
|
||||
Patient p = bundle.getResources(Patient.class).get(0);
|
||||
assertEquals("idaaa", p.getNameFirstRep().getFamilyAsSingleString());
|
||||
assertEquals("IDAAA (identifier123)", bundle.getEntries().get(0).getTitle().getValue());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSearchWithOrList() throws Exception {
|
||||
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?findPatientWithOrList=aaa,bbb");
|
||||
|
|
|
@ -1053,11 +1053,11 @@ public class Controller {
|
|||
private IResource loadAndAddConf(HttpServletRequest theServletRequest, final HomeRequest theRequest, final ModelMap theModel) {
|
||||
switch (theRequest.getFhirVersion(myConfig)) {
|
||||
case DEV:
|
||||
return loadAndAddConfDev(theServletRequest, theRequest, theModel);
|
||||
return loadAndAddConfDstu2(theServletRequest, theRequest, theModel);
|
||||
case DSTU1:
|
||||
return loadAndAddConfDstu1(theServletRequest, theRequest, theModel);
|
||||
case DSTU2:
|
||||
return loadAndAddConfDev(theServletRequest, theRequest, theModel);
|
||||
return loadAndAddConfDstu2(theServletRequest, theRequest, theModel);
|
||||
}
|
||||
throw new IllegalStateException("Unknown version: " + theRequest.getFhirVersion(myConfig));
|
||||
}
|
||||
|
@ -1121,7 +1121,7 @@ public class Controller {
|
|||
return conformance;
|
||||
}
|
||||
|
||||
private IResource loadAndAddConfDev(HttpServletRequest theServletRequest, final HomeRequest theRequest, final ModelMap theModel) {
|
||||
private IResource loadAndAddConfDstu2(HttpServletRequest theServletRequest, final HomeRequest theRequest, final ModelMap theModel) {
|
||||
IGenericClient client = getContext(theRequest).newRestfulGenericClient(theRequest.getServerBase(theServletRequest, myConfig));
|
||||
|
||||
ca.uhn.fhir.model.dstu2.resource.Conformance conformance;
|
||||
|
|
|
@ -14,6 +14,7 @@ import ca.uhn.fhir.parser.IParser;
|
|||
import ca.uhn.fhir.rest.client.GenericClient;
|
||||
import ca.uhn.fhir.rest.client.IClientInterceptor;
|
||||
import ca.uhn.fhir.rest.server.EncodingEnum;
|
||||
import ca.uhn.fhir.rest.server.IncomingRequestAddressStrategy;
|
||||
import ca.uhn.fhir.to.Controller;
|
||||
import ca.uhn.fhir.to.TesterConfig;
|
||||
|
||||
|
@ -48,10 +49,13 @@ public class HomeRequest {
|
|||
}
|
||||
|
||||
if (retVal.contains("${serverBase}")) {
|
||||
String base = theRequest.getRequestURL().toString();
|
||||
String base = new IncomingRequestAddressStrategy().determineServerBase(theRequest.getServletContext(), theRequest);
|
||||
if (base.endsWith("/")) {
|
||||
base = base.substring(0, base.length() - 1);
|
||||
}
|
||||
if (base.endsWith("/resource")) {
|
||||
base = base.substring(0, base.length() - "/resource".length());
|
||||
}
|
||||
retVal = retVal.replace("${serverBase}", base);
|
||||
}
|
||||
|
||||
|
|
|
@ -10,8 +10,6 @@
|
|||
|
||||
<section name="JPA Server">
|
||||
|
||||
<img src="images/jpa_architecture.png" alt="Architecture"/>
|
||||
|
||||
<p>
|
||||
The HAPI FHIR
|
||||
<a href="./doc_rest_server.html">RestfulServer</a>
|
||||
|
@ -20,10 +18,10 @@
|
|||
clinical system, a set of files, or anything else you come up with.
|
||||
</p>
|
||||
<p>
|
||||
HAPI also provides a specific database implementation which can be used to
|
||||
provide a complete RESTful server implementation, backed by a database.
|
||||
HAPI FHIR's JPA module is an implementation of a database storage layer, using
|
||||
the JPA 2.0 API with Hibernate as the recommended implementation.
|
||||
HAPI also provides a persistence module which can be used to
|
||||
provide a complete RESTful server implementation, backed by a database of
|
||||
your choosing. This module uses the <a href="http://en.wikipedia.org/wiki/Java_Persistence_API">JPA 2.0</a>
|
||||
API to store data in a database without depending on any specific database technology.
|
||||
</p>
|
||||
<p>
|
||||
<b>Important Note: </b>
|
||||
|
@ -39,13 +37,67 @@
|
|||
|
||||
<p>
|
||||
The easiest way to get started with HAPI's JPA server module is
|
||||
to begin with the example project.
|
||||
|
||||
to begin with the example project. There is a complete sample project
|
||||
found in our GitHub repo here: <a href="https://github.com/jamesagnew/hapi-fhir/tree/master/hapi-fhir-jpaserver-example">hapi-fhir-jpaserver-example</a>
|
||||
</p>
|
||||
|
||||
</subsection>
|
||||
|
||||
<p>
|
||||
This example is a fully contained FHIR server, supporting all standard operations (read/create/delete/etc).
|
||||
It bundles an embedded instance of the <a href="http://db.apache.org/derby/">Apache Derby</a> Java database
|
||||
so that the server can run without depending on any external database, but it can also be
|
||||
configured to use an installation of Oracle, Postgres, etc.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
To take this project for a spin, check out the sources from GitHib (or download a snapshot),
|
||||
and then build the project:
|
||||
</p>
|
||||
|
||||
<source><![CDATA[$ cd hapi-fhir-jpaserver-example
|
||||
$ mvn install]]></source>
|
||||
|
||||
<p>
|
||||
You now have two options for starting the server:
|
||||
</p>
|
||||
<ul>
|
||||
<li>
|
||||
<b>Deploy to Tomcat/JBoss/Websphere/etc: </b> You will now have a file
|
||||
in your <code>target</code> directory called <code>hapi-fhir-jpaserver-example.war</code>.
|
||||
This WAR file can be deployed to any Servlet container, at which point you could
|
||||
access the server at a URL similar to the following (you may need to adjust the
|
||||
port depending on which port your container is configured to listen on):
|
||||
<a href="http://localhost:8080/hapi-fhir-jpaserver-example/">http://localhost:8080/hapi-fhir-jpaserver-example/</a>
|
||||
</li>
|
||||
<li>
|
||||
<b>Run with Maven and Embedded Jetty: </b> To start the server
|
||||
directly within Maven, you can execute the following command:<br/>
|
||||
<source>$ mvn jetty:run</source>
|
||||
You can then access the server
|
||||
</li>
|
||||
</ul>
|
||||
</subsection>
|
||||
</section>
|
||||
|
||||
|
||||
<section name="Architecture">
|
||||
|
||||
<img src="images/jpa_architecture.png" alt="Architecture" align="right"/>
|
||||
|
||||
<p>
|
||||
The HAPI JPA Server has the following components:
|
||||
</p>
|
||||
|
||||
<ul>
|
||||
<li>
|
||||
<b>Resource Providers: </b>
|
||||
A RESTful server <a href="./doc_rest_server.html#resource_providers">Resource Provider</a> is
|
||||
provided for each resource type in a given release of FHIR, which
|
||||
</li>
|
||||
<li><b>Database: </b></li> The
|
||||
|
||||
</ul>
|
||||
|
||||
</section>
|
||||
|
||||
</body>
|
||||
|
||||
</document>
|
||||
|
|
Loading…
Reference in New Issue