Skip to content

Commit

Permalink
Use configurable profiles for registries (#8)
Browse files Browse the repository at this point in the history
Use configurable profiles for registries
  • Loading branch information
akileng56 authored Aug 5, 2024
1 parent 5eba817 commit 2b8413c
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 32 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"packages/*"
],
"scripts": {
"start": "openmrs develop --sources 'packages/esm-*-app'",
"start": "openmrs develop",
"ci:publish": "lerna publish from-package --yes",
"ci:prepublish": "lerna publish from-package --no-git-reset --yes --dist-tag next",
"release": "lerna version --no-git-tag-version",
Expand Down
1 change: 0 additions & 1 deletion packages/esm-patient-registration-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"lint": "cross-env TIMING=1 eslint src --ext ts,tsx",
"test:watch": "cross-env TZ=UTC jest --watch --config jest.config.js --color",
"coverage": "yarn test --coverage",
"typescript": "tsc",
"extract-translations": "i18next 'src/**/*.component.tsx'"
},
"browserslist": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ import { FetchResponse, openmrsFetch, showNotification, showToast, showModal } f
import { generateFHIRPayload } from './patient-verification-utils';
import useSWR from 'swr';
import { ConceptAnswers, ConceptResponse, FormValues } from '../patient-registration/patient-registration.types';
import { patientRegistries } from './verification-constants';
// import { patientRegistries } from './verification-constants';

export const searchRegistry = async (searchParams, advancedSearchParams) => {
const { registry, identifier } = searchParams;
const { firstName, familyName, otherName } = advancedSearchParams;
let enteredFields = [];
let urlParams = '';

let selectedRegistry = patientRegistries.filter((r) => r.name === registry);
if (selectedRegistry.length) {
// let selectedRegistry = patientRegistries.filter((r) => r.name === registry);
if (registry) {
if (identifier) {
urlParams = `?identifier=${identifier.toUpperCase()}`;
} else {
Expand All @@ -28,7 +28,7 @@ export const searchRegistry = async (searchParams, advancedSearchParams) => {
}
urlParams = urlParams + '&_tag:not=5c827da5-4858-4f3d-a50c-62ece001efea';

const query = `${selectedRegistry[0].url}/fhir/Patient` + urlParams;
const query = `${registry}` + urlParams;
try {
let res = await fetch(query);
return await res.json();
Expand All @@ -55,9 +55,8 @@ export function useConceptAnswers(conceptUuid: string): { data: Array<ConceptAns

export function savePatientToRegistry(formValues: FormValues, registry) {
const createdRegistryPatient = generateFHIRPayload(formValues);
let selectedRegistry = patientRegistries.filter((r) => r.name === registry);
if (selectedRegistry.length) {
return fetch(`${selectedRegistry[0].url}/fhir`, {
if (registry) {
return fetch(`${registry}`, {
headers: { Accept: 'application/json', 'Content-Type': 'application/json' },
method: 'POST',
body: JSON.stringify(createdRegistryPatient),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,39 @@
export const patientRegistries = [
{
uuid: '84242661-aadf-42e4-9431-bf8afefb4433',
id: 1,
name: 'Client Registry (CR)',
url: 'http://165.232.114.52:8085/hapi-fhir-jpaserver',
},
{
uuid: '',
id: 2,
name: 'Shared Health Record (SHR)',
url: 'http://165.227.170.84:9091',
},
{
uuid: '',
id: 3,
name: 'Cross Border Registry (CBR)',
url: 'http://ea-shr-url',
},
];
import useSWR from 'swr';
import { openmrsFetch, restBaseUrl } from '@openmrs/esm-framework';

declare type fhirProfile = {
uuid: string;
name: string;
url: string;
profileEnabled: boolean;
profileSearchable: boolean;
};

export function useGetPatientRegistries() {
const apiUrl = `${restBaseUrl}/syncfhirprofile`;
const { data, error, isLoading } = useSWR<{ data: { results: any } }, Error>(apiUrl, openmrsFetch);
return {
patientRegistries: data ? mapDataElements(data?.data['results']) : [],
isError: error,
isLoadingFhirProfiles: isLoading,
};
}

export function mapDataElements(dataArray: Array<Record<string, string>>) {
const arrayToReturn: Array<fhirProfile> = [];
if (dataArray) {
dataArray.map((profile: Record<string, any>) => {
if (profile?.profileEnabled && profile?.searchable) {
arrayToReturn.push({
name: profile?.name,
uuid: profile?.uuid,
url: profile?.searchURL,
profileEnabled: profile?.profileEnabled,
profileSearchable: profile?.searchable,
});
}
});
}

return arrayToReturn;
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { useTranslation } from 'react-i18next';
import { Select, SelectItem } from '@carbon/react';
import { patientRegistries } from '../../verification-constants';
import { useGetPatientRegistries } from '../../verification-constants';
import styles from '../../patient-verification.scss';

const RegistrySelect = ({ values, setValues }) => {
Expand All @@ -22,8 +22,8 @@ const RegistrySelect = ({ values, setValues }) => {
<SelectItem key={'registry'} text={'Select Registry'} value={''}>
{' '}
</SelectItem>
{patientRegistries.map((registry) => (
<SelectItem key={registry.id} text={registry.name} value={registry.name}>
{useGetPatientRegistries()?.patientRegistries.map((registry) => (
<SelectItem key={registry.uuid} text={registry.name} value={registry.url}>
{registry.name}
</SelectItem>
))}
Expand Down

0 comments on commit 2b8413c

Please sign in to comment.