Tutorial 2: Project Setup¶
Time: 40 minutes | Pages: 2
📖 Page 1: Create Spring Boot Project¶
Step 1: Use Spring Initializr (5 min)¶
-
Go to https://start.spring.io
-
Fill in:
- Project: Maven
- Language: Java
- Spring Boot: 3.2.1
- Group: com.healthcare
- Artifact: fhir-pms
- Java: 17
-
Add dependencies:
- Spring Web
- Thymeleaf
- Validation
- Lombok
-
Click Generate → Download ZIP
Step 2: Open in IntelliJ (5 min)¶
Step 3: Add FHIR Libraries (10 min)¶
Edit pom.xml, add inside <dependencies>:
<!-- HAPI FHIR -->
<dependency>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-base</artifactId>
<version>6.10.1</version>
</dependency>
<dependency>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-client</artifactId>
<version>6.10.1</version>
</dependency>
<dependency>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-structures-r4</artifactId>
<version>6.10.1</version>
</dependency>
Then reload Maven:
- IntelliJ → Maven tab → Reload button
- Or terminal: mvn clean install
📖 Page 2: Configure FHIR¶
Step 4: Configure Application¶
Create/Edit src/main/resources/application.properties:
# Server
server.port=8081
# FHIR Server
fhir.server.base-url=https://hapi.fhir.org/baseR4
# Thymeleaf
spring.thymeleaf.cache=false
# Logging
logging.level.com.healthcare.pms=DEBUG
Step 5: Create FHIR Config¶
Create src/main/java/com/healthcare/pms/config/FhirConfig.java:
package com.healthcare.pms.config;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.rest.client.api.IGenericClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class FhirConfig {
@Value("${fhir.server.base-url}")
private String fhirServerUrl;
@Bean
public FhirContext fhirContext() {
return FhirContext.forR4();
}
@Bean
public IGenericClient fhirClient(FhirContext fhirContext) {
return fhirContext.newRestfulGenericClient(fhirServerUrl);
}
}
Step 6: Test Run¶
Expected output:
Test in browser: http://localhost:8081
You'll see 404 error - that's good! (No controllers yet)
✅ Project Structure¶
fhir-pms/
├── pom.xml ✅ With HAPI FHIR
├── src/main/
│ ├── java/com/healthcare/pms/
│ │ ├── Application.java ✅ Main class
│ │ └── config/
│ │ └── FhirConfig.java ✅ FHIR setup
│ └── resources/
│ └── application.properties ✅ Configuration
✅ You Now Have¶
- Spring Boot project created
- HAPI FHIR libraries added
- FHIR client configured
- Application running successfully
- Connected to public FHIR server
🚀 Next¶
Your project is ready! Now let's create the Patient module.
→ Tutorial 3: Patient DTO & Mapper
💡 Quick Tips¶
Port Already in Use?
Change server.port=8082 in application.properties
Maven Issues?
Run mvn clean install to refresh dependencies
FHIR Client
IGenericClient is the main interface for all FHIR operations