Skip to content

Tutorial 10: Testing & Deployment

Pages: 2


📖 Page 1: Testing

Manual Testing Checklist

Test each module systematically:

Patient Module:

â–¡ Create patient with all fields
â–¡ View patient details
â–¡ Edit patient information
â–¡ Delete patient (with confirmation)
â–¡ Search by name
â–¡ Filter by gender
â–¡ Filter by blood group
â–¡ Filter by status (active/inactive)
â–¡ Filter by age range
â–¡ Sort by name (A-Z, Z-A)
â–¡ Sort by age (youngest, oldest)
â–¡ Pagination (10, 25, 50 per page)
â–¡ Navigate pages (first, prev, next, last)

Practitioner Module:

â–¡ CRUD operations
â–¡ Filter by specialty
â–¡ All filters and pagination working

Organization Module:

â–¡ CRUD operations
â–¡ Filter by type
â–¡ All features working

Appointment Module:

â–¡ Create with patient + practitioner selection
â–¡ DateTime picker working
â–¡ Status changes
â–¡ View appointments
â–¡ Filter by date range
â–¡ Filter by status

Audit Trail:

â–¡ All actions logged (C, R, U, D)
â–¡ Filter by action type
â–¡ Filter by resource type
â–¡ Timestamps correct

End-to-End Test Scenario

Complete workflow:

  1. Create 3 practitioners (different specialties)
  2. Create 1 organization (Hospital)
  3. Create 10 patients (varied ages, genders, blood groups)
  4. Create 5 appointments (different patients/practitioners)
  5. Update 2 patients
  6. Delete 1 patient
  7. Check audit trail (should show all actions)
  8. Test all filters on each module
  9. Test pagination with different page sizes
  10. Test search functionality

Expected: Everything works smoothly!


📖 Page 2: Production Deployment

Build JAR File

# Clean and build
mvn clean package

# JAR file created in target/
ls -lh target/fhir-pms-1.0.0.jar

Run in Production

Option 1: Direct JAR

# Run with production settings
java -jar target/fhir-pms-1.0.0.jar \
  --server.port=80 \
  --spring.thymeleaf.cache=true \
  --logging.level.com.healthcare.pms=INFO

Option 2: With Environment Variables

# Set environment variables
export SERVER_PORT=80
export FHIR_SERVER_URL=https://hapi.fhir.org/baseR4
export THYMELEAF_CACHE=true

# Run
java -jar target/fhir-pms-1.0.0.jar

Option 3: Systemd Service (Linux)

Create /etc/systemd/system/fhir-pms.service:

[Unit]
Description=FHIR Patient Management System
After=network.target

[Service]
Type=simple
User=fhirapp
WorkingDirectory=/opt/fhir-pms
ExecStart=/usr/bin/java -jar /opt/fhir-pms/fhir-pms-1.0.0.jar
Restart=always
RestartSec=10
Environment="SERVER_PORT=80"
Environment="FHIR_SERVER_URL=https://hapi.fhir.org/baseR4"

[Install]
WantedBy=multi-user.target

Enable and start:

sudo systemctl enable fhir-pms
sudo systemctl start fhir-pms
sudo systemctl status fhir-pms

Docker Deployment

Create Dockerfile:

FROM eclipse-temurin:17-jre
WORKDIR /app
COPY target/fhir-pms-1.0.0.jar app.jar
EXPOSE 8081
ENTRYPOINT ["java", "-jar", "app.jar"]

Build and run:

# Build image
docker build -t fhir-pms:1.0 .

# Run container
docker run -d \
  -p 8081:8081 \
  -e FHIR_SERVER_URL=https://hapi.fhir.org/baseR4 \
  --name fhir-pms \
  fhir-pms:1.0

# Check logs
docker logs -f fhir-pms

Production Configuration

Create application-prod.properties:

# Server
server.port=80
server.compression.enabled=true

# FHIR
fhir.server.base-url=${FHIR_SERVER_URL:https://hapi.fhir.org/baseR4}

# Thymeleaf - ENABLE CACHE
spring.thymeleaf.cache=true

# Logging - PRODUCTION LEVEL
logging.level.root=WARN
logging.level.com.healthcare.pms=INFO

# Error handling
server.error.include-message=never
server.error.include-binding-errors=never
server.error.include-stacktrace=never

Run with profile:

java -jar fhir-pms-1.0.0.jar --spring.profiles.active=prod

Troubleshooting

Problem: Port 80 requires sudo

# Option 1: Use port 8081 and reverse proxy (nginx)
# Option 2: Give java permission
sudo setcap CAP_NET_BIND_SERVICE=+eip /usr/bin/java

Problem: Out of memory

# Increase heap size
java -Xmx512m -jar fhir-pms-1.0.0.jar

Problem: FHIR server timeout

# In application.properties, increase timeout
fhir.client.connection-timeout=30000
fhir.client.socket-timeout=30000

Problem: Logs filling disk

# Add log rotation in application-prod.properties
logging.file.name=/var/log/fhir-pms/application.log
logging.file.max-size=10MB
logging.file.max-history=30

Security Checklist

â–¡ Change default ports
â–¡ Enable HTTPS (use Let's Encrypt + nginx)
â–¡ Add authentication (Spring Security)
â–¡ Enable CORS only for trusted domains
â–¡ Disable debug endpoints
â–¡ Set secure headers
â–¡ Regular dependency updates (mvn versions:display-dependency-updates)
â–¡ Environment variables for secrets (not in code)
â–¡ Firewall rules (allow only necessary ports)
â–¡ Regular backups of FHIR data

Monitoring

Add health endpoint in Application.java:

@RestController
public class HealthController {

    @GetMapping("/health")
    public Map<String, String> health() {
        Map<String, String> response = new HashMap<>();
        response.put("status", "UP");
        response.put("timestamp", LocalDateTime.now().toString());
        return response;
    }
}

Check health:

curl http://localhost:8081/health

✅ Deployment Complete!

  • Tested all features manually
  • Built production JAR
  • Multiple deployment options (JAR, Docker, Systemd)
  • Production configuration ready
  • Security checklist reviewed
  • Health monitoring added
  • Troubleshooting guide complete

🎉 CONGRATULATIONS!

You built a complete FHIR Patient Management System!

What you created: - ✅ 4 FHIR modules (Patient, Practitioner, Organization, Appointment) - ✅ Complete CRUD operations - ✅ Advanced filters (6+ per module) - ✅ Sorting (name, age, etc.) - ✅ Pagination (with page size selector) - ✅ Professional UI (Bootstrap) - ✅ Audit trail (compliance ready) - ✅ Production ready deployment

Skills gained: - Spring Boot application development - FHIR R4 implementation - HAPI FHIR Client usage - REST API design - Thymeleaf templating - Production deployment - Healthcare IT basics


🚀 Next Steps

Enhance Your System:

  1. Add Authentication
  2. Spring Security
  3. User roles (Admin, Doctor, Nurse)
  4. Login/logout

  5. Add More Features

  6. Patient medical history
  7. Prescription management
  8. Lab results
  9. Reports and analytics

  10. Improve UI

  11. Add charts (Chart.js)
  12. Better responsive design
  13. Dark mode toggle

  14. Performance

  15. Add caching (Redis)
  16. Connection pooling
  17. Load balancing

  18. Deploy to Cloud

  19. AWS Elastic Beanstalk
  20. Google Cloud Run
  21. Azure App Service
  22. Heroku

📚 Additional Resources

FHIR: - HL7 FHIR - HAPI FHIR Docs

Spring Boot: - Spring Boot Docs - Spring Security

Deployment: - Docker Docs - AWS Deployment


💡 Final Tips

Keep Learning

FHIR is vast - you learned the essentials, explore more!

Contribute

Open source your project, help others learn!

Iterate

Start with basics, add features gradually!


🎉 YOU DID IT! CONGRATULATIONS! 🎉

Share your success and keep building! 🚀