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

fix(search): Log message when missing search parameter in MockClient, add tests #4604

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
Use predefined function to validate resource type
  • Loading branch information
thejwuscript authored and ThatOneBro committed May 28, 2024
commit 913668ccfea9100ca1d995d86cf3153ccb617637
2 changes: 2 additions & 0 deletions packages/fhir-router/src/fhirrouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
normalizeOperationOutcome,
notFound,
parseSearchRequest,
validateResourceType
} from '@medplum/core';
import { OperationOutcome, Resource, ResourceType } from '@medplum/fhirtypes';
import type { IncomingHttpHeaders } from 'node:http';
Expand Down Expand Up @@ -45,6 +46,7 @@ async function batch(req: FhirRequest, repo: FhirRepository, router: FhirRouter)
// Search
async function search(req: FhirRequest, repo: FhirRepository): Promise<FhirResponse> {
const { resourceType } = req.params;
validateResourceType(resourceType);
const query = req.query as Record<string, string[] | string | undefined>;
const bundle = await repo.search(parseSearchRequest(resourceType as ResourceType, query));
return [allOk, bundle];
Expand Down
3 changes: 0 additions & 3 deletions packages/fhir-router/src/repo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,9 +363,6 @@ export class MemoryRepository extends BaseRepository implements FhirRepository {

async search<T extends Resource>(searchRequest: SearchRequest<T>): Promise<Bundle<T>> {
const { resourceType } = searchRequest;
if (!this.resources.has(resourceType)) {
throw new Error(`Unknown resource type: ${resourceType}`);
}
const resources = this.resources.get(resourceType) ?? new Map();
const result = [];
for (const resource of resources.values()) {
Expand Down