Skip to content

Commit

Permalink
OHRI-1839 Support for rendering problem by concept class (#125)
Browse files Browse the repository at this point in the history
* add support for rendering a problem by concept class

* refactor concept datasource
  • Loading branch information
kajambiya authored Oct 6, 2023
1 parent 3b490ee commit 9b46355
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 4 deletions.
10 changes: 10 additions & 0 deletions src/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,3 +259,13 @@ export interface DataSource<T> {
*/
toUuidAndDisplay(item: T): OpenmrsResource;
}

export interface ControlTemplate {
name: string;
datasource: DataSourceParameters;
}

export interface DataSourceParameters {
name: string;
config?: Record<string, any>;
}
14 changes: 11 additions & 3 deletions src/datasources/concept-data-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,21 @@ import { BaseOpenMRSDataSource } from './data-source';

export class ConceptDataSource extends BaseOpenMRSDataSource {
constructor() {
super('/ws/rest/v1/concept?name=&searchType=fuzzy&v=custom:(uuid,display)');
super('/ws/rest/v1/concept?name=&searchType=fuzzy&v=custom:(uuid,display,conceptClass:(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]}`;
if (typeof config.class == 'string') {
let urlParts = this.url.split('name=');
this.url = `${urlParts[0]}&name=&class=${config.class}&${urlParts[1]}`;
} else {
return openmrsFetch(searchTerm ? `${this.url}&q=${searchTerm}` : this.url).then(({ data }) => {
return data.results.filter(
concept => concept.conceptClass && config.class.includes(concept.conceptClass.uuid),
);
});
}
}
return openmrsFetch(searchTerm ? `${this.url}&q=${searchTerm}` : this.url).then(({ data }) => {
return data.results;
Expand Down
13 changes: 12 additions & 1 deletion src/registry/inbuilt-components/control-templates.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export const controlTemplates = [
import { ControlTemplate } from '../../api/types';

export const controlTemplates: Array<ControlTemplate> = [
{
name: 'drug',
datasource: {
Expand All @@ -8,6 +10,15 @@ export const controlTemplates = [
},
},
},
{
name: 'problem',
datasource: {
name: 'problem_datasource',
config: {
class: ['8d4918b0-c2cc-11de-8d13-0010c6dffd0f', '8d492954-c2cc-11de-8d13-0010c6dffd0f'],
},
},
},
];

export const getControlTemplate = (name: string) => {
Expand Down
4 changes: 4 additions & 0 deletions src/registry/inbuilt-components/inbuiltDataSources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ export const inbuiltDataSources: Array<RegistryItem<DataSource<any>>> = [
name: 'drug_datasource',
component: new ConceptDataSource(),
},
{
name: 'problem_datasource',
component: new ConceptDataSource(),
},
];

export const validateInbuiltDatasource = (name: string) => {
Expand Down
4 changes: 4 additions & 0 deletions src/registry/inbuilt-components/template-component-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@ export const templateToComponentMap = [
name: 'drug',
baseControlComponent: UISelectExtended,
},
{
name: 'problem',
baseControlComponent: UISelectExtended,
}
];

0 comments on commit 9b46355

Please sign in to comment.