Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
141 changes: 141 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
# SampleXChange - AI Agent Guidelines

This document provides guidelines for AI agents working on the SampleXChange codebase, a Spring Boot application for FHIR resource conversion between BBMRI and MII KDS profiles.

## Project Overview

- **Technology Stack**: Java 17, Spring Boot 3.4.0, HAPI FHIR 6.8.8, Maven

Choose a reason for hiding this comment

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

Should this than be updated to the newest versions as well?

- **Purpose**: Convert FHIR resources between BBMRI Profiles and MII KDS Profiles for biobank data interchange
- **Architecture**: Component-based Spring application with FHIR mapping layers

## Build and Development Commands

```bash
# Build the project
mvn clean install

# Build without tests
mvn clean package -DskipTests

# Run the application
mvn spring-boot:run

# Run with specific profile
mvn spring-boot:run -Dspring-boot.run.arguments="--profile=BBMRI2MII"

# Run tests (when implemented)
mvn test

# Run single test class (when implemented)
mvn test -Dtest=ClassName

# Run single test method (when implemented)
mvn test -Dtest=ClassName#methodName

# Docker operations
docker build -t samplexchange .
docker-compose up
```

## Code Style Guidelines

### Package Structure
```
de.samply.samplexchange/
├── configuration/ # Spring configuration classes
├── converters/ # Data conversion utilities
├── enums/ # Enumerations for fixed values
├── exceptions/ # Custom exception classes
├── mapper/fhir/ # FHIR mapping logic (bbmri/, mii/ subpackages)
├── models/ # Data model classes
├── readers/ # FHIR resource readers
├── resources/ # Resource mapping classes
├── repository/ # Repository layer
├── utils/fhir/ # FHIR utility classes
└── writers/fhir/ # FHIR writer classes
```

### Naming Conventions
- **Classes**: PascalCase (e.g., `SpecimenMapping`, `TemperatureConverter`)
- **Methods**: camelCase with descriptive names (e.g., `fromBbrmiToMii`, `toMii`)
- **Variables**: camelCase (e.g., `bbmriId`, `miiSubject`)
- **Constants**: UPPER_SNAKE_CASE (e.g., `URL`, `DEFAULT_TIMEOUT`)
- **Packages**: lowercase with dots (e.g., `de.samply.samplexchange.converters`)

### Import Organization
1. Standard Java imports (`java.*`)
2. Third-party imports (`org.springframework.*`, `ca.uhn.fhir.model.*`)
3. Local imports (`de.samply.samplexchange.*`)

### Code Patterns
- **Lombok Usage**: Heavy use of `@Slf4j`, `@Data`, `@Getter`, `@Setter`
- **Spring Annotations**: `@Component`, `@Value`, `@Service`, `@Repository`
- **Documentation**: JavaDoc required for all public classes and methods
- **Access Modifiers**: Public for API, private for internal utilities

## Type Safety and Generics
- Use generic types in template classes: `ConvertClass<T1, T2>`
- Strong typing with FHIR model classes from HAPI FHIR
- Enum usage for fixed value sets (`ProfileFormats`)
- Avoid raw types where possible

## Error Handling
- Custom exceptions extend `Exception` (not `RuntimeException`)
- Use proper exception chaining with descriptive messages
- Checked exceptions for expected error conditions
- Log errors appropriately using `@Slf4j`

## FHIR-Specific Guidelines
- Use HAPI FHIR R4 structures exclusively
- Separate mappers for BBMRI↔MII conversions
- Handle extensions properly for custom data fields
- Follow FHIR resource structure conventions
- Validate resources before conversion

## Configuration Management
- Environment variables: `PROFILE`, `DISABLESSL`, `SOURCE_URL`, `TARGET_URL`, etc.
- Configuration in `application.yml`
- Support for both BBMRI2MII and MII2BBMRI profiles
- Proper binding of environment-specific properties

## Testing Guidelines (When Implemented)
- Use JUnit 4.13.2 with Spring Boot Test framework
- Mockito for mocking dependencies
- Testcontainers for integration tests
- Follow AAA pattern (Arrange, Act, Assert)
- Test both successful conversions and error scenarios

## Architecture Patterns
- **Template Method**: Use `ConvertClass<T1, T2>` as base class
- **Strategy Pattern**: Different mappers for profile conversions
- **Factory Pattern**: Resource creation in readers/writers
- **Dependency Injection**: Spring component management

## Development Best Practices
- Maintain separation of concerns between layers
- Use Spring's dependency injection properly
- Follow FHIR best practices for resource handling
- Ensure thread safety for component classes
- Add appropriate logging at INFO/DEBUG/ERROR levels
- Validate inputs at service boundaries

## Environment Setup
- Java 17 required
- Maven 3.6+ for building
- Docker for containerization
- Environment variables for configuration (see application.yml)

## When Making Changes
1. Understand the FHIR profile differences (BBMRI vs MII KDS)
2. Check for existing mapper patterns before creating new ones
3. Ensure proper exception handling for FHIR parsing errors
4. Add appropriate logging for debugging conversion issues
5. Test with both source and target profiles when applicable
6. Verify resource validity after conversion

## Common Pitfalls to Avoid
- Don't mix FHIR versions (use R4 consistently)
- Avoid hardcoded URLs or credentials
- Don't ignore SSL certificate validation in production
- Ensure proper resource ID handling during conversion
- Don't break existing mapper contracts when extending functionality
96 changes: 78 additions & 18 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.4.0</version>
<version>4.0.2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>de.samply</groupId>
Expand All @@ -14,17 +14,12 @@
<name>SampleXChange</name>
<description>SampleXChange</description>
<properties>
<java.version>17</java.version>
<hapi.version>6.8.8</hapi.version>
<testcontainers.version>1.18.3</testcontainers.version>
<java.version>25</java.version>
<hapi.version>8.6.5</hapi.version>
<testcontainers.version>1.21.4</testcontainers.version>
</properties>
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>1.3.2</version>
Expand Down Expand Up @@ -54,18 +49,18 @@
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>5.4.0</version>
<version>5.21.0</version>
</dependency>
<dependency>
<groupId>org.fhir</groupId>
<artifactId>ucum</artifactId>
<version>1.0.3</version>
<version>1.0.10</version>
</dependency>

<dependency>
<groupId>com.opencsv</groupId>
<artifactId>opencsv</artifactId>
<version>5.7.1</version>
<version>5.12.0</version>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
Expand All @@ -86,12 +81,12 @@
<dependency>
<groupId>jakarta.xml.ws</groupId>
<artifactId>jakarta.xml.ws-api</artifactId>
<version>4.0.0</version>
<version>4.0.2</version>
</dependency>
<dependency>
<groupId>org.glassfish.hk2</groupId>
<artifactId>osgi-resource-locator</artifactId>
<version>2.5.0-b42</version>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
Expand All @@ -106,8 +101,13 @@
<version>${testcontainers.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>

</dependencies>
</dependencies>

<build>
<plugins>
Expand All @@ -119,9 +119,69 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>16</source>
<target>16</target>
<source>${java.version}</source>
<target>${java.version}</target>
<annotationProcessorPaths>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.42</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>2.21.0</version>
<configuration>
<ignoredVersions>.*-M.*,.*\.M\d+,.*-rc.*,.*-RC.*,.*-SNAPSHOT,.*-alpha.*,.*-beta.*</ignoredVersions>
</configuration>
</plugin>
<plugin>
<groupId>org.openrewrite.maven</groupId>
<artifactId>rewrite-maven-plugin</artifactId>
<version>6.28.1</version>
<configuration>
<activeRecipes>
<recipe>org.openrewrite.staticanalysis.CommonStaticAnalysis</recipe>
<recipe>org.openrewrite.staticanalysis.CodeCleanup</recipe>
<recipe>org.openrewrite.java.migrate.UpgradeToJava17</recipe>
<recipe>org.openrewrite.java.RemoveUnusedImports</recipe>
<recipe>org.openrewrite.java.OrderImports</recipe>
<recipe>org.openrewrite.java.migrate.guava.NoGuava</recipe>
<recipe>org.openrewrite.java.migrate.guava.NoGuavaRefasterRecipes</recipe>
<recipe>org.openrewrite.java.migrate.RemoveIllegalSemicolons</recipe>
<recipe>org.openrewrite.java.testing.junit.JUnit6BestPractices</recipe>
<recipe>org.openrewrite.java.testing.mockito.MockitoBestPractices</recipe>
<recipe>org.openrewrite.java.testing.assertj.Assertj</recipe>
</activeRecipes>
<exclusions>
<exclude>**/java-gen/**</exclude>
</exclusions>
</configuration>
<dependencies>
<dependency>
<groupId>org.openrewrite.recipe</groupId>
<artifactId>rewrite-testing-frameworks</artifactId>
<version>3.26.0</version>
</dependency>
<dependency>
<groupId>org.openrewrite.recipe</groupId>
<artifactId>rewrite-migrate-java</artifactId>
<version>3.26.0</version>
</dependency>
<dependency>
<groupId>org.openrewrite.recipe</groupId>
<artifactId>rewrite-logging-frameworks</artifactId>
<version>3.22.0</version>
</dependency>
<dependency>
<groupId>org.openrewrite.recipe</groupId>
<artifactId>rewrite-static-analysis</artifactId>
<version>2.26.0</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
Expand Down
48 changes: 48 additions & 0 deletions qodana.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#-------------------------------------------------------------------------------#
# Qodana analysis is configured by qodana.yaml file #
# https://www.jetbrains.com/help/qodana/qodana-yaml.html #
#-------------------------------------------------------------------------------#

#################################################################################
# WARNING: Do not store sensitive information in this file, #
# as its contents will be included in the Qodana report. #
#################################################################################
version: "1.0"

#Specify inspection profile for code analysis
profile:
name: qodana.starter

#Enable inspections
#include:
# - name: <SomeEnabledInspectionId>

#Disable inspections
#exclude:
# - name: <SomeDisabledInspectionId>
# paths:
# - <path/where/not/run/inspection>

projectJDK: "25" #(Applied in CI/CD pipeline)

#Execute shell command before Qodana execution (Applied in CI/CD pipeline)
#bootstrap: sh ./prepare-qodana.sh

#Install IDE plugins before Qodana execution (Applied in CI/CD pipeline)
#plugins:
# - id: <plugin.id> #(plugin id can be found at https://plugins.jetbrains.com)

# Quality gate. Will fail the CI/CD pipeline if any condition is not met
# severityThresholds - configures maximum thresholds for different problem severities
# testCoverageThresholds - configures minimum code coverage on a whole project and newly added code
# Code Coverage is available in Ultimate and Ultimate Plus plans
#failureConditions:
# severityThresholds:
# any: 15
# critical: 5
# testCoverageThresholds:
# fresh: 70
# total: 50

#Specify Qodana linter for analysis (Applied in CI/CD pipeline)
linter: jetbrains/qodana-jvm:2025.3
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static void main(String[] args) {
SpringApplication.run(SampleXChangeApplication.class, args);

long endTime = System.currentTimeMillis() - startTime;
log.info("Finished SampleXChang in " + endTime + " mil sec");
log.info("Finished SampleXChang in {} mil sec", endTime);
}

@Override
Expand Down