From affa14f879582039ca78c24133883c7c85a1bc2d Mon Sep 17 00:00:00 2001 From: LaurenD Date: Mon, 2 Dec 2024 09:00:11 -0500 Subject: [PATCH] Disable authoring functionality when using publishable env --- app/src/components/ResourceInfoCard.tsx | 30 ++++++---- app/src/components/SearchComponent.tsx | 2 +- app/src/pages/[resourceType]/[id].tsx | 56 ++++++++++--------- app/src/pages/_app.tsx | 27 +++++---- .../pages/authoring/[resourceType]/[id].tsx | 11 +++- .../pages/authoring/[resourceType]/index.tsx | 11 +++- app/src/pages/authoring/index.tsx | 9 +++ app/src/server/trpc/routers/service.ts | 10 ++++ 8 files changed, 105 insertions(+), 51 deletions(-) diff --git a/app/src/components/ResourceInfoCard.tsx b/app/src/components/ResourceInfoCard.tsx index 2813c6e9..893f99f9 100644 --- a/app/src/components/ResourceInfoCard.tsx +++ b/app/src/components/ResourceInfoCard.tsx @@ -39,6 +39,7 @@ export default function ResourceInfoCard({ resourceInfo, authoring }: ResourceIn const utils = trpc.useUtils(); const [isDeleteConfirmationModalOpen, setIsDeleteConfirmationModalOpen] = useState(false); const [isCloneConfirmationModalOpen, setIsCloneConfirmationModalOpen] = useState(false); + const authoringEnvironment = trpc.service.getAuthoring.useQuery(); const successNotification = (resourceType: string, childArtifact: boolean, action: string, idOrUrl?: string) => { let message; @@ -180,19 +181,24 @@ export default function ResourceInfoCard({ resourceInfo, authoring }: ResourceIn - - - - - - - + {authoringEnvironment.data ? ( + + + + + + + + ) : ( + <> + )} {authoring && + authoringEnvironment && (resourceInfo.isChild ? ( diff --git a/app/src/components/SearchComponent.tsx b/app/src/components/SearchComponent.tsx index fa5f286a..4ff06a7e 100644 --- a/app/src/components/SearchComponent.tsx +++ b/app/src/components/SearchComponent.tsx @@ -115,7 +115,7 @@ export default function SearchComponent({ resourceType }: SearchComponentProps) requestParams.push({ name: 'version', value: version }); } const query = requestParams.filter(si => si.value !== '').map(si => si.name + '=' + si.value); - return query.length !== 0 ? `?${query.join('&')}` : ''; + return query.length !== 0 ? `?status=active&${query.join('&')}` : '?status=active'; }; return ( diff --git a/app/src/pages/[resourceType]/[id].tsx b/app/src/pages/[resourceType]/[id].tsx index 9776dfd3..3898dedf 100644 --- a/app/src/pages/[resourceType]/[id].tsx +++ b/app/src/pages/[resourceType]/[id].tsx @@ -50,6 +50,7 @@ export default function ResourceIDPage({ jsonData }: InferGetServerSidePropsType const ctx = trpc.useContext(); const router = useRouter(); + const authoring = trpc.service.getAuthoring.useQuery(); // Overwrite Prism with our custom Prism that includes CQL as a language useEffect(() => { @@ -150,31 +151,36 @@ export default function ResourceIDPage({ jsonData }: InferGetServerSidePropsType
- - - {jsonData.resourceType}/{jsonData.id} - - {!!jsonData?.extension?.find( - ext => ext.url === 'http://hl7.org/fhir/StructureDefinition/artifact-isOwned' && ext.valueBoolean === true - ) ? ( - - - - - - ) : ( - - )} - + {authoring.data ? ( + + + {jsonData.resourceType}/{jsonData.id} + + {!!jsonData?.extension?.find( + ext => + ext.url === 'http://hl7.org/fhir/StructureDefinition/artifact-isOwned' && ext.valueBoolean === true + ) ? ( + + + + + + ) : ( + + )} + + ) : ( + <> + )}
diff --git a/app/src/pages/_app.tsx b/app/src/pages/_app.tsx index acf0aefb..e3390d57 100644 --- a/app/src/pages/_app.tsx +++ b/app/src/pages/_app.tsx @@ -41,6 +41,7 @@ const useStyles = createStyles(theme => ({ function App({ Component, pageProps }: AppProps) { const router = useRouter(); const { classes } = useStyles(); + const authoring = trpc.service.getAuthoring.useQuery(); return ( <> @@ -139,17 +140,21 @@ function App({ Component, pageProps }: AppProps) { Repository - - - Authoring - - + {authoring.data ? ( + + + Authoring + + + ) : ( + <> + )} } diff --git a/app/src/pages/authoring/[resourceType]/[id].tsx b/app/src/pages/authoring/[resourceType]/[id].tsx index a46813be..4860c0d2 100644 --- a/app/src/pages/authoring/[resourceType]/[id].tsx +++ b/app/src/pages/authoring/[resourceType]/[id].tsx @@ -1,5 +1,5 @@ import { trpc } from '@/util/trpc'; -import { Button, Center, Divider, Grid, Group, Paper, Select, Stack, Text, Tooltip } from '@mantine/core'; +import { Button, Center, Divider, Grid, Group, Paper, Select, Stack, Text, Title, Tooltip } from '@mantine/core'; import { useState, useEffect } from 'react'; import { useRouter } from 'next/router'; import { Prism } from '@mantine/prism'; @@ -100,6 +100,15 @@ export default function ResourceAuthoringPage() { } }, [resource]); + const authoring = trpc.service.getAuthoring.useQuery(); + if (!authoring.data) { + return ( +
+ Authoring Unavailable +
+ ); + } + const resourceUpdate = trpc.draft.updateDraft.useMutation({ onSuccess: () => { notifications.show({ diff --git a/app/src/pages/authoring/[resourceType]/index.tsx b/app/src/pages/authoring/[resourceType]/index.tsx index 267c42a7..91730ce6 100644 --- a/app/src/pages/authoring/[resourceType]/index.tsx +++ b/app/src/pages/authoring/[resourceType]/index.tsx @@ -1,5 +1,5 @@ import { trpc } from '@/util/trpc'; -import { Center, Text, Divider } from '@mantine/core'; +import { Center, Text, Divider, Title } from '@mantine/core'; import { useRouter } from 'next/router'; import { ArtifactResourceType, ResourceInfo } from '@/util/types/fhir'; import ResourceCards from '@/components/ResourceCards'; @@ -16,6 +16,15 @@ export default function ResourceAuthoringPage() { return (artifacts ?? []).map(a => extractResourceInfo(a)); }, [artifacts]); + const authoring = trpc.service.getAuthoring.useQuery(); + if (!authoring.data) { + return ( +
+ Authoring Unavailable +
+ ); + } + return (
diff --git a/app/src/pages/authoring/index.tsx b/app/src/pages/authoring/index.tsx index 4627118a..1607b123 100644 --- a/app/src/pages/authoring/index.tsx +++ b/app/src/pages/authoring/index.tsx @@ -38,6 +38,15 @@ export default function AuthoringPage() { const { classes } = useStyles(); const router = useRouter(); + const authoring = trpc.service.getAuthoring.useQuery(); + if (!authoring.data) { + return ( +
+ Authoring Unavailable +
+ ); + } + const successNotification = ( resourceType: string, createdFromArtifact: boolean, diff --git a/app/src/server/trpc/routers/service.ts b/app/src/server/trpc/routers/service.ts index ed1f0bd7..f2cb426d 100644 --- a/app/src/server/trpc/routers/service.ts +++ b/app/src/server/trpc/routers/service.ts @@ -13,6 +13,16 @@ export const serviceRouter = router({ return process.env.PUBLIC_MRS_SERVER; }), + getAuthoring: publicProcedure.query(async () => { + // get authoring environment based on capability statement + const res = await fetch(`${process.env.MRS_SERVER}/metadata`); + const capabilityStatement = res.status === 200 ? ((await res.json()) as fhir4.CapabilityStatement) : null; + //defaults to publishable if capability statement cannot be resolved + return !!capabilityStatement?.instantiates?.includes( + 'http://hl7.org/fhir/us/cqfmeasures/CapabilityStatement/authoring-measure-repository' + ); + }), + getArtifactCounts: publicProcedure.query(async () => { const [measureBundle, libraryBundle] = await Promise.all([ fetch(`${process.env.MRS_SERVER}/Measure?_summary=count&status=active`),