-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #879 from aehrc/feature/extract
Feature/extract
- Loading branch information
Showing
53 changed files
with
2,137 additions
and
71 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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
69 changes: 69 additions & 0 deletions
69
apps/smart-forms-app/src/features/playground/api/extract.ts
This file contains 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,69 @@ | ||
/* | ||
* Copyright 2024 Commonwealth Scientific and Industrial Research | ||
* Organisation (CSIRO) ABN 41 687 119 230. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { HEADERS } from '../../../api/headers.ts'; | ||
import type { Bundle, Questionnaire, StructureMap } from 'fhir/r4'; | ||
import * as FHIR from 'fhirclient'; | ||
import { FORMS_SERVER_URL } from '../../../globals.ts'; | ||
|
||
export async function fetchTargetStructureMap( | ||
questionnaire: Questionnaire | ||
): Promise<StructureMap | null> { | ||
let targetStructureMapCanonical = questionnaire.extension?.find( | ||
(extension) => | ||
extension.url === | ||
'http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-targetStructureMap' | ||
)?.valueCanonical; | ||
|
||
if (!targetStructureMapCanonical) { | ||
return null; | ||
} | ||
|
||
targetStructureMapCanonical = targetStructureMapCanonical.replace('|', '&version='); | ||
const requestUrl = `/StructureMap?url=${targetStructureMapCanonical}&_sort=_lastUpdated`; | ||
const resource = await FHIR.client(FORMS_SERVER_URL).request({ | ||
url: requestUrl, | ||
headers: HEADERS | ||
}); | ||
|
||
// Response isn't a resource, exit early | ||
if (!resource.resourceType) { | ||
return null; | ||
} | ||
|
||
if (resource.resourceType === 'Bundle') { | ||
return resource.entry?.find((entry: any) => entry.resource?.resourceType === 'StructureMap') | ||
?.resource as StructureMap; | ||
} | ||
|
||
if (resource.resourceType === 'StructureMap') { | ||
return resource as StructureMap; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
export function extractedResourceIsBatchBundle( | ||
extractedResource: any | ||
): extractedResource is Bundle { | ||
return ( | ||
!!extractedResource && | ||
!!extractedResource.resourceType && | ||
extractedResource.resourceType === 'Bundle' && | ||
(extractedResource.type === 'transaction' || extractedResource.type === 'batch') | ||
); | ||
} |
67 changes: 67 additions & 0 deletions
67
apps/smart-forms-app/src/features/playground/components/ExtractButtonForPlayground.tsx
This file contains 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,67 @@ | ||
/* | ||
* Copyright 2024 Commonwealth Scientific and Industrial Research | ||
* Organisation (CSIRO) ABN 41 687 119 230. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
// @ts-ignore | ||
import React from 'react'; | ||
import { CircularProgress, Fade, IconButton, Tooltip } from '@mui/material'; | ||
import Typography from '@mui/material/Typography'; | ||
import CloudUploadIcon from '@mui/icons-material/CloudUpload'; | ||
import { FORMS_SERVER_URL } from '../../../globals.ts'; | ||
|
||
interface ExtractForPlaygroundProps { | ||
extractEnabled: boolean; | ||
isExtracting: boolean; | ||
onExtract: () => void; | ||
} | ||
|
||
function ExtractButtonForPlayground(props: ExtractForPlaygroundProps) { | ||
const { extractEnabled, isExtracting, onExtract } = props; | ||
|
||
const toolTipText = extractEnabled | ||
? 'Perform $extract' | ||
: `The current questionnaire does not have a target StructureMap for $extract, or the target StructureMap cannot be found on ${FORMS_SERVER_URL}`; | ||
|
||
return ( | ||
<> | ||
<Tooltip title={toolTipText} placement="bottom-end"> | ||
<span> | ||
<IconButton | ||
disabled={isExtracting || !extractEnabled} | ||
onClick={onExtract} | ||
size="small" | ||
color="primary" | ||
data-test="extract-button-playground"> | ||
{isExtracting ? ( | ||
<CircularProgress size={20} color="inherit" sx={{ mb: 0.5 }} /> | ||
) : ( | ||
<CloudUploadIcon /> | ||
)} | ||
</IconButton> | ||
</span> | ||
</Tooltip> | ||
{isExtracting ? ( | ||
<Fade in={true} timeout={100}> | ||
<Typography variant="body2" color="text.secondary"> | ||
Performing extraction... | ||
</Typography> | ||
</Fade> | ||
) : null} | ||
</> | ||
); | ||
} | ||
|
||
export default ExtractButtonForPlayground; |
This file contains 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
Oops, something went wrong.