Skip to content

Commit

Permalink
Change service location in frontend, another upload script
Browse files Browse the repository at this point in the history
  • Loading branch information
elsaperelli committed Nov 25, 2024
1 parent 9e6e8a2 commit 8f2756b
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 10 deletions.
2 changes: 1 addition & 1 deletion app/src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export default function Home({
<Divider my="sm" variant="dotted" />
<Title order={2}>Service Location:</Title>
<div style={{ marginTop: '18px', marginBottom: '18px' }}>
<Anchor href={`${serviceUri}/metadata`}>{`${serviceUri}/metadata`}</Anchor>
<Anchor href={`${serviceUri}`}>{`${serviceUri}`}</Anchor>
</div>
<Divider my="sm" variant="dotted" />
<Title order={2}>Service Capabilities:</Title>
Expand Down
12 changes: 12 additions & 0 deletions service/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,18 @@ To load [ecqm-content-qicore-2024](https://github.com/cqframework/ecqm-content-q
npm run db:loadEcqmContent <optional service url, default: http://localhost:3000/4_0_1>
```

To load a measure bundle and related library artifacts, and coerce all of their statuses to `active`, run:

```
npm run db:loadPublishableContent <path to measure bundle>
```

To load multiple bundles from a directory, and coerce all of their statuses to `active`, run:

```
npm run db:loadPublishableContent <path to directory>
```

### Bundle Upload Details

Upon uploading a Measure resource, the Measure's main library is added to the `relatedArtifact` array with an [isOwned extension](https://build.fhir.org/ig/HL7/fhir-extensions/StructureDefinition-artifact-isOwned.html).
Expand Down
1 change: 1 addition & 0 deletions service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"db:loadBundle": "ts-node ./scripts/dbSetup.ts loadBundle",
"db:postBundle": "ts-node ./scripts/dbSetup.ts postBundle",
"db:loadEcqmContent": "ts-node ./scripts/dbSetup.ts loadEcqmContent",
"db:loadPublishableContent": "ts-node ./scripts/dbSetup.ts loadPublishableContent",
"lint": "eslint \"./src/**/*.{js,ts}\"",
"lint:fix": "eslint \"./src/**/*.{js,ts}\" --fix",
"prettier": "prettier --check \"./src/**/*.{js,ts}\"",
Expand Down
37 changes: 28 additions & 9 deletions service/scripts/dbSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ async function deleteCollections() {
* If a connectionURL is provided, then posts the resources to the server at the
* connectionURL (as a transaction bundle), otherwise, loads the resources directly to the database
*/
async function loadBundle(fileOrDirectoryPath: string, connectionURL?: string) {
async function loadBundle(fileOrDirectoryPath: string, connectionURL?: string, publishable?: boolean) {
const status = fs.statSync(fileOrDirectoryPath);
if (status.isDirectory()) {
const filePaths: string[] = [];
Expand All @@ -178,12 +178,14 @@ async function loadBundle(fileOrDirectoryPath: string, connectionURL?: string) {
});

for (const filePath of filePaths) {
await (connectionURL ? postBundleResources(filePath, connectionURL) : uploadBundleResources(filePath));
await (connectionURL
? postBundleResources(filePath, connectionURL, publishable)
: uploadBundleResources(filePath, publishable));
}
} else {
await (connectionURL
? postBundleResources(fileOrDirectoryPath, connectionURL)
: uploadBundleResources(fileOrDirectoryPath));
? postBundleResources(fileOrDirectoryPath, connectionURL, publishable)
: uploadBundleResources(fileOrDirectoryPath, publishable));
}
}

Expand Down Expand Up @@ -225,7 +227,7 @@ async function transactBundle(bundle: fhir4.Bundle, url: string) {
/*
* Loads all resources found in the bundle at filePath, by POSTing them to the provided url
*/
async function postBundleResources(filePath: string, url: string) {
async function postBundleResources(filePath: string, url: string, publishable?: boolean) {
console.log(`Loading bundle from path ${filePath}`);

const data = fs.readFileSync(filePath, 'utf8');
Expand All @@ -235,7 +237,7 @@ async function postBundleResources(filePath: string, url: string) {
const entries = bundle.entry as fhir4.BundleEntry<FhirArtifact>[];
// modify bundles before posting
if (entries) {
const modifiedEntries = modifyEntriesForUpload(entries);
const modifiedEntries = modifyEntriesForUpload(entries, publishable);
bundle.entry = modifiedEntries;
}
await transactBundle(bundle, url);
Expand All @@ -245,7 +247,7 @@ async function postBundleResources(filePath: string, url: string) {
/*
* Loads all resources found in the bundle at filePath, directly to the database
*/
async function uploadBundleResources(filePath: string) {
async function uploadBundleResources(filePath: string, publishable?: boolean) {
console.log(`Loading bundle from path ${filePath}`);

const data = fs.readFileSync(filePath, 'utf8');
Expand All @@ -259,7 +261,7 @@ async function uploadBundleResources(filePath: string) {
console.log(`Connected to ${DB_URL}`);
let resourcesUploaded = 0;
let notUploaded = 0;
const modifiedEntries = modifyEntriesForUpload(entries);
const modifiedEntries = modifyEntriesForUpload(entries, publishable);
const uploads = modifiedEntries.map(async entry => {
// add Library owned extension
if (entry.resource?.resourceType === 'Library' || entry.resource?.resourceType === 'Measure') {
Expand Down Expand Up @@ -300,7 +302,7 @@ async function uploadBundleResources(filePath: string) {
* Convenience modification of an array of entries to create isOwned relationships and coerce to status active.
* This lets us massage existing data that may not have the appropriate properties needed for a Publishable Measure Repository
*/
export function modifyEntriesForUpload(entries: fhir4.BundleEntry<fhir4.FhirResource>[]) {
export function modifyEntriesForUpload(entries: fhir4.BundleEntry<fhir4.FhirResource>[], publishable?: boolean) {
// pre-process to find owned relationships
const ownedUrls: string[] = [];
const modifiedEntries = entries.map(ent => {
Expand Down Expand Up @@ -339,6 +341,11 @@ export function modifyEntriesForUpload(entries: fhir4.BundleEntry<fhir4.FhirReso
console.warn(
`Resource ${updatedEntry.resource.resourceType}/${updatedEntry.resource.id} status has been coerced to 'active' for Publishable environment.`
);
} else if (publishable) {
updatedEntry.resource.status = 'active';
console.warn(
`Resource ${updatedEntry.resource.resourceType}/${updatedEntry.resource.id} status has been coerced to 'active' for Publishable environment.`
);
}
}
return updatedEntry;
Expand Down Expand Up @@ -437,6 +444,18 @@ if (process.argv[2] === 'delete') {

const bundlePaths = getBundlePaths();
loadEcqmContent(bundlePaths, url);
} else if (process.argv[2] === 'loadPublishableContent') {
if (process.argv.length < 4) {
throw new Error('Filename argument required.');
}
loadBundle(process.argv[3], undefined, true)
.then(() => {
console.log('Done');
})
.catch(console.error)
.finally(() => {
Connection.connection?.close();
});
} else {
console.log('Usage: ts-node src/scripts/dbSetup.ts <create|delete|reset>');
}

0 comments on commit 8f2756b

Please sign in to comment.