Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
package ca.uhn.fhir.spring.boot.autoconfigure;

import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.jaxrs.server.AbstractJaxRsProvider;
import ca.uhn.fhir.jpa.api.config.JpaStorageSettings;
import ca.uhn.fhir.jpa.config.HapiJpaConfig;
import ca.uhn.fhir.jpa.config.JpaDstu2Config;
Expand Down Expand Up @@ -103,7 +102,7 @@ public FhirContext fhirContext() {
}

@Configuration
@ConditionalOnClass(AbstractJaxRsProvider.class)
@ConditionalOnClass(RestfulServer.class)
@EnableConfigurationProperties(FhirProperties.class)
@ConfigurationProperties("hapi.fhir.rest")
@SuppressWarnings("serial")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,17 @@

import ca.uhn.fhir.rest.client.api.IGenericClient;
import ca.uhn.fhir.rest.client.interceptor.LoggingInterceptor;
import ca.uhn.fhir.spring.boot.autoconfigure.FhirAutoConfiguration;

import org.hl7.fhir.dstu3.model.CapabilityStatement;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;

@SpringBootApplication
@ImportAutoConfiguration(FhirAutoConfiguration.class)
public class SampleApacheRestfulClientApplication {

public static void main(String[] args) {
Expand All @@ -45,7 +49,7 @@ public CommandLineRunner runner(final IGenericClient fhirClient) {

@Override
public void run(String... args) throws Exception {
fhirClient.capabilities().ofType(CapabilityStatement.class).execute();
fhirClient.capabilities().ofType(CapabilityStatement.class) /* .execute() */;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why wouldn't you do the execute invocation here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling execute would actually execute the request, and fail if there isn't a FHIR server running on localhost:8080.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Enabled execute again, and added a mock CommandLineRunner in the test class.

}
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package sample.fhir.client;

import static org.assertj.core.api.Assertions.assertThat;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.ApplicationContext;

import ca.uhn.fhir.spring.boot.autoconfigure.FhirProperties;

@SpringBootTest
public class AutoconfigurationTest {

@Autowired
private FhirProperties properties;

@Autowired
private ApplicationContext applicationContext;

@Test
public void testContextNotNull() {
assertThat(applicationContext).isNotNull();
}

@Test
public void testBean() {
// Test that no bean has a URL mapping that includes the FHIR server path set in the application configuration
String[] beanNames = applicationContext.getBeanNamesForType(ServletRegistrationBean.class);
String expectedPath = properties.getServer().getPath();
long count = 0;
for (String beanName : beanNames) {
ServletRegistrationBean<?> bean = applicationContext.getBean(beanName, ServletRegistrationBean.class);
for (String mapping : bean.getUrlMappings()) {
if (mapping.contains(expectedPath)) {
count++;
}
}
}
// The server should not be created because the hapi-fhir-server dependency is not added
assertThat(count).isEqualTo(0);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<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-spring-boot-samples</artifactId>
<version>8.5.1-SNAPSHOT</version>

</parent>

<artifactId>hapi-fhir-spring-boot-sample-server-plain</artifactId>
<name>HAPI-FHIR Spring Boot Sample Server</name>

<packaging>jar</packaging>

<dependencies>
<!-- Compile -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-spring-boot-starter</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-structures-r4</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-server</artifactId>
<version>${project.version}</version>
</dependency>
<!-- Test -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>

<!-- Logging -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
</dependency>

</dependencies>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring_boot_version}</version>
<type>pom</type>
<scope>import</scope>
<optional>true</optional>
</dependency>
</dependencies>
</dependencyManagement>

<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.basepom.maven</groupId>
<artifactId>duplicate-finder-maven-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*-
* #%L
* hapi-fhir-spring-boot-sample-server-jersey
* %%
* Copyright (C) 2014 - 2017 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%
*/
package sample.fhir.server.plain;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import ca.uhn.fhir.spring.boot.autoconfigure.FhirAutoConfiguration;

@SpringBootApplication
@ImportAutoConfiguration(FhirAutoConfiguration.class)
public class SamplePlainRestfulServerApplication {

public static void main(String[] args) {
SpringApplication.run(SamplePlainRestfulServerApplication.class, args);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*-
* #%L
* hapi-fhir-spring-boot-sample-server-jersey
* %%
* Copyright (C) 2014 - 2017 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%
*/
package sample.fhir.server.plain.provider;

import java.util.HashMap;

import org.hl7.fhir.r4.model.HumanName;
import org.hl7.fhir.r4.model.IdType;
import org.hl7.fhir.r4.model.Patient;
import org.springframework.stereotype.Component;

import ca.uhn.fhir.i18n.Msg;
import ca.uhn.fhir.rest.annotation.IdParam;
import ca.uhn.fhir.rest.annotation.Read;
import ca.uhn.fhir.rest.server.IResourceProvider;
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;

@Component
public class PatientResourceProvider implements IResourceProvider {

private static final HashMap<String, Patient> patients = new HashMap<>();

static {
patients.put(String.valueOf(1L), createPatient("1", "Doe", "Jane"));
patients.put(String.valueOf(2L), createPatient("2", "Doe", "John"));
}

@Override
public Class<Patient> getResourceType() {
return Patient.class;
}

@Read
public Patient find(@IdParam final IdType theId) {
if (patients.containsKey(theId.getIdPart())) {
return patients.get(theId.getIdPart());
} else {
throw new ResourceNotFoundException(Msg.code(2005) + theId);
}
}

private static Patient createPatient(final String id, final String family, final String given) {
final Patient patient = new Patient();
patient.getName().add(new HumanName().setFamily(family).addGiven(given));
patient.setId(id);
return patient;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
hapi:
fhir:
version: R4
server:
path: /fhir/*
rest:
server-name: hapi-fhir-spring-boot-sample-server-plain
server-version: 1.0.0
implementation-description: Spring Boot Plain Server Sample
default-response-encoding: json
e-tag-support: enabled
default-pretty-print: true
validation:
enabled: true
request-only: true
management:
security:
enabled: false
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package sample.fhir.server.plain;

import static org.assertj.core.api.Assertions.assertThat;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.ApplicationContext;

import ca.uhn.fhir.spring.boot.autoconfigure.FhirProperties;

@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
public class SamplePlainRestfulServerApplicationTest {

@Autowired
private FhirProperties properties;

@Autowired
private ApplicationContext applicationContext;

@Test
public void testBean() {
// Test if exactly one bean has a URL mapping that includes the FHIR server path set in the application configuration
String[] beanNames = applicationContext.getBeanNamesForType(ServletRegistrationBean.class);
String expectedPath = properties.getServer().getPath();
long count = 0;
for (String beanName : beanNames) {
ServletRegistrationBean<?> bean = applicationContext.getBean(beanName, ServletRegistrationBean.class);
for (String mapping : bean.getUrlMappings()) {
if (mapping.contains(expectedPath)) {
count++;
}
}
}
assertThat(count).isEqualTo(1);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<configuration>

<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} [%file:%line] - %msg%n
</pattern>
</encoder>
</appender>

<root level="info">
<appender-ref ref="STDOUT" />
</root>

</configuration>
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<module>hapi-fhir-spring-boot-sample-client-apache</module>
<module>hapi-fhir-spring-boot-sample-client-okhttp</module>
<module>hapi-fhir-spring-boot-sample-server-jersey</module>
<module>hapi-fhir-spring-boot-sample-server-plain</module>
</modules>

<dependencyManagement>
Expand Down