-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into detail-page
- Loading branch information
Showing
38 changed files
with
574 additions
and
240 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
21 changes: 21 additions & 0 deletions
21
src/components/BaseQuestionnaireResponseForm/readonly-widgets/MarkdownRender/index.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,21 @@ | ||
import classNames from 'classnames'; | ||
import Markdown from 'react-markdown'; | ||
import { QuestionItemProps } from 'sdc-qrf'; | ||
|
||
import { useFieldController } from 'src/components/BaseQuestionnaireResponseForm/hooks'; | ||
|
||
import s from '../ReadonlyWidgets.module.scss'; | ||
import { S } from '../ReadonlyWidgets.styles'; | ||
|
||
export function MarkdownRenderControl({ parentPath, questionItem }: QuestionItemProps) { | ||
const { linkId, text } = questionItem; | ||
const fieldName = [...parentPath, linkId, 0, 'value', 'string']; | ||
const { value } = useFieldController(fieldName, questionItem); | ||
|
||
return ( | ||
<S.Question className={classNames(s.question, s.column, 'form__question')}> | ||
<span className={s.questionText}>{text}</span> | ||
<Markdown>{value || '-'}</Markdown> | ||
</S.Question> | ||
); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { Provenance } from 'fhir/r4b'; | ||
import { describe } from 'vitest'; | ||
|
||
import { getLinkToEditUrl } from 'src/components/LinkToEdit/utils'; | ||
|
||
describe('getSourceFromProvenance', () => { | ||
test('getSourceFromProvenance for empty Provenance', () => { | ||
const provenance = {} as Provenance; | ||
const pathname = '/patients/patient1/resources'; | ||
|
||
expect(getLinkToEditUrl({ provenance, pathname })).toBeUndefined(); | ||
}); | ||
|
||
test('getSourceFromProvenance for undefined Provenance', () => { | ||
expect(getLinkToEditUrl({})).toBeUndefined(); | ||
}); | ||
|
||
test('getSourceFromProvenance for Provenance with source reference', () => { | ||
const provenance: Provenance = { | ||
resourceType: 'Provenance', | ||
entity: [ | ||
{ | ||
role: 'source', | ||
what: { | ||
reference: 'QuestionnaireResponse/getme', | ||
}, | ||
}, | ||
], | ||
agent: [ | ||
{ | ||
who: {}, | ||
}, | ||
], | ||
target: [{}], | ||
recorded: '', | ||
}; | ||
const pathname = '/patients/patient1/resources'; | ||
|
||
expect(getLinkToEditUrl({ provenance, pathname })).toEqual('/patients/patient1/documents/getme'); | ||
}); | ||
|
||
test('getSourceFromProvenance for Provenance with source reference and custom to', () => { | ||
const provenance: Provenance = { | ||
resourceType: 'Provenance', | ||
entity: [ | ||
{ | ||
role: 'source', | ||
what: { | ||
reference: 'QuestionnaireResponse/getme', | ||
}, | ||
}, | ||
], | ||
agent: [ | ||
{ | ||
who: {}, | ||
}, | ||
], | ||
target: [{}], | ||
recorded: '', | ||
}; | ||
const pathname = '/patients/patient1/resources'; | ||
const to = '/custom'; | ||
|
||
expect(getLinkToEditUrl({ provenance, pathname, to })).toEqual('/custom/getme'); | ||
}); | ||
}); |
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,11 @@ | ||
import { createContext } from 'react'; | ||
|
||
import { getLinkToEditUrl, GetLinkToEditUrlProps } from 'src/components/LinkToEdit/utils'; | ||
|
||
export type LinkToEditContextType = { | ||
getLinkToEditUrl: (props: GetLinkToEditUrlProps) => string | undefined; | ||
}; | ||
|
||
export const LinkToEditContext = createContext<LinkToEditContextType>({ | ||
getLinkToEditUrl, | ||
}); |
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,38 @@ | ||
import { Resource, Provenance } from 'fhir/r4b'; | ||
import { useContext } from 'react'; | ||
import { Link, useLocation } from 'react-router-dom'; | ||
import { fromFHIRReference } from 'sdc-qrf'; | ||
|
||
import { LinkToEditContext } from 'src/components/LinkToEdit/context'; | ||
|
||
interface LinkToEditProps { | ||
name?: string; | ||
resource: Resource; | ||
provenanceList: Provenance[]; | ||
to?: string; | ||
} | ||
|
||
export function LinkToEdit(props: LinkToEditProps) { | ||
const { name, resource, provenanceList, to } = props; | ||
|
||
const location = useLocation(); | ||
const provenance = provenanceList | ||
.filter((provenance) => | ||
provenance.target.find( | ||
(target) => | ||
fromFHIRReference(target)?.id === resource.id && | ||
fromFHIRReference(target)?.resourceType === resource.resourceType, | ||
), | ||
) | ||
.sort((a, b) => new Date(b.recorded).getTime() - new Date(a.recorded).getTime())[0]; | ||
|
||
const { getLinkToEditUrl } = useContext(LinkToEditContext); | ||
|
||
const customPathTo = getLinkToEditUrl({ provenance, pathname: location.pathname, to }); | ||
|
||
if (!customPathTo) { | ||
return <>{name}</>; | ||
} | ||
|
||
return <Link to={`${customPathTo}`}>{name}</Link>; | ||
} |
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,30 @@ | ||
import { Provenance } from 'fhir/r4b'; | ||
import { fromFHIRReference } from 'sdc-qrf'; | ||
|
||
export type GetLinkToEditUrlProps = { | ||
provenance?: Provenance; | ||
pathname?: string; | ||
to?: string; | ||
}; | ||
|
||
export function getLinkToEditUrl(props: GetLinkToEditUrlProps): string | undefined { | ||
const { provenance, pathname, to } = props; | ||
|
||
const entity = provenance?.entity?.[0]?.what; | ||
const qrId = fromFHIRReference(entity)?.id; | ||
const baseUrl = pathname?.split('/').slice(0, 3).join('/'); | ||
|
||
if (!qrId) { | ||
return undefined; | ||
} | ||
|
||
if (to) { | ||
return `${to}/${qrId}`; | ||
} | ||
|
||
if (!baseUrl) { | ||
return undefined; | ||
} | ||
|
||
return `${baseUrl}/documents/${qrId}`; | ||
} |
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
Oops, something went wrong.