Skip to content

Commit

Permalink
Introduce Drug control
Browse files Browse the repository at this point in the history
  • Loading branch information
kajambiya committed Jul 31, 2023
1 parent ae36707 commit 6eebef1
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
12 changes: 12 additions & 0 deletions src/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,3 +254,15 @@ export interface DataSource<T> {
*/
toUuidAndDisplay(item: T): OpenmrsResource;
}

export interface Drug {
uuid: string;
display: string;
name: string;
retired?: boolean;
concept?: {
uuid: string;
display: string;
links: any[];
};
}
19 changes: 19 additions & 0 deletions src/datasources/drug-data-source.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { openmrsFetch, OpenmrsResource } from '@openmrs/esm-framework';
import { DataSource, Drug } from '../api/types';

export class DrugDataSource implements DataSource<Drug> {
private readonly url = '/ws/rest/v1/drug?v=custom:(uuid,display)';

fetchData(searchTerm: string): Promise<Drug[]> {
return openmrsFetch(searchTerm ? `${this.url}&q=${searchTerm}` : this.url).then(({ data }) => {
return data.results;
});
}

toUuidAndDisplay(drug: any): OpenmrsResource {
return {
uuid: drug.uuid,
display: drug.display,
};
}
}
9 changes: 7 additions & 2 deletions src/registry/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { OHRIFormsStore } from '../constants';
import OHRIExtensionParcel from '../components/extension/ohri-extension-parcel.component';
import { EncounterDatetimeHandler } from '../submission-handlers/encounterDatetimeHandler';
import { UISelectExtended } from '../components/inputs/ui-select-extended/ui-select-extended';

import { DrugDataSource } from '../datasources/drug-data-source';
export interface RegistryItem {
id: string;
component: any;
Expand Down Expand Up @@ -198,7 +198,12 @@ const fieldValidators: Array<ValidatorRegistryItem> = [
},
];

const dataSources: Array<DataSourceRegistryItem> = [];
const dataSources: Array<DataSourceRegistryItem> = [
{
id: 'drug',
component: new DrugDataSource(),
},
];

export const getFieldComponent = renderType => {
let lazy = baseFieldComponents.find(item => item.type == renderType || item?.alias == renderType)?.loadControl;
Expand Down

0 comments on commit 6eebef1

Please sign in to comment.