|
1 | | -OHS Digital Health Backend Exercise – Starter |
| 1 | +# County Hospital Health API |
2 | 2 |
|
3 | | -Prerequisites |
4 | | -- Java 17+ |
5 | | -- Maven 3.8+ |
| 3 | +A Development-ready digital health backend system for managing patient records and encounters, built with Spring Boot and following healthcare domain standards. |
| 4 | +[https://health.backend.williamachuchi.com/](https://health.backend.williamachuchi.com/) |
6 | 5 |
|
7 | | -Getting Started |
8 | | -1. Navigate to starter-project |
9 | | -2. Run: mvn clean spring-boot:run |
10 | | -3. API runs at http://localhost:8080 |
| 6 | +## Overview |
11 | 7 |
|
12 | | -Tech Stack |
13 | | -- Spring Boot (Web, Data JPA, Validation) |
14 | | -- H2 database (in‑memory) |
| 8 | +This API provides comprehensive healthcare data management for county hospitals, including patient registration, encounter tracking, and advanced search capabilities. The system is designed with scalability, security, and healthcare compliance in mind. |
15 | 9 |
|
16 | | -Configuration |
17 | | -- See starter-project/src/main/resources/application.properties |
18 | | -- Change DB or port as needed |
| 10 | +## Quick Start |
19 | 11 |
|
20 | | -Development Notes |
21 | | -- Use layered architecture (controller → service → repository) |
22 | | -- Prefer DTOs at API boundary |
23 | | -- Add Bean Validation annotations and exception handling |
| 12 | +### Prerequisites |
24 | 13 |
|
25 | | -API Documentation |
26 | | -- Option A: Add springdoc‑openapi‑starter‑webmvc‑ui and expose Swagger UI at /swagger-ui.html |
27 | | -- Option B: Document endpoints with examples in README or EXERCISE.md |
| 14 | +* Java 21 (What I used) or Java 17+(Atleast) |
| 15 | +* Maven 3.8+ |
| 16 | +* Docker (Optional, for containerized deployment) |
28 | 17 |
|
29 | | -Testing |
30 | | -- JUnit 5 and Spring Boot test starter are available once added to pom |
31 | | -- Include unit tests for services and one controller/slice test |
| 18 | +### Clone & Run (Development Mode) |
32 | 19 |
|
33 | | -Submission |
34 | | -- Include run instructions and any design notes in your project README |
| 20 | +```bash |
| 21 | +# Clone the repository |
| 22 | +git clone https://github.com/DeveloperWilliams/ohs-backend-developer-exercise |
| 23 | +cd ohs-backend-developer-exercise |
35 | 24 |
|
| 25 | +# Run with detailed logging |
| 26 | +mvn clean spring-boot:run -X |
| 27 | + |
| 28 | +# Or run normally |
| 29 | +mvn clean spring-boot:run |
| 30 | +``` |
| 31 | + |
| 32 | +**Access Points (Development)** |
| 33 | + |
| 34 | +* API Base URL: [http://localhost:8080](http://localhost:8080) |
| 35 | +* Swagger UI Documentation: [http://localhost:8080/swagger-ui.html](http://localhost:8080/swagger-ui.html) |
| 36 | +* H2 Database Console: [http://localhost:8080/h2-console](http://localhost:8080/h2-console) |
| 37 | +* Health Check: [http://localhost:8080/actuator/health](http://localhost:8080/actuator/health) |
| 38 | + |
| 39 | +### Production Deployment |
| 40 | + |
| 41 | +```bash |
| 42 | +# Using Docker |
| 43 | +docker-compose -f docker/docker-compose.yml up --build |
| 44 | + |
| 45 | +# Access production API |
| 46 | +curl https://health.backend.williamachuchi.com/api/patients |
| 47 | +``` |
| 48 | + |
| 49 | +## Technology Stack |
| 50 | + |
| 51 | +* Java 21 - Runtime environment |
| 52 | +* Spring Boot 3.3.4 - Application framework |
| 53 | +* H2 Database - In-memory database (Development) |
| 54 | +* PostgreSQL - Production database(Not ready H2 used) |
| 55 | +* Spring Data JPA - Data access layer |
| 56 | +* Spring Security - Authentication & Authorization |
| 57 | +* Spring Validation - Input validation |
| 58 | +* OpenAPI 3 - API documentation |
| 59 | +* Docker - Containerization |
| 60 | + |
| 61 | +## API Features |
| 62 | + |
| 63 | +### Patient Management |
| 64 | + |
| 65 | +* Create, read, update, delete patients |
| 66 | +* Search by family name, given name, identifier, birth date |
| 67 | +* Advanced search with multiple criteria |
| 68 | +* Pagination and sorting support |
| 69 | + |
| 70 | +### Encounter Management |
| 71 | + |
| 72 | +* Record patient visits (INPATIENT, OUTPATIENT, EMERGENCY, VIRTUAL) |
| 73 | +* Date range queries and filtering |
| 74 | +* Patient encounter history |
| 75 | +* Encounter classification |
| 76 | + |
| 77 | +### Data Integrity & Validation |
| 78 | + |
| 79 | +* Comprehensive input validation |
| 80 | +* Unique patient identifiers |
| 81 | +* Date validation and business rules |
| 82 | +* Proper error handling with consistent responses |
| 83 | + |
| 84 | +## Database Configuration |
| 85 | + |
| 86 | +### Development (H2) |
| 87 | + |
| 88 | +```properties |
| 89 | +spring.datasource.url=jdbc:h2:mem:healthdb |
| 90 | +spring.h2.console.enabled=true |
| 91 | +``` |
| 92 | + |
| 93 | +### Production (PostgreSQL) |
| 94 | + |
| 95 | +```properties |
| 96 | +spring.datasource.url=jdbc:postgresql://localhost:5432/healthdb |
| 97 | +spring.datasource.username=healthuser |
| 98 | +spring.datasource.password=healthpass |
| 99 | +``` |
| 100 | + |
| 101 | +## Configuration |
| 102 | + |
| 103 | +### Key Application Properties |
| 104 | + |
| 105 | +```properties |
| 106 | +# Server |
| 107 | +server.port=8080 |
| 108 | + |
| 109 | +# Security (Development - Disabled for testing) |
| 110 | +app.security.enabled=false |
| 111 | + |
| 112 | +# Database |
| 113 | +spring.jpa.show-sql=true |
| 114 | +spring.jpa.hibernate.ddl-auto=create-drop |
| 115 | + |
| 116 | +# Date Format |
| 117 | +spring.jackson.serialization.write-dates-as-timestamps=false |
| 118 | +``` |
| 119 | + |
| 120 | +## Testing |
| 121 | + |
| 122 | +### Run All Tests |
| 123 | + |
| 124 | +```bash |
| 125 | +mvn test |
| 126 | +``` |
| 127 | + |
| 128 | +### Test Specific Components |
| 129 | + |
| 130 | +```bash |
| 131 | +# Unit tests only |
| 132 | +mvn test -Dtest=*ServiceTest,*RepositoryTest |
| 133 | + |
| 134 | +# Integration tests |
| 135 | +mvn test -Dtest=*IntegrationTest |
| 136 | + |
| 137 | +# Controller tests |
| 138 | +mvn test -Dtest=*ControllerTest |
| 139 | +``` |
| 140 | + |
| 141 | +### Manual Testing via Swagger |
| 142 | + |
| 143 | +1. Start the application |
| 144 | +2. Navigate to [http://localhost:8080/swagger-ui.html](http://localhost:8080/swagger-ui.html) |
| 145 | +3. Use the "Try it out" feature for each endpoint |
| 146 | +4. Test with sample data provided in the examples |
| 147 | + |
| 148 | +## Troubleshooting |
| 149 | + |
| 150 | +### Common Issues |
| 151 | + |
| 152 | +**Port 8080 Already in Use** |
| 153 | + |
| 154 | +```bash |
| 155 | +sudo lsof -i :8080 |
| 156 | +# Kill the process or use different port |
| 157 | +mvn spring-boot:run -Dspring-boot.run.arguments=--server.port=8081 |
| 158 | +``` |
| 159 | + |
| 160 | +**Java Version Issues** |
| 161 | + |
| 162 | +```bash |
| 163 | +java -version |
| 164 | +# Should show Java 17 or 21 |
| 165 | +``` |
| 166 | + |
| 167 | +**Maven Dependencies** |
| 168 | + |
| 169 | +```bash |
| 170 | +mvn clean |
| 171 | +mvn dependency:purge-local-repository |
| 172 | +mvn install |
| 173 | +``` |
| 174 | + |
| 175 | +**Database Connection** |
| 176 | + |
| 177 | +* H2 Console: [http://localhost:8080/h2-console](http://localhost:8080/h2-console) |
| 178 | +* JDBC URL: jdbc:h2:mem:healthdb |
| 179 | +* Username: sa |
| 180 | +* Password: (empty) |
| 181 | + |
| 182 | +**Verification Steps** |
| 183 | + |
| 184 | +* Application starts without errors |
| 185 | +* Swagger UI loads with all endpoints |
| 186 | +* Health endpoint returns {"status":"UP"} |
| 187 | +* H2 console accessible and shows sample data |
| 188 | +* API endpoints respond without authentication |
| 189 | + |
| 190 | +## Security Considerations |
| 191 | + |
| 192 | +### Development Mode |
| 193 | + |
| 194 | +* Spring Security is disabled for easier testing and analysis |
| 195 | +* H2 console is enabled for database inspection |
| 196 | +* CORS is configured for local development |
| 197 | + |
| 198 | +### Production Readiness |
| 199 | + |
| 200 | +* API Key authentication is implemented but disabled |
| 201 | +* Input validation and sanitization are active |
| 202 | +* Proper error handling prevents information leakage |
| 203 | +* SQL injection protection via JPA/Hibernate |
| 204 | + |
| 205 | +**Security Features (Code-Commented for Analysis)** |
| 206 | + |
| 207 | +```java |
| 208 | +// API Key authentication filter |
| 209 | +// CORS configuration |
| 210 | +// Input validation annotations |
| 211 | +// SQL injection prevention |
| 212 | +// XSS protection headers |
| 213 | +``` |
| 214 | + |
| 215 | +## Project Structure |
| 216 | + |
| 217 | +``` |
| 218 | +src/ |
| 219 | +├── main/ |
| 220 | +│ ├── java/com/countyhospital/healthapi/ |
| 221 | +│ │ ├── patient/ # Patient domain |
| 222 | +│ │ ├── encounter/ # Encounter domain |
| 223 | +│ │ ├── observation/ # Observation domain |
| 224 | +│ │ ├── common/ # Shared components |
| 225 | +│ │ └── config/ # Configuration |
| 226 | +│ └── resources/ |
| 227 | +│ ├── application.properties |
| 228 | +│ └── db/ # Database scripts |
| 229 | +└── test/ # Comprehensive test suite |
| 230 | +``` |
| 231 | + |
| 232 | +## Design Principles |
| 233 | + |
| 234 | +### Layered Architecture |
| 235 | + |
| 236 | +* Controller Layer: REST endpoints, input validation |
| 237 | +* Service Layer: Business logic, transaction management |
| 238 | +* Repository Layer: Data access, JPA operations |
| 239 | +* Domain Layer: Business entities, validation rules |
| 240 | + |
| 241 | +### Healthcare Standards |
| 242 | + |
| 243 | +* FHIR-inspired data models |
| 244 | +* ISO date formats throughout |
| 245 | +* Standardized gender codes (MALE, FEMALE, OTHER, UNKNOWN) |
| 246 | +* Encounter classification following healthcare norms |
| 247 | + |
| 248 | +### Production Considerations |
| 249 | + |
| 250 | +* Comprehensive error handling with consistent responses |
| 251 | +* Proper logging and monitoring setup |
| 252 | +* Database indexing for performance |
| 253 | +* Input validation and sanitization |
| 254 | +* Security headers and CORS configuration |
| 255 | + |
| 256 | +#BY DEV William Achuchi |
0 commit comments