Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
bb45f44
Add AWS Bedrock client and configuration to backend
Apr 3, 2025
511c5b6
Update package dependencies and enhance AWS Bedrock service with medi…
Apr 3, 2025
b666d87
Refactor AwsBedrockService tests and improve code formatting for bett…
Apr 3, 2025
585ff73
Update package dependencies to latest versions, including @vitest/cov…
Apr 3, 2025
bb8fa1c
Enhance AwsBedrockService to include metadata in medical information …
Apr 3, 2025
125187a
Refactor error handling in AwsBedrockService to improve readability a…
Apr 3, 2025
d4c38eb
Refactor AwsBedrockService to improve configuration handling, add rat…
adamrefaey Apr 3, 2025
fd80b62
Refactor AwsBedrockService and security.utils for improved code forma…
adamrefaey Apr 3, 2025
4dbabc3
Update default AWS Bedrock model in configuration and AwsBedrockServi…
adamrefaey Apr 4, 2025
d1a6eff
Improve code formatting in AwsBedrockService by adjusting line breaks…
adamrefaey Apr 4, 2025
e3e92e4
Enhance AwsBedrockService and tests to support image-based medical in…
adamrefaey Apr 4, 2025
0971bb1
Enhance image validation in AwsBedrockService and security.utils to s…
adamrefaey Apr 4, 2025
fa494a8
Add configuration loading and mock providers in AppModule tests for A…
adamrefaey Apr 4, 2025
302ffa4
Update AWS SDK dependencies and enhance AwsBedrockService for improve…
adamrefaey Apr 6, 2025
269f231
Refactor BedrockTestController and AwsBedrockService tests to improve…
adamrefaey Apr 6, 2025
79a133b
Refactor test cases in BedrockTestController and AwsBedrockService fo…
adamrefaey Apr 6, 2025
1cc30b4
Add AWS Textract integration for extracting text from medical lab rep…
adamrefaey Apr 7, 2025
5d79900
Remove BedrockTestController and related files from the backend, incl…
adamrefaey Apr 7, 2025
4de57dc
Refactor backend/src/app.module.ts to streamline controller definitio…
adamrefaey Apr 7, 2025
afe9035
Update AwsBedrockService and related tests to enhance model interacti…
adamrefaey Apr 7, 2025
60fea4e
Update AWS Textract configuration and integrate rate limiting functio…
adamrefaey Apr 7, 2025
92183fc
Enhance AwsBedrockService with improved client initialization and rat…
adamrefaey Apr 7, 2025
eddc74f
Refactor AwsBedrockService to simplify model ID and inference profile…
adamrefaey Apr 7, 2025
f3ae9b5
Refactor AwsTextractService to remove metadata handling and simplify …
adamrefaey Apr 7, 2025
bba9571
Refactor AwsTextractService to encapsulate client creation logic
adamrefaey Apr 7, 2025
4e2c1ba
Refactor unit tests for AwsTextractService to improve mock configuration
adamrefaey Apr 7, 2025
499c562
Enhance AwsBedrockService with medical document analysis capabilities
adamrefaey Apr 7, 2025
6359b4b
Enhance AwsBedrockService and AwsTextractService with user ID-based r…
adamrefaey Apr 8, 2025
36cdfd4
Implement cleanup mechanism in RateLimiter for efficient request trac…
adamrefaey Apr 8, 2025
4a778b6
Add DocumentProcessorModule and DocumentProcessorService for medical …
adamrefaey Apr 8, 2025
b0e33f0
Refactor AwsTextractService to streamline document processing logic
adamrefaey Apr 8, 2025
b46b5df
Add DocumentProcessorController and update README for medical documen…
adamrefaey Apr 8, 2025
cbac3d8
Refactor app.module.ts and document-processor.module.ts to remove Tex…
adamrefaey Apr 8, 2025
32a9272
Refactor document processing structure and implement new services
adamrefaey Apr 8, 2025
4c29353
Enhance DocumentProcessorService with Perplexity integration for simp…
adamrefaey Apr 8, 2025
fbc5c20
Remove unused devDependencies from package.json and package-lock.json…
adamrefaey Apr 9, 2025
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
2 changes: 1 addition & 1 deletion backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,4 @@ This script sets a resource policy that:
1. Allows only authenticated Cognito users to access your API
2. Denies any non-HTTPS requests to your API

If you need more complex permissions, you can modify the policy object in the script.
If you need more complex permissions, you can modify the policy object in the script.
4,783 changes: 3,464 additions & 1,319 deletions backend/package-lock.json

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@
"cdk:synth": "dotenv -- npx cdk synth"
},
"dependencies": {
"@aws-sdk/client-bedrock": "^3.782.0",
"@aws-sdk/client-bedrock-runtime": "^3.782.0",
"@aws-sdk/client-dynamodb": "^3.758.0",
"@aws-sdk/client-secrets-manager": "^3.758.0",
"@aws-sdk/client-textract": "^3.782.0",
"@aws-sdk/util-dynamodb": "^3.758.0",
"@nestjs/common": "^10.0.0",
"@nestjs/config": "^3.1.1",
Expand Down Expand Up @@ -69,10 +72,11 @@
"@types/jest": "^29.5.14",
"@types/jsonwebtoken": "^9.0.4",
"@types/jwk-to-pem": "^2.0.2",
"@types/multer": "^1.4.12",
"@types/node": "^20.12.7",
"@typescript-eslint/eslint-plugin": "^7.9.0",
"@typescript-eslint/parser": "^7.9.0",
"@vitest/coverage-c8": "^0.33.0",
"@vitest/coverage-v8": "^3.1.1",
"aws-cdk": "2.139.0",
"aws-cdk-lib": "^2.185.0",
"dotenv-cli": "^8.0.0",
Expand All @@ -89,7 +93,7 @@
"tsconfig-paths": "^4.2.0",
"typescript": "^5.4.5",
"vite-tsconfig-paths": "^4.2.0",
"vitest": "^0.33.0"
"vitest": "^3.1.1"
},
"peerDependencies": {
"aws-cdk-lib": "^2.185.0"
Expand Down
33 changes: 33 additions & 0 deletions backend/src/app.module.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,19 @@ import { ConfigModule } from '@nestjs/config';
import { JwtModule } from '@nestjs/jwt';
import { ReportsService } from './reports/reports.service';
import { vi, describe, it, expect } from 'vitest';
import configuration from './config/configuration';
import { PerplexityService } from './services/perplexity.service';
import { AwsSecretsService } from './services/aws-secrets.service';
import { AwsTextractService } from './document-processor/services/aws-textract.service';
import { AwsBedrockService } from './document-processor/services/aws-bedrock.service';

describe('AppModule', () => {
it('should compile the module', async () => {
const module = await Test.createTestingModule({
imports: [
ConfigModule.forRoot({
isGlobal: true,
load: [configuration],
}),
JwtModule.register({
secret: 'test-secret',
Expand All @@ -26,6 +32,33 @@ describe('AppModule', () => {
findOne: vi.fn().mockResolvedValue({}),
updateStatus: vi.fn().mockResolvedValue({}),
})
.overrideProvider(PerplexityService)
.useValue({
askQuestion: vi.fn().mockResolvedValue({}),
})
.overrideProvider(AwsSecretsService)
.useValue({
getPerplexityApiKey: vi.fn().mockResolvedValue('test-api-key'),
})
.overrideProvider(AwsTextractService)
.useValue({
extractText: vi.fn().mockResolvedValue({}),
processBatch: vi.fn().mockResolvedValue([]),
})
.overrideProvider(AwsBedrockService)
.useValue({
generateResponse: vi.fn().mockResolvedValue('test response'),
analyzeMedicalDocument: vi.fn().mockResolvedValue({
keyMedicalTerms: [],
labValues: [],
diagnoses: [],
metadata: {
isMedicalReport: true,
confidence: 0.9,
missingInformation: [],
},
}),
})
.compile();

expect(module).toBeDefined();
Expand Down
2 changes: 2 additions & 0 deletions backend/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { UserController } from './user/user.controller';
import { ReportsModule } from './reports/reports.module';
import { HealthController } from './health/health.controller';
import { AuthMiddleware } from './auth/auth.middleware';
import { DocumentProcessorModule } from './document-processor/document-processor.module';

@Module({
imports: [
Expand All @@ -18,6 +19,7 @@ import { AuthMiddleware } from './auth/auth.middleware';
load: [configuration],
}),
ReportsModule,
DocumentProcessorModule,
],
controllers: [AppController, HealthController, PerplexityController, UserController],
providers: [AppService, AwsSecretsService, PerplexityService],
Expand Down
8 changes: 4 additions & 4 deletions backend/src/config/configuration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import configuration from './configuration';
describe('Configuration', () => {
// Save original environment
const originalEnv = { ...process.env };

beforeEach(() => {
// Clear environment variables before each test
process.env = {};

// Set NODE_ENV to test for the first test
process.env.NODE_ENV = 'test';
});
Expand All @@ -20,7 +20,7 @@ describe('Configuration', () => {

it('should return default values when no env variables are set', () => {
const config = configuration();

expect(config.port).toBe(3000);
expect(config.environment).toBe('test');
expect(config.aws.region).toBe('us-east-1'); // Default value in configuration.ts
Expand Down Expand Up @@ -50,4 +50,4 @@ describe('Configuration', () => {
delete process.env.AWS_COGNITO_USER_POOL_ID;
delete process.env.AWS_COGNITO_CLIENT_ID;
});
});
});
19 changes: 17 additions & 2 deletions backend/src/config/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,27 @@ export default () => ({
clientId: process.env.AWS_COGNITO_CLIENT_ID,
},
secretsManager: {
perplexityApiKeySecret: process.env.PERPLEXITY_API_KEY_SECRET_NAME || 'medical-reports-explainer/perplexity-api-key',
perplexityApiKeySecret:
process.env.PERPLEXITY_API_KEY_SECRET_NAME ||
'medical-reports-explainer/perplexity-api-key',
},
aws: {
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
}
sessionToken: process.env.AWS_SESSION_TOKEN,
},
bedrock: {
model: process.env.AWS_BEDROCK_MODEL || 'us.anthropic.claude-3-7-sonnet-20250219-v1:0',
maxTokens: parseInt(process.env.AWS_BEDROCK_MAX_TOKENS || '2048', 10),
inferenceProfileArn:
process.env.AWS_BEDROCK_INFERENCE_PROFILE_ARN ||
'arn:aws:bedrock:us-east-1:841162674562:inference-profile/us.anthropic.claude-3-7-sonnet-20250219-v1:0',
requestsPerMinute: parseInt(process.env.AWS_BEDROCK_REQUESTS_PER_MINUTE || '20', 20),
},
textract: {
maxBatchSize: parseInt(process.env.AWS_TEXTRACT_MAX_BATCH_SIZE || '10', 10),
documentRequestsPerMinute: parseInt(process.env.AWS_TEXTRACT_DOCS_PER_MINUTE || '20', 20),
},
},
perplexity: {
apiBaseUrl: 'https://api.perplexity.ai',
Expand Down
Loading