-
Notifications
You must be signed in to change notification settings - Fork 3
Evaluation verifier #109
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
Merged
Merged
Evaluation verifier #109
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
123 changes: 123 additions & 0 deletions
123
components/measure-upload/EvaluationServiceVerifier.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| import { Alert, Button, Group, Space, TextInput } from '@mantine/core'; | ||
| import React, { useEffect, useState } from 'react'; | ||
| import { useRecoilState, useRecoilValue } from 'recoil'; | ||
| import { evaluationState } from '../../state/atoms/evaluation'; | ||
| import { measureBundleState } from '../../state/atoms/measureBundle'; | ||
| import { showNotification } from '@mantine/notifications'; | ||
| import { IconAlertCircle, IconCircleCheck } from '@tabler/icons'; | ||
|
|
||
| export default function EvaluationServiceVerifier() { | ||
| const [isLoadingId, setIsLoadingId] = useState(false); | ||
| const { content } = useRecoilValue(measureBundleState); | ||
| const [{ evaluationServiceUrl, evaluationMeasureId }, setEvaluation] = useRecoilState(evaluationState); | ||
|
|
||
| useEffect(() => { | ||
| // Called when the measure content value changes | ||
| setEvaluation(e => ({ | ||
| ...e, | ||
| evaluationMeasureId: '' | ||
| })); | ||
| }, [content, setEvaluation]); | ||
|
|
||
| /** | ||
| * Handles updating of the Evaluation Service url field and associated state variables | ||
| */ | ||
| function handleUrlChange(event: React.ChangeEvent<HTMLInputElement>) { | ||
| setEvaluation({ | ||
| evaluationServiceUrl: event.currentTarget.value, | ||
| evaluationMeasureId: '' | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Sends a `GET` request to the `/Measure` endpoint of the specified evaluation service URL. | ||
| * Parses and stores the url and the id of the matching (same url/version) Measure if successful | ||
| */ | ||
| async function verifyMeasure() { | ||
| setIsLoadingId(true); | ||
| let parsedEvaluationUrl = evaluationServiceUrl; | ||
| if (evaluationServiceUrl.slice(-1) === '/') { | ||
| parsedEvaluationUrl = evaluationServiceUrl.slice(0, -1); | ||
| } | ||
| try { | ||
| const response = await fetch(`${parsedEvaluationUrl}/Measure`); | ||
| const responseBody = await response.json(); | ||
| if (response.status === 200) { | ||
| if (responseBody.entry.length === 0) { | ||
| showNotification({ | ||
| icon: <IconAlertCircle />, | ||
| title: 'No measures found', | ||
| message: `Evalution service hosted at ${parsedEvaluationUrl} returned an empty | ||
| FHIR Bundle when queried for Measures. Ensure Measures are present on server.`, | ||
| color: 'red' | ||
| }); | ||
| setIsLoadingId(false); | ||
| return; | ||
| } | ||
| const selectedMeasure = content?.entry?.find(e => e.resource?.resourceType === 'Measure') | ||
| ?.resource as fhir4.Measure; | ||
| // Currently taking the safe path and not assuming support for search -> finding the correct measure from a pull of all measures | ||
| const currentEvalMeasure = responseBody.entry.find( | ||
| (e: { resource: fhir4.Measure }) => | ||
| e.resource.url === selectedMeasure.url && e.resource.version === selectedMeasure.version | ||
| )?.resource; | ||
| if (!currentEvalMeasure) { | ||
| showNotification({ | ||
| icon: <IconAlertCircle />, | ||
| title: 'Failed to locate measure', | ||
| message: `Could not find measure with url ${selectedMeasure.url} and version ${selectedMeasure.version} on the selected evaluation service.`, | ||
| color: 'red' | ||
| }); | ||
| setIsLoadingId(false); | ||
| return; | ||
| } | ||
|
|
||
| setEvaluation({ evaluationServiceUrl: parsedEvaluationUrl, evaluationMeasureId: currentEvalMeasure.id }); | ||
| } else { | ||
| showNotification({ | ||
| icon: <IconAlertCircle />, | ||
| title: 'Failed reaching out to server', | ||
| message: `Server responded with code: ${response.status}:${response.statusText}`, | ||
| color: 'red' | ||
| }); | ||
| } | ||
| } catch (e) { | ||
|
zacharyrobin marked this conversation as resolved.
|
||
| showNotification({ | ||
| icon: <IconAlertCircle />, | ||
| title: 'Failed reaching out to server', | ||
| message: `Could not connect to server with url: ${parsedEvaluationUrl}`, | ||
| color: 'red' | ||
| }); | ||
| } | ||
| setIsLoadingId(false); | ||
| } | ||
|
|
||
| return ( | ||
| <div> | ||
| <Group position="apart" align="flex-end"> | ||
| <TextInput | ||
| label="Evaluation Service URL" | ||
| placeholder="http://example.com/fhir" | ||
| value={evaluationServiceUrl} | ||
| onChange={handleUrlChange} | ||
| style={{ flexGrow: 1 }} | ||
| /> | ||
| <Button | ||
| onClick={verifyMeasure} | ||
| loading={isLoadingId} | ||
| disabled={evaluationServiceUrl === '' || content === null} | ||
| > | ||
| Verify | ||
| </Button> | ||
| </Group> | ||
| <Space h="md" /> | ||
| {evaluationMeasureId !== '' && ( | ||
| <Group position="center" align="flex-end"> | ||
| <Alert variant="light" color="green" icon={<IconCircleCheck />}> | ||
| Located Measure ID: {evaluationMeasureId} | ||
| </Alert> | ||
| </Group> | ||
| )} | ||
| </div> | ||
| ); | ||
| } | ||
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import { atom } from 'recoil'; | ||
|
|
||
| interface EvaluationStateType { | ||
| evaluationServiceUrl: string; | ||
| evaluationMeasureId: string; | ||
| } | ||
|
|
||
| /** | ||
| * Atom tracking and controlling values for the evaluation service | ||
| */ | ||
| export const evaluationState = atom<EvaluationStateType>({ | ||
| key: 'evaluationState', | ||
| default: { | ||
| evaluationServiceUrl: '', | ||
| evaluationMeasureId: '' | ||
| } | ||
| }); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.