-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce Capturing of drugs as observations
- Loading branch information
Showing
9 changed files
with
105 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { openmrsFetch } from '@openmrs/esm-framework'; | ||
import { BaseOpenMRSDataSource } from './data-source'; | ||
|
||
export class ConceptDataSource extends BaseOpenMRSDataSource { | ||
constructor() { | ||
super('/ws/rest/v1/concept?name=&searchType=fuzzy&v=custom:(uuid,display)'); | ||
} | ||
|
||
fetchData(searchTerm: string, config?: Record<string, any>): Promise<any[]> { | ||
if (config?.class) { | ||
let urlParts = this.url.split('name='); | ||
this.url = `${urlParts[0]}&name=&class=${config.class}&${urlParts[1]}`; | ||
} | ||
return openmrsFetch(searchTerm ? `${this.url}&q=${searchTerm}` : this.url).then(({ data }) => { | ||
return data.results; | ||
}); | ||
} | ||
} |
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,22 @@ | ||
import { useEffect, useState } from 'react'; | ||
import { getControlTemplate } from '../registry/inbuilt-components/control-templates'; | ||
import { OHRIFormField } from '../api/types'; | ||
import { useTranslation } from 'react-i18next'; | ||
|
||
export function useDataSourceConfig(field: OHRIFormField) { | ||
const [config, setConfig] = useState({}); | ||
const { t } = useTranslation(); | ||
|
||
useEffect(() => { | ||
if (field.questionOptions.datasource?.name) { | ||
setConfig(field.questionOptions.datasource.config); | ||
} else { | ||
const template = getControlTemplate(field.questionOptions.rendering); | ||
setConfig(template.datasource.config); | ||
} | ||
}, [field]); | ||
|
||
return { | ||
config, | ||
}; | ||
} |
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,18 @@ | ||
import UISelectExtended from '../../components/inputs/ui-select-extended/ui-select-extended'; | ||
|
||
export const controlTemplates = [ | ||
{ | ||
name: 'drug', | ||
baseControlComponent: UISelectExtended, | ||
datasource: { | ||
name: 'drug_datasource', | ||
config: { | ||
class: '8d490dfc-c2cc-11de-8d13-0010c6dffd0f', | ||
}, | ||
}, | ||
}, | ||
]; | ||
|
||
export const getControlTemplate = (name: string) => { | ||
return controlTemplates.find(template => template.name === name); | ||
}; |
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