Skip to content

Commit

Permalink
Merge pull request #878 from aehrc/deploy-transform
Browse files Browse the repository at this point in the history
Add transform endpoint on ehr proxy deployment
  • Loading branch information
fongsean authored Jun 20, 2024
2 parents fbf260f + b27529f commit 7400b31
Show file tree
Hide file tree
Showing 10 changed files with 179 additions and 32 deletions.
22 changes: 21 additions & 1 deletion deployment/ehr-proxy/ehr-proxy-app/lib/ehr-proxy-app-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { ARecord, HostedZone, RecordTarget } from 'aws-cdk-lib/aws-route53';
import { LoadBalancerTarget } from 'aws-cdk-lib/aws-route53-targets';
import { HapiEndpoint } from 'ehr-proxy-hapi-endpoint';
import { SmartProxy } from 'ehr-proxy-smart-proxy';
import { TransformEndpoint } from 'ehr-proxy-transform-endpoint';

export class EhrProxyAppStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
Expand Down Expand Up @@ -53,6 +54,25 @@ export class EhrProxyAppStack extends cdk.Stack {

const hapi = new HapiEndpoint(this, 'EhrProxyHapi', { cluster });
const smartProxy = new SmartProxy(this, 'EhrProxySmartProxy', { cluster });
const transform = new TransformEndpoint(this, 'EhrProxyTransform', { cluster });

// Create a target for the transform service
const transformTarget = transform.service.loadBalancerTarget({
containerName: transform.containerName,
containerPort: transform.containerPort
});
const transformTargetGroup = new ApplicationTargetGroup(this, 'EhrProxyTransformTargetGroup', {
vpc,
port: transform.containerPort,
protocol: ApplicationProtocol.HTTP,
targets: [transformTarget],
healthCheck: { path: '/StructureMap' }
});
listener.addAction('EhrProxyTransformAction', {
action: ListenerAction.forward([transformTargetGroup]),
priority: 1,
conditions: [ListenerCondition.pathPatterns(['/fhir/StructureMap/$transform'])]
});

// Create a target for the HAPI FHIR API service
const hapiTarget = hapi.service.loadBalancerTarget({
Expand All @@ -68,7 +88,7 @@ export class EhrProxyAppStack extends cdk.Stack {
});
listener.addAction('EhrProxyHapiAction', {
action: ListenerAction.forward([hapiTargetGroup]),
priority: 1,
priority: 2,
conditions: [ListenerCondition.pathPatterns(['/fhir*'])]
});

Expand Down
3 changes: 2 additions & 1 deletion deployment/ehr-proxy/ehr-proxy-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"constructs": "^10.0.0",
"source-map-support": "^0.5.21",
"ehr-proxy-hapi-endpoint": "^0.1.0",
"ehr-proxy-smart-proxy": "^0.1.0"
"ehr-proxy-smart-proxy": "^0.1.0",
"ehr-proxy-transform-endpoint": "^0.1.0"
}
}
8 changes: 8 additions & 0 deletions deployment/ehr-proxy/transform-endpoint/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
*.js
!jest.config.js
*.d.ts
node_modules

# CDK asset staging directory
.cdk.staging
cdk.out
6 changes: 6 additions & 0 deletions deployment/ehr-proxy/transform-endpoint/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*.ts
!*.d.ts

# CDK asset staging directory
.cdk.staging
cdk.out
14 changes: 14 additions & 0 deletions deployment/ehr-proxy/transform-endpoint/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Welcome to your CDK TypeScript project

This is a blank project for CDK development with TypeScript.

The `cdk.json` file tells the CDK Toolkit how to execute your app.

## Useful commands

* `npm run build` compile typescript to js
* `npm run watch` watch for changes and compile
* `npm run test` perform the jest unit tests
* `cdk deploy` deploy this stack to your default AWS account/region
* `cdk diff` compare deployed stack with current state
* `cdk synth` emits the synthesized CloudFormation template
8 changes: 8 additions & 0 deletions deployment/ehr-proxy/transform-endpoint/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
testEnvironment: 'node',
roots: ['<rootDir>/test'],
testMatch: ['**/*.test.ts'],
transform: {
'^.+\\.tsx?$': 'ts-jest'
}
};
49 changes: 49 additions & 0 deletions deployment/ehr-proxy/transform-endpoint/lib/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import {
AwsLogDriver,
Cluster,
Compatibility,
ContainerImage,
FargateService,
TaskDefinition
} from 'aws-cdk-lib/aws-ecs';
import { Construct } from 'constructs';
import { RetentionDays } from 'aws-cdk-lib/aws-logs';

export interface TransformEndpointProps {
cluster: Cluster;
}

export class TransformEndpoint extends Construct {
containerName = 'ehr-proxy-transform';
containerPort = 80;
service: FargateService;

constructor(scope: Construct, id: string, props: TransformEndpointProps) {
super(scope, id);

const { cluster } = props;

// Create a task definition that contains both the application and cache containers.
const taskDefinition = new TaskDefinition(this, 'EhrProxyTransformTaskDefinition', {
compatibility: Compatibility.FARGATE,
cpu: '256',
memoryMiB: '512'
});

// Create the cache container.
taskDefinition.addContainer('EhrProxyTransformContainer', {
containerName: this.containerName,
image: ContainerImage.fromRegistry('yeexianfong/demo-map-server:latest'),
portMappings: [{ containerPort: this.containerPort }],
logging: AwsLogDriver.awsLogs({
streamPrefix: 'ehr-proxy-transform',
logRetention: RetentionDays.ONE_MONTH
})
});

this.service = new FargateService(this, 'EhrProxyTransformService', {
cluster,
taskDefinition
});
}
}
25 changes: 25 additions & 0 deletions deployment/ehr-proxy/transform-endpoint/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "ehr-proxy-transform-endpoint",
"version": "0.1.0",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"scripts": {
"build": "tsc",
"watch": "tsc -w",
"test": "jest"
},
"devDependencies": {
"@types/jest": "^29.5.5",
"@types/node": "20.14.2",
"aws-cdk-lib": "2.104.0",
"constructs": "^10.0.0",
"jest": "^29.7.0",
"ts-jest": "^29.1.1",
"typescript": "~5.2.2"
},
"dependencies": {
"aws-cdk-lib": "2.104.0",
"constructs": "^10.0.0",
"source-map-support": "^0.5.21"
}
}
23 changes: 23 additions & 0 deletions deployment/ehr-proxy/transform-endpoint/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"compilerOptions": {
"target": "ES2020",
"module": "commonjs",
"lib": ["es2020", "dom"],
"declaration": true,
"strict": true,
"noImplicitAny": true,
"strictNullChecks": true,
"noImplicitThis": true,
"alwaysStrict": true,
"noUnusedLocals": false,
"noUnusedParameters": false,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": false,
"inlineSourceMap": true,
"inlineSources": true,
"experimentalDecorators": true,
"strictPropertyInitialization": false,
"typeRoots": ["./node_modules/@types"]
},
"exclude": ["node_modules", "cdk.out"]
}
53 changes: 23 additions & 30 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7400b31

Please sign in to comment.