Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

U4X-838:Add a validation rule on the clinical assessment form to be saved once in a day #270

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
},
"devDependencies": {
"@carbon/react": "^1.64.1",
"@openmrs/esm-form-engine-lib": "latest",
"@openmrs/esm-framework": "next",
"@openmrs/esm-patient-common-lib": "next",
"@openmrs/esm-styleguide": "next",
Expand Down
1 change: 1 addition & 0 deletions packages/esm-ugandaemr-app/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ export const REGISTRY_REGIONS_URL = 'https://nhfr-staging-api.planetsystems.co/n

// privileges
export const PRIVILEGE_UPDATE_FACILITY_CODE = 'Update Facility Code';
export const dateFormat = 'YYYY-MM-DD';
27 changes: 27 additions & 0 deletions packages/esm-ugandaemr-app/src/custom-expressions/custom-apis.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { fhirBaseUrl, restBaseUrl, openmrsFetch } from '@openmrs/esm-framework';
import { configSchema } from '@ugandaemr/esm-care-panel-app/src/config-schema';
import dayjs from "dayjs";
import {dateFormat} from "../constants";

export async function getLatestObs(patientUuid: string, conceptUuid: string, encounterTypeUuid?: string) {
let params = `patient=${patientUuid}&code=${conceptUuid}${
Expand Down Expand Up @@ -47,3 +49,28 @@ export async function getCohortCategorization(uuid: string) {

return await openmrsFetch(apiUrl);
}

export async function getEncounters(patientUuid: string, encounterTypeUuid?: string) {
let params = `patient=${patientUuid}${encounterTypeUuid ? `&encounterType=${encounterTypeUuid}` : ''}`;

const apiUrl = `${restBaseUrl}/encounter?${params}&v=custom:(uuid,encounterDatetime,encounterType:(uuid,name))`;
const { data } = await openmrsFetch(apiUrl);

return (
data?.results?.map((encounter) => ({
uuid: encounter.uuid,
encounterDatetime: encounter.encounterDatetime,
encounterType: encounter.encounterType.name,
})) || []
);
}

export function getPatientEncounterDates(patientUuid: string, encounterTypeUuid: string) {
let params = `encounterType=${encounterTypeUuid}&patient=${patientUuid}&v=custom:(uuid,encounterDatetime)`;
return openmrsFetch(`${restBaseUrl}/encounter?${params}`).then(({ data }) => {
if (data.results.length === 0) {
return [];
}
return data.results.map((encounter: any) => dayjs(encounter.encounterDatetime).format(dateFormat));
});
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { getCohortCategorization, getConceptDataType, getLatestObs, getPatientPrograms } from './custom-apis';
import { getCohortCategorization, getConceptDataType, getLatestObs, getPatientPrograms, getEncounters } from './custom-apis';
import dayjs from 'dayjs';
import { configSchema } from '@ugandaemr/esm-care-panel-app/src/config-schema';
import { DataSource } from '@openmrs/openmrs-form-engine-lib';
import { OpenmrsResource } from '@openmrs/esm-framework';
import {openmrsFetch, OpenmrsResource, restBaseUrl} from '@openmrs/esm-framework';
import {dateFormat} from "../constants";

export async function latestObs(patientId: string, conceptUuid: string) {
const response = await getLatestObs(patientId, conceptUuid);
Expand Down Expand Up @@ -67,3 +68,4 @@ export class DSDMCategorizationDatasource implements DataSource<OpenmrsResource>
return data;
}
}

2 changes: 2 additions & 0 deletions packages/esm-ugandaemr-app/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
latestObs,
patientDSDM,
} from './custom-expressions/custom-expressions';
import {getPatientEncounterDates} from "./custom-expressions/custom-apis";

export const importTranslation = require.context('../translations', false, /.json$/, 'lazy');

Expand All @@ -45,6 +46,7 @@ export function startupApp() {
registerExpressionHelper('cusGetLatestObs', latestObs);
registerExpressionHelper('getPatientDSMD', patientDSDM);
registerExpressionHelper('CustomMonthsOnARTCalc', CalcMonthsOnART);
registerExpressionHelper('getPreviousEncounterDates', getPatientEncounterDates);

registerCustomDataSource({
name: 'dsdm_categorization_datasource',
Expand Down