Skip to content

Commit

Permalink
Disable authoring functionality when using publishable env
Browse files Browse the repository at this point in the history
  • Loading branch information
lmd59 committed Dec 2, 2024
1 parent 602edd0 commit affa14f
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 51 deletions.
30 changes: 18 additions & 12 deletions app/src/components/ResourceInfoCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -180,19 +181,24 @@ export default function ResourceInfoCard({ resourceInfo, authoring }: ResourceIn
</ActionIcon>
</Tooltip>
</Link>
<Link
href={{
pathname: `/review/${resourceInfo.resourceType}/${resourceInfo.id}`,
query: { authoring: `${authoring}` }
}}
>
<Tooltip label={authoring ? 'Review Draft Resource' : 'Review Resource'} openDelay={1000}>
<ActionIcon radius="md" size="md" variant="subtle" color="blue">
<Report size="24" />
</ActionIcon>
</Tooltip>
</Link>
{authoringEnvironment.data ? (
<Link
href={{
pathname: `/review/${resourceInfo.resourceType}/${resourceInfo.id}`,
query: { authoring: `${authoring}` }
}}
>
<Tooltip label={authoring ? 'Review Draft Resource' : 'Review Resource'} openDelay={1000}>
<ActionIcon radius="md" size="md" variant="subtle" color="blue">
<Report size="24" />
</ActionIcon>
</Tooltip>
</Link>
) : (
<></>
)}
{authoring &&
authoringEnvironment &&
(resourceInfo.isChild ? (
<Group>
<Tooltip label={'Child artifacts cannot be directly cloned'}>
Expand Down
2 changes: 1 addition & 1 deletion app/src/components/SearchComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
56 changes: 31 additions & 25 deletions app/src/pages/[resourceType]/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down Expand Up @@ -150,31 +151,36 @@ export default function ResourceIDPage({ jsonData }: InferGetServerSidePropsType
<div>
<Stack spacing="xs">
<div>
<Group position="apart">
<Text size="xl" color="gray">
{jsonData.resourceType}/{jsonData.id}
</Text>
{!!jsonData?.extension?.find(
ext => ext.url === 'http://hl7.org/fhir/StructureDefinition/artifact-isOwned' && ext.valueBoolean === true
) ? (
<Tooltip label="Child artifacts cannot be directly drafted">
<span>
<Button w={240} loading={draftFromArtifactMutation.isLoading} disabled={true}>
Create Draft of {jsonData.resourceType}
</Button>
</span>
</Tooltip>
) : (
<Button
w={240}
loading={draftFromArtifactMutation.isLoading}
onClick={createDraftOfArtifact}
disabled={false}
>
Create Draft of {jsonData.resourceType}
</Button>
)}
</Group>
{authoring.data ? (
<Group position="apart">
<Text size="xl" color="gray">
{jsonData.resourceType}/{jsonData.id}
</Text>
{!!jsonData?.extension?.find(
ext =>
ext.url === 'http://hl7.org/fhir/StructureDefinition/artifact-isOwned' && ext.valueBoolean === true
) ? (
<Tooltip label="Child artifacts cannot be directly drafted">
<span>
<Button w={240} loading={draftFromArtifactMutation.isLoading} disabled={true}>
Create Draft of {jsonData.resourceType}
</Button>
</span>
</Tooltip>
) : (
<Button
w={240}
loading={draftFromArtifactMutation.isLoading}
onClick={createDraftOfArtifact}
disabled={false}
>
Create Draft of {jsonData.resourceType}
</Button>
)}
</Group>
) : (
<></>
)}
</div>
<Divider my="sm" pb={6} />
<Tabs variant="outline" defaultValue="json" value={activeTab} onTabChange={setActiveTab}>
Expand Down
27 changes: 16 additions & 11 deletions app/src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<>
Expand Down Expand Up @@ -139,17 +140,21 @@ function App({ Component, pageProps }: AppProps) {
Repository
</Text>
</Link>
<Link href="/authoring">
<Text
c={
router.asPath.endsWith(`authoring=true`) || router.pathname.startsWith('/authoring')
? 'orange.3'
: 'gray.4'
}
>
Authoring
</Text>
</Link>
{authoring.data ? (
<Link href="/authoring">
<Text
c={
router.asPath.endsWith(`authoring=true`) || router.pathname.startsWith('/authoring')
? 'orange.3'
: 'gray.4'
}
>
Authoring
</Text>
</Link>
) : (
<> </>
)}
</Group>
</Header>
}
Expand Down
11 changes: 10 additions & 1 deletion app/src/pages/authoring/[resourceType]/[id].tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -100,6 +100,15 @@ export default function ResourceAuthoringPage() {
}
}, [resource]);

const authoring = trpc.service.getAuthoring.useQuery();
if (!authoring.data) {
return (
<Center>
<Title> Authoring Unavailable </Title>
</Center>
);
}

const resourceUpdate = trpc.draft.updateDraft.useMutation({
onSuccess: () => {
notifications.show({
Expand Down
11 changes: 10 additions & 1 deletion app/src/pages/authoring/[resourceType]/index.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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 (
<Center>
<Title> Authoring Unavailable </Title>
</Center>
);
}

return (
<div>
<Center>
Expand Down
9 changes: 9 additions & 0 deletions app/src/pages/authoring/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ export default function AuthoringPage() {
const { classes } = useStyles();
const router = useRouter();

const authoring = trpc.service.getAuthoring.useQuery();
if (!authoring.data) {
return (
<Center>
<Title> Authoring Unavailable </Title>
</Center>
);
}

const successNotification = (
resourceType: string,
createdFromArtifact: boolean,
Expand Down
10 changes: 10 additions & 0 deletions app/src/server/trpc/routers/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`),
Expand Down

0 comments on commit affa14f

Please sign in to comment.