diff --git a/package.json b/package.json index 763b056..46167c7 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/packages/esm-patient-registration-app/package.json b/packages/esm-patient-registration-app/package.json index e545b07..5cdf132 100644 --- a/packages/esm-patient-registration-app/package.json +++ b/packages/esm-patient-registration-app/package.json @@ -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": [ diff --git a/packages/esm-patient-registration-app/src/patient-verification/patient-verification-hook.tsx b/packages/esm-patient-registration-app/src/patient-verification/patient-verification-hook.tsx index daf2661..ee7b60c 100644 --- a/packages/esm-patient-registration-app/src/patient-verification/patient-verification-hook.tsx +++ b/packages/esm-patient-registration-app/src/patient-verification/patient-verification-hook.tsx @@ -2,7 +2,7 @@ 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; @@ -10,8 +10,8 @@ export const searchRegistry = async (searchParams, 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 { @@ -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(); @@ -55,9 +55,8 @@ export function useConceptAnswers(conceptUuid: string): { data: Array 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), diff --git a/packages/esm-patient-registration-app/src/patient-verification/verification-constants.ts b/packages/esm-patient-registration-app/src/patient-verification/verification-constants.ts index 0005298..59ac869 100644 --- a/packages/esm-patient-registration-app/src/patient-verification/verification-constants.ts +++ b/packages/esm-patient-registration-app/src/patient-verification/verification-constants.ts @@ -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>) { + const arrayToReturn: Array = []; + if (dataArray) { + dataArray.map((profile: Record) => { + if (profile?.profileEnabled && profile?.searchable) { + arrayToReturn.push({ + name: profile?.name, + uuid: profile?.uuid, + url: profile?.searchURL, + profileEnabled: profile?.profileEnabled, + profileSearchable: profile?.searchable, + }); + } + }); + } + + return arrayToReturn; +} diff --git a/packages/esm-patient-registration-app/src/patient-verification/verification-forms/fields/registry-select.component.tsx b/packages/esm-patient-registration-app/src/patient-verification/verification-forms/fields/registry-select.component.tsx index d9907e3..d87219b 100644 --- a/packages/esm-patient-registration-app/src/patient-verification/verification-forms/fields/registry-select.component.tsx +++ b/packages/esm-patient-registration-app/src/patient-verification/verification-forms/fields/registry-select.component.tsx @@ -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 }) => { @@ -22,8 +22,8 @@ const RegistrySelect = ({ values, setValues }) => { {' '} - {patientRegistries.map((registry) => ( - + {useGetPatientRegistries()?.patientRegistries.map((registry) => ( + {registry.name} ))}