Skip to content

Commit

Permalink
Add the rest of the approve input parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
elsaperelli committed Aug 20, 2024
1 parent 2e47e38 commit 6d11eaf
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 3 deletions.
3 changes: 3 additions & 0 deletions service/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,9 @@ And takes the following optional parameters:
- approvalDate
- artifactAssessmentType (must be included with artifactAssessmentSummary if provided)
- artifactAssessmentSummary (must be included with artifactAssessmentType if provided)
- artifactAssessmentTarget
- artifactAssessmentRelatedArtifact
- artifactAssessmentAuthor

## License

Expand Down
7 changes: 6 additions & 1 deletion service/src/requestSchemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { BadRequestError, NotImplementedError } from './util/errorUtils';

const DATE_REGEX = /([0-9]([0-9]([0-9][1-9]|[1-9]0)|[1-9]00)|[1-9]000)(-(0[1-9]|1[0-2])(-(0[1-9]|[1-2][0-9]|3[0-1]))?)/;
const VERSION_REGEX = /^\d+\.\d+\.\d+(\.\d+|)$/;
const URI_REGEX = /\S*/; // as defined by the FHIR specification: https://hl7.org/fhir/R4/datatypes.html#uri

// Operation Definition: http://hl7.org/fhir/us/cqfmeasures/STU4/OperationDefinition-cqfm-package.html
const UNSUPPORTED_PACKAGE_ARGS = [
Expand Down Expand Up @@ -178,6 +179,7 @@ const stringToBool = z
const stringToNumber = z.coerce.number();
const checkDate = z.string().regex(DATE_REGEX, 'Invalid FHIR date');
const checkVersion = z.string().regex(VERSION_REGEX, 'Invalid Semantic Version');
const checkUri = z.string().regex(URI_REGEX, 'Invalid URI');

export const DraftArgs = z
.object({ id: z.string(), version: checkVersion })
Expand All @@ -196,7 +198,10 @@ export const ApproveArgs = z
artifactAssessmentType: z
.union([z.literal('documentation'), z.literal('guidance'), z.literal('review')])
.optional(),
artifactAssessmentSummary: z.string().optional()
artifactAssessmentSummary: z.string().optional(),
artifactAssessmentTarget: checkUri.optional(),
artifactAssessmentRelatedArtifact: checkUri.optional(),
artifactAssessmentAuthor: z.object({ reference: z.string() }).optional()
})
.strict()
.superRefine(catchInvalidParams([catchMissingId, catchMissingTypeAndSummary]));
Expand Down
22 changes: 22 additions & 0 deletions service/src/services/LibraryService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,17 @@ export class LibraryService implements Service<CRMIShareableLibrary> {
{ url: 'type', valueCode: parsedParams.artifactAssessmentType },
{ url: 'text', valueMarkdown: parsedParams.artifactAssessmentSummary }
);

if (parsedParams.artifactAssessmentTarget) {
approveExtension.push({ url: 'target', valueUri: parsedParams.artifactAssessmentTarget });
}
if (parsedParams.artifactAssessmentRelatedArtifact) {
approveExtension.push({ url: 'reference', valueUri: parsedParams.artifactAssessmentRelatedArtifact });
}
if (parsedParams.artifactAssessmentAuthor) {
approveExtension.push({ url: 'user', valueString: parsedParams.artifactAssessmentAuthor.reference });
}

if (library.extension) {
library.extension.push({
extension: approveExtension,
Expand Down Expand Up @@ -318,6 +329,17 @@ export class LibraryService implements Service<CRMIShareableLibrary> {
{ url: 'type', valueCode: parsedParams.artifactAssessmentType },
{ url: 'text', valueMarkdown: parsedParams.artifactAssessmentSummary }
);

if (parsedParams.artifactAssessmentTarget) {
approveExtension.push({ url: 'target', valueUri: parsedParams.artifactAssessmentTarget });
}
if (parsedParams.artifactAssessmentRelatedArtifact) {
approveExtension.push({ url: 'reference', valueUri: parsedParams.artifactAssessmentRelatedArtifact });
}
if (parsedParams.artifactAssessmentAuthor) {
approveExtension.push({ url: 'user', valueString: parsedParams.artifactAssessmentAuthor.reference });
}

if (child.extension) {
child.extension.push({
extension: approveExtension,
Expand Down
22 changes: 22 additions & 0 deletions service/src/services/MeasureService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,17 @@ export class MeasureService implements Service<CRMIShareableMeasure> {
{ url: 'type', valueCode: parsedParams.artifactAssessmentType },
{ url: 'text', valueMarkdown: parsedParams.artifactAssessmentSummary }
);

if (parsedParams.artifactAssessmentTarget) {
approveExtension.push({ url: 'target', valueUri: parsedParams.artifactAssessmentTarget });
}
if (parsedParams.artifactAssessmentRelatedArtifact) {
approveExtension.push({ url: 'reference', valueUri: parsedParams.artifactAssessmentRelatedArtifact });
}
if (parsedParams.artifactAssessmentAuthor) {
approveExtension.push({ url: 'user', valueString: parsedParams.artifactAssessmentAuthor.reference });
}

if (measure.extension) {
measure.extension.push({
extension: approveExtension,
Expand Down Expand Up @@ -320,6 +331,17 @@ export class MeasureService implements Service<CRMIShareableMeasure> {
{ url: 'type', valueCode: parsedParams.artifactAssessmentType },
{ url: 'text', valueMarkdown: parsedParams.artifactAssessmentSummary }
);

if (parsedParams.artifactAssessmentTarget) {
approveExtension.push({ url: 'target', valueUri: parsedParams.artifactAssessmentTarget });
}
if (parsedParams.artifactAssessmentRelatedArtifact) {
approveExtension.push({ url: 'reference', valueUri: parsedParams.artifactAssessmentRelatedArtifact });
}
if (parsedParams.artifactAssessmentAuthor) {
approveExtension.push({ url: 'user', valueString: parsedParams.artifactAssessmentAuthor.reference });
}

if (child.extension) {
child.extension.push({
extension: approveExtension,
Expand Down
1 change: 1 addition & 0 deletions service/src/util/inputUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export function gatherParams(query: RequestQuery, parameters?: fhir4.Parameters)
bodyParam.valueCanonical ||
bodyParam.valueDate ||
bodyParam.valueCode ||
bodyParam.valueReference ||
bodyParam.valueBoolean;
}
return params;
Expand Down
9 changes: 8 additions & 1 deletion service/test/services/LibraryService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1085,13 +1085,20 @@ describe('LibraryService', () => {
it('returns 200 status with a Bundle result containing the updated parent Library artifact and any children it has for GET /Library/$approve', async () => {
await supertest(server.app)
.get('/4_0_1/Library/$approve')
.query({ id: 'approve-child1' })
.query({
id: 'approve-child1',
artifactAssessmentType: 'guidance',
artifactAssessmentSummary: 'Sample summary',
artifactAssessmentAuthor: { reference: 'Sample Author' }
})
.set('Accept', 'application/json+fhir')
.expect(200)
.then(response => {
expect(response.body.total).toEqual(2);
expect(response.body.entry[0].resource.date).toBeDefined();
expect(response.body.entry[0].resource.extension[0].extension[2].valueString).toEqual('Sample Author');
expect(response.body.entry[1].resource.date).toBeDefined();
expect(response.body.entry[1].resource.extension[1].extension[2].valueString).toEqual('Sample Author');
});
});

Expand Down
10 changes: 9 additions & 1 deletion service/test/services/MeasureService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1098,14 +1098,22 @@ describe('MeasureService', () => {
it('returns 200 status with a Bundle result containing the updated parent Measure artifact and any children it has for GET /Measure/$approve', async () => {
await supertest(server.app)
.get('/4_0_1/Measure/$approve')
.query({ id: 'approve-parent' })
.query({
id: 'approve-parent',
artifactAssessmentType: 'guidance',
artifactAssessmentSummary: 'Sample summary',
artifactAssessmentAuthor: { reference: 'Sample Author' }
})
.set('Accept', 'application/json+fhir')
.expect(200)
.then(response => {
expect(response.body.total).toEqual(3);
expect(response.body.entry[0].resource.date).toBeDefined();
expect(response.body.entry[0].resource.extension[0].extension[2].valueString).toEqual('Sample Author');
expect(response.body.entry[1].resource.date).toBeDefined();
expect(response.body.entry[1].resource.extension[1].extension[2].valueString).toEqual('Sample Author');
expect(response.body.entry[2].resource.date).toBeDefined();
expect(response.body.entry[2].resource.extension[1].extension[2].valueString).toEqual('Sample Author');
});
});

Expand Down

0 comments on commit 6d11eaf

Please sign in to comment.