Skip to content

Commit

Permalink
Clean comments, errors, and imports
Browse files Browse the repository at this point in the history
  • Loading branch information
lmd59 committed Oct 7, 2024
1 parent 5e69f96 commit 7e1f078
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
14 changes: 7 additions & 7 deletions app/src/server/trpc/routers/draft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import { Bundle, OperationOutcome } from 'fhir/r4';
import { calculateVersion } from '@/util/versionUtils';

/**
* Endpoints dealing with outgoing calls to the central measure repository service to handle draft measures
* Endpoints dealing with outgoing calls to the central measure repository service to handle draft artifacts
*/
export const draftRouter = router({
getDraftCounts: publicProcedure.query(async () => {
const [measureBundle, libraryBundle] = await Promise.all([
fetch(`${process.env.MRS_SERVER}/Measure?_summary=count&status=draft`),
fetch(`${process.env.MRS_SERVER}/Library?_summary=count&status=draft`)
]).then(([resMeasure, resLibrary]) =>
Promise.all([resMeasure.json() as Promise<fhir4.Bundle>, resLibrary.json() as Promise<fhir4.Bundle>])
Promise.all([resMeasure.json() as Promise<Bundle>, resLibrary.json() as Promise<Bundle>])
);

return {
Expand All @@ -25,7 +25,7 @@ export const draftRouter = router({
getDrafts: publicProcedure.input(z.enum(['Measure', 'Library']).optional()).query(async ({ input }) => {
if (!input) return null;
const artifactBundle = await fetch(`${process.env.MRS_SERVER}/${input}?status=draft`).then(
resArtifacts => resArtifacts.json() as Promise<fhir4.Bundle<FhirArtifact>>
resArtifacts => resArtifacts.json() as Promise<Bundle<FhirArtifact>>
);
const artifactList = artifactBundle.entry
?.filter(entry => entry.resource)
Expand Down Expand Up @@ -57,7 +57,7 @@ export const draftRouter = router({
return { draftId: res.headers.get('Location')?.split('/')[2] as string };
}
const outcome: OperationOutcome = await res.json();
throw new Error(`Received ${res.status} error on create: ${outcome.issue[0].details?.text}`);
throw new Error(`Received ${res.status} error on create: ${outcome.issue[0].details?.text}`);
}),

updateDraft: publicProcedure
Expand Down Expand Up @@ -85,7 +85,7 @@ export const draftRouter = router({
return {};
}
const outcome: OperationOutcome = await res.json();
throw new Error(`Received ${res.status} error on update: ${outcome.issue[0].details?.text}`);
throw new Error(`Received ${res.status} error on update: ${outcome.issue[0].details?.text}`);
}),

deleteDraft: publicProcedure
Expand Down Expand Up @@ -115,7 +115,7 @@ export const draftRouter = router({
return resData;
}
const outcome: OperationOutcome = await res.json();
throw new Error(`Received ${res.status} error on delete: ${outcome.issue[0].details?.text}`);
throw new Error(`Received ${res.status} error on delete: ${outcome.issue[0].details?.text}`);
}),

cloneParent: publicProcedure
Expand All @@ -131,7 +131,7 @@ export const draftRouter = router({

if (res.status !== 200) {
const outcome: OperationOutcome = await res.json();
throw new Error(`Received ${res.status} error on $clone: ${outcome.issue[0].details?.text}`);
throw new Error(`Received ${res.status} error on $clone: ${outcome.issue[0].details?.text}`);
}

const resBundle: Bundle<FhirArtifact> = await res.json();
Expand Down
8 changes: 4 additions & 4 deletions app/src/server/trpc/routers/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Bundle, OperationOutcome } from 'fhir/r4';
import { calculateVersion } from '@/util/versionUtils';

/**
* Endpoints dealing with outgoing calls to the central measure repository service to handle active measures
* Endpoints dealing with outgoing calls to the central measure repository service to handle active artifacts
*/
export const serviceRouter = router({
getPublicUrl: publicProcedure.query(async () => {
Expand All @@ -18,7 +18,7 @@ export const serviceRouter = router({
fetch(`${process.env.MRS_SERVER}/Measure?_summary=count&status=active`),
fetch(`${process.env.MRS_SERVER}/Library?_summary=count&status=active`)
]).then(([resMeasure, resLibrary]) =>
Promise.all([resMeasure.json() as Promise<fhir4.Bundle>, resLibrary.json() as Promise<fhir4.Bundle>])
Promise.all([resMeasure.json() as Promise<Bundle>, resLibrary.json() as Promise<Bundle>])
);

return {
Expand All @@ -32,7 +32,7 @@ export const serviceRouter = router({
.query(async ({ input }) => {
const artifactBundle = await fetch(
`${process.env.MRS_SERVER}/${input.resourceType}?_elements=id,name,extension,version&status=active`
).then(resArtifacts => resArtifacts.json() as Promise<fhir4.Bundle<FhirArtifact>>);
).then(resArtifacts => resArtifacts.json() as Promise<Bundle<FhirArtifact>>);
const artifactList = artifactBundle.entry?.map(entry => ({
label:
entry.resource?.name?.concat(`|${entry.resource.version}`) ||
Expand Down Expand Up @@ -80,7 +80,7 @@ export const serviceRouter = router({

if (res.status !== 200) {
const outcome: OperationOutcome = await res.json();
throw new Error(`Received ${res.status} error on $draft: ${outcome.issue[0].details?.text}`);
throw new Error(`Received ${res.status} error on $draft: ${outcome.issue[0].details?.text}`);
}

const resBundle: Bundle<FhirArtifact> = await res.json();
Expand Down
6 changes: 4 additions & 2 deletions app/src/util/versionUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,10 @@ function checkVersionFormat(version: string): boolean {
return format.test(version);
}

// a function to check if the given url/version/resourceType exists on the server
// in order to decide whether to increment the version further
/**
* A function to check if the given url/version/resourceType exists on the server
* in order to decide whether to increment the version further
*/
async function getResourceByUrl(url: string, version: string, resourceType: string) {
const res = await fetch(`${process.env.MRS_SERVER}/${resourceType}?url=${url}&version=${version}`);
const bundle: Bundle<FhirArtifact> = await res.json();
Expand Down

0 comments on commit 7e1f078

Please sign in to comment.