Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up ExpressJS services #898

Merged
merged 26 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
dd7dbcf
Make endpoints configurable
fongsean Jul 1, 2024
cc54640
Add env var support for docker image
fongsean Jul 2, 2024
d23349b
Update package versions
fongsean Jul 2, 2024
adcc8d3
Update docker image link in README
fongsean Jul 2, 2024
cc6f566
Clean up extract-express index to try catch whole block
fongsean Jul 2, 2024
035d371
Implement populate express properly
fongsean Jul 2, 2024
015546a
Delete .env file
fongsean Jul 2, 2024
74f628f
Add defaultTerminologyRequest tests in sdc-populate
fongsean Jul 2, 2024
0d1b496
Clean up sdc populate api calls
fongsean Jul 2, 2024
31f1823
Clean up gitignores
fongsean Jul 2, 2024
68ddcbf
Update package versions
fongsean Jul 2, 2024
7acb94a
Add example.env
fongsean Jul 2, 2024
d99ba59
Fix populate-express to let it compile properly
fongsean Jul 3, 2024
edf18eb
Add sdc-populate tests
fongsean Jul 3, 2024
370141d
Add EHR Server endpoint to not-found issues
fongsean Jul 3, 2024
ba945fb
Update sdc-populate and populate-express to v2.2.6
fongsean Jul 3, 2024
6dc9d3c
Add debug=true query param to populate-express and add README
fongsean Jul 3, 2024
1425e1e
Add $populate service to forms server
fongsean Jul 3, 2024
aa864c7
Bring assemble-express in line with extract and populate
fongsean Jul 3, 2024
3b624df
Remove 'cache control' header when requesting terminology
fongsean Jul 3, 2024
b82985e
Update sdc-populate to v2.2.7
fongsean Jul 3, 2024
b320117
Add endpoint to sdc-assemble 'not-found' warnings and errors
fongsean Jul 4, 2024
a108b08
Remove .env from git
fongsean Jul 4, 2024
83a36c8
Update sdc-assemble and assemble-express to v1.3.0
fongsean Jul 4, 2024
2f86394
Clean up READMEs
fongsean Jul 4, 2024
b117ef1
Fix sdc-assemble module resolution issue
fongsean Jul 4, 2024
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 apps/demo-renderer-app/src/utils/populateInputParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
}

// setting local parameter as false as we are calling $populate with an NPM package, not a server
// package doesn't contain any fhir resources to "know" the context from
// the package doesn't contain any fhir resources to "know" the context from
function createLocalParam(): ParametersParameter {
return {
name: 'local',
Expand All @@ -63,7 +63,7 @@
launchContext: LaunchContext,
patient: Patient,
user: Practitioner,
fhirPathContext: Record<string, any>

Check warning on line 66 in apps/demo-renderer-app/src/utils/populateInputParams.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
): ParametersParameter | null {
const name = launchContext.extension[0].valueId ?? launchContext.extension[0].valueCoding?.code;
if (!name) {
Expand Down Expand Up @@ -170,7 +170,7 @@
launchContexts: LaunchContext[],
sourceQueries: SourceQuery[],
questionnaireLevelVariables: QuestionnaireLevelXFhirQueryVariable[],
fhirPathContext: Record<string, any>

Check warning on line 173 in apps/demo-renderer-app/src/utils/populateInputParams.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
): Parameters | null {
const patientSubject = createPatientSubject(questionnaire, patient);
if (!patientSubject) {
Expand Down
4 changes: 2 additions & 2 deletions apps/smart-forms-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
},
"homepage": "https://github.com/aehrc/smart-forms#readme",
"dependencies": {
"@aehrc/sdc-assemble": "^1.2.0",
"@aehrc/sdc-populate": "^2.2.4",
"@aehrc/sdc-assemble": "^1.3.1",
"@aehrc/sdc-populate": "^2.2.7",
"@aehrc/smart-forms-renderer": "^0.35.9",
"@emotion/react": "^11.11.4",
"@emotion/styled": "^11.11.5",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
import { AssembleEndpoint } from 'forms-server-assemble-endpoint';
import { HapiEndpoint } from 'forms-server-hapi-endpoint';
import { Certificate } from 'aws-cdk-lib/aws-certificatemanager';
import { PopulateEndpoint } from 'forms-server-populate-endpoint';

export class FormsServerAppStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
Expand All @@ -38,9 +39,29 @@ export class FormsServerAppStack extends cdk.Stack {
protocol: ApplicationProtocol.HTTPS,
certificates: [certificate]
});
const populate = new PopulateEndpoint(this, 'FormsServerPopulate', { cluster });
const assemble = new AssembleEndpoint(this, 'FormsServerAssemble', { cluster });
const hapi = new HapiEndpoint(this, 'FormsServerHapi', { cluster });

// Create a target for the populate service, routed from the "api/fhir/$populate" path.
const populateTarget = populate.service.loadBalancerTarget({
containerName: populate.containerName,
containerPort: populate.containerPort
});

const populateTargetGroup = new ApplicationTargetGroup(this, 'FormsServerPopulateTargetGroup', {
vpc,
port: populate.containerPort,
protocol: ApplicationProtocol.HTTP,
targets: [populateTarget],
healthCheck: { path: '/fhir/Questionnaire/$populate' }
});
listener.addAction('FormsServerPopulateAction', {
action: ListenerAction.forward([populateTargetGroup]),
priority: 1,
conditions: [ListenerCondition.pathPatterns(['/fhir/Questionnaire/$populate'])]
});

// Create a target for the assemble service, routed from the "api/fhir/$assemble" path.
const assembleTarget = assemble.service.loadBalancerTarget({
containerName: assemble.containerName,
Expand All @@ -56,7 +77,7 @@ export class FormsServerAppStack extends cdk.Stack {
});
listener.addAction('FormsServerAssembleAction', {
action: ListenerAction.forward([assembleTargetGroup]),
priority: 1,
priority: 2,
conditions: [ListenerCondition.pathPatterns(['/fhir/Questionnaire/$assemble'])]
});

Expand Down
3 changes: 2 additions & 1 deletion deployment/forms-server/forms-server-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"constructs": "^10.3.0",
"source-map-support": "^0.5.21",
"forms-server-assemble-endpoint": "^0.1.0",
"forms-server-hapi-endpoint": "^0.1.0"
"forms-server-hapi-endpoint": "^0.1.0",
"forms-server-populate-endpoint": "^0.1.0"
}
}
8 changes: 8 additions & 0 deletions deployment/forms-server/populate-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/forms-server/populate-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
12 changes: 12 additions & 0 deletions deployment/forms-server/populate-endpoint/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Welcome to your CDK TypeScript Construct Library project

You should explore the contents of this project. It demonstrates a CDK Construct Library that includes a construct (`PopulateEndpoint`)
which contains an Amazon SQS queue that is subscribed to an Amazon SNS topic.

The construct defines an interface (`PopulateEndpointProps`) to configure the visibility timeout of the queue.

## 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
8 changes: 8 additions & 0 deletions deployment/forms-server/populate-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/forms-server/populate-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 PopulateEndpointProps {
cluster: Cluster;
}

export class PopulateEndpoint extends Construct {
containerName = 'forms-server-populate';
containerPort = 3001;
service: FargateService;

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

const { cluster } = props;

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

// Create the cache container.
taskDefinition.addContainer('FormsServerPopulateContainer', {
containerName: this.containerName,
image: ContainerImage.fromRegistry('aehrc/smart-forms-populate:latest'),
portMappings: [{ containerPort: this.containerPort }],
logging: AwsLogDriver.awsLogs({
streamPrefix: 'forms-server-populate',
logRetention: RetentionDays.ONE_MONTH
})
});

this.service = new FargateService(this, 'FormsServerPopulateService', {
cluster,
taskDefinition
});
}
}
24 changes: 24 additions & 0 deletions deployment/forms-server/populate-endpoint/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "forms-server-populate-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.12",
"@types/node": "20.14.2",
"aws-cdk-lib": "2.104.0",
"constructs": "^10.3.0",
"jest": "^29.7.0",
"ts-jest": "^29.1.1",
"typescript": "~5.2.2"
},
"peerDependencies": {
"aws-cdk-lib": "2.104.0",
"constructs": "^10.3.0"
}
}
23 changes: 23 additions & 0 deletions deployment/forms-server/populate-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"]
}
Loading
Loading