Skip to content

Commit

Permalink
update imports
Browse files Browse the repository at this point in the history
  • Loading branch information
tcodling committed Feb 20, 2025
1 parent 410a1d5 commit 477f135
Show file tree
Hide file tree
Showing 66 changed files with 235 additions and 185 deletions.
6 changes: 3 additions & 3 deletions packages/central-server/__tests__/admin/patientMerge.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { fake, fakeUser } from '@tamanu/shared/test-helpers/fake';
import { fake, fakeUser } from '@tamanu/data-generation/helpers/fake';
import {
getTablesWithNoMergeCoverage,
mergePatient,
Expand Down Expand Up @@ -691,7 +691,7 @@ describe('Patient merge', () => {

const updatedFieldValues = await PatientFieldValue.findAll({});
expect(updatedFieldValues.length).toEqual(3);
updatedFieldValues.forEach(fieldValue => {
updatedFieldValues.forEach((fieldValue) => {
expect(fieldValue.value).toEqual(testValuesObject[fieldValue.definitionId].expect);
});
});
Expand Down Expand Up @@ -742,7 +742,7 @@ describe('Patient merge', () => {

const postPatientFacilities = await PatientFacility.findAll({});
expect(postPatientFacilities.length).toEqual(3);
expect(postPatientFacilities.map(p => p.facilityId).sort()).toEqual(
expect(postPatientFacilities.map((p) => p.facilityId).sort()).toEqual(
[facilityWithKeep.id, facilityWithMerge.id, facilityWithBoth.id].sort(),
);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { exportProgram } from '../../../dist/admin/programExporter';
import { createTestContext } from '../../utilities';
import { fake } from '@tamanu/shared/test-helpers/fake';
import { fake } from '@tamanu/data-generation/helpers/fake';
import { Program, Survey, ProgramDataElement, SurveyScreenComponent } from '@tamanu/database';

const surveySheetHeaders = [
Expand Down Expand Up @@ -44,7 +44,7 @@ const buildExpectedMetadataSheet = (program, surveys) => [
'notifiable',
'notifyEmailAddresses',
],
...surveys.map(survey => [
...surveys.map((survey) => [
survey.code,
survey.name,
survey.surveyType,
Expand All @@ -58,7 +58,7 @@ const buildExpectedMetadataSheet = (program, surveys) => [
]),
];

const buildExpectedSurveySheet = surveyScreenComponentAndProgramDataElements => [
const buildExpectedSurveySheet = (surveyScreenComponentAndProgramDataElements) => [
surveySheetHeaders,
...surveyScreenComponentAndProgramDataElements.map(
({ surveyScreenComponent, programDataElement }) => [
Expand Down Expand Up @@ -87,7 +87,7 @@ const buildExpectedSurveySheet = surveyScreenComponentAndProgramDataElements =>
jest.mock('xlsx', () => ({
utils: {
book_new: () => ({}),
aoa_to_sheet: data => data,
aoa_to_sheet: (data) => data,
book_append_sheet: (book, sheet, name) => {
book[name] = sheet;
},
Expand Down
10 changes: 5 additions & 5 deletions packages/central-server/__tests__/admin/settings.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SETTINGS_SCOPES } from '@tamanu/constants';
import { fake, chance } from '@tamanu/shared/test-helpers/fake';
import { fake, chance } from '@tamanu/data-generation/helpers/fake';
import { createTestContext } from '../utilities';
import { settingsCache } from '@tamanu/settings';

Expand Down Expand Up @@ -70,20 +70,20 @@ describe('Settings Admin', () => {

// Loop through each scope and do a put request with the settings object and scope to save to DB
const saveResponses = await Promise.all(
Object.values(SETTINGS_SCOPES).map(async scope => {
Object.values(SETTINGS_SCOPES).map(async (scope) => {
const facilityId = scope === SETTINGS_SCOPES.FACILITY ? facility.id : null;
return saveSettings(scopeTestJsons[scope], scope, facilityId);
}),
);

// Ensure all saving responses were successful
saveResponses.forEach(response => {
saveResponses.forEach((response) => {
expect(response).toHaveSucceeded();
});

// Loop through each scope and get the json object of settings saved to the DB when fetching by scope
const getResponses = await Promise.all(
Object.values(SETTINGS_SCOPES).map(async scope => {
Object.values(SETTINGS_SCOPES).map(async (scope) => {
const facilityId = scope === SETTINGS_SCOPES.FACILITY ? facility.id : null;
const getResponse = await getSettings(scope, facilityId);
return { getResponse, scope };
Expand Down Expand Up @@ -185,7 +185,7 @@ describe('Settings Admin', () => {
const endpointResponse = await adminApp.get('/v1/admin/facilities');
expect(endpointResponse).toHaveSucceeded();

const plainFacilityList = [facility1, facility2].map(facility => {
const plainFacilityList = [facility1, facility2].map((facility) => {
const { id, name } = facility.get({ plain: true });
return { id, name };
});
Expand Down
2 changes: 1 addition & 1 deletion packages/central-server/__tests__/facility.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { fake } from '@tamanu/shared/test-helpers/fake';
import { fake } from '@tamanu/data-generation/helpers/fake';
import { createTestContext } from './utilities';

describe('facility routes', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { fake, fakeReferenceData, fakeUser } from '@tamanu/shared/test-helpers/fake';
import { fake, fakeReferenceData, fakeUser } from '@tamanu/data-generation/helpers/fake';
import {
administeredVaccineToHL7Immunization,
getAdministeredVaccineInclude,
Expand Down
2 changes: 1 addition & 1 deletion packages/central-server/__tests__/hl7fhir/labTest.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createDummyEncounter, createDummyPatient } from '@tamanu/database/demoData/patients';
import { randomLabRequest } from '@tamanu/database/demoData/labRequests';
import { LAB_REQUEST_STATUSES, REFERENCE_TYPES } from '@tamanu/constants';
import { fake } from '@tamanu/shared/test-helpers/fake';
import { fake } from '@tamanu/data-generation/helpers/fake';

import { createTestContext } from '../utilities';
import { validate } from './hl7utilities';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { formatRFC7231 } from 'date-fns';

import { fake } from '@tamanu/shared/test-helpers/fake';
import { fake } from '@tamanu/data-generation/helpers/fake';
import { getCurrentDateString } from '@tamanu/utils/dateTime';
import { fakeUUID } from '@tamanu/utils/generateId';
import { formatFhirDate } from '@tamanu/shared/utils/fhir/datetime';
Expand Down Expand Up @@ -413,7 +413,7 @@ describe(`Materialised FHIR - Patient`, () => {
expect(response.body.entry.length).toBe(3);

// The first order is actually address[].line[] (so streetVillage)
expect(response.body.entry.map(x => x.resource.address[0].city)).toEqual([
expect(response.body.entry.map((x) => x.resource.address[0].city)).toEqual([
'El Paso',
'Amsterdam',
'Cabo',
Expand Down Expand Up @@ -702,7 +702,7 @@ describe(`Materialised FHIR - Patient`, () => {
expect(response.body.entry.length).toBe(5);

// Numbers don't repeat so everything else should be in place
expect(response.body.entry.map(x => x.resource.telecom[0].value)).toEqual([
expect(response.body.entry.map((x) => x.resource.telecom[0].value)).toEqual([
'123456783',
'123456781',
'123456782',
Expand Down Expand Up @@ -1146,8 +1146,7 @@ describe(`Materialised FHIR - Patient`, () => {
diagnostics: expect.any(String),
expression: '_page',
details: {
text:
'this must be a `number` type, but the final value was: `NaN` (cast from the value `"z"`).',
text: 'this must be a `number` type, but the final value was: `NaN` (cast from the value `"z"`).',
},
},
{
Expand All @@ -1156,8 +1155,7 @@ describe(`Materialised FHIR - Patient`, () => {
diagnostics: expect.any(String),
expression: '_count',
details: {
text:
'this must be a `number` type, but the final value was: `NaN` (cast from the value `"x"`).',
text: 'this must be a `number` type, but the final value was: `NaN` (cast from the value `"x"`).',
},
},
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { VISIBILITY_STATUSES } from '@tamanu/constants';
import { fake } from '@tamanu/shared/test-helpers/fake';
import { fake } from '@tamanu/data-generation/helpers/fake';

import { createTestContext } from '../../utilities';

Expand Down Expand Up @@ -55,7 +55,7 @@ describe(`Materialised FHIR - Patient Merge`, () => {
FhirPatient.materialiseFromUpstream(id),
),
)
).map(row => row.id);
).map((row) => row.id);

await FhirPatient.resolveUpstreams();

Expand Down Expand Up @@ -188,10 +188,12 @@ describe(`Materialised FHIR - Patient Merge`, () => {
const response = await app.get(path);

// assert
const resourceC = response.body?.entry?.find(({ resource }) => resource.id === ids.c)
?.resource;
const resourceD = response.body?.entry?.find(({ resource }) => resource.id === ids.d)
?.resource;
const resourceC = response.body?.entry?.find(
({ resource }) => resource.id === ids.c,
)?.resource;
const resourceD = response.body?.entry?.find(
({ resource }) => resource.id === ids.d,
)?.resource;

expect(resourceC).toMatchObject({
resourceType: 'Patient',
Expand Down Expand Up @@ -409,10 +411,12 @@ describe(`Materialised FHIR - Patient Merge`, () => {
const response = await app.get(path);

// assert
const resourceC = response.body?.entry?.find(({ resource }) => resource.id === ids.c)
?.resource;
const resourceD = response.body?.entry?.find(({ resource }) => resource.id === ids.d)
?.resource;
const resourceC = response.body?.entry?.find(
({ resource }) => resource.id === ids.c,
)?.resource;
const resourceD = response.body?.entry?.find(
({ resource }) => resource.id === ids.d,
)?.resource;

expect(resourceC).toMatchObject({
resourceType: 'Patient',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { fake, fakeReferenceData, fakeUser } from '@tamanu/shared/test-helpers/fake';
import { fake, fakeReferenceData, fakeUser } from '@tamanu/data-generation/helpers/fake';
import { createTestContext } from '@tamanu/central-server/__tests__/utilities';

export function testImmunizationHandler(integrationName, requestHeaders = {}) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { format } from 'date-fns';

import { fake } from '@tamanu/shared/test-helpers/fake';
import { fake } from '@tamanu/data-generation/helpers/fake';
import { getCurrentDateString } from '@tamanu/utils/dateTime';

import { createTestContext } from '../../utilities';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { format } from 'date-fns';

import { fake } from '@tamanu/shared/test-helpers/fake';
import { fake } from '@tamanu/data-generation/helpers/fake';
import { getCurrentDateString } from '@tamanu/utils/dateTime';
import { createTestContext } from '@tamanu/central-server/__tests__/utilities';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { fake } from '@tamanu/shared/test-helpers/fake';
import { fake } from '@tamanu/data-generation/helpers/fake';
import { findOneOrCreate } from '@tamanu/shared/test-helpers/factory';
import { SURVEY_TYPES } from '@tamanu/constants';
import { importerTransaction } from '../../dist/admin/importer/importerEndpoint';
Expand Down Expand Up @@ -384,7 +384,7 @@ describe('Programs import', () => {
it('Should import a valid vitals survey and delete visualisationConfig', async () => {
const { ProgramDataElement } = ctx.store.models;

const validateVisualisationConfig = async expectValue => {
const validateVisualisationConfig = async (expectValue) => {
const { visualisationConfig } = await ProgramDataElement.findOne({
where: {
code: 'PatientVitalsHeartRate',
Expand Down Expand Up @@ -688,7 +688,8 @@ describe('Programs import', () => {
file: 'charting-simple-datetime-invalid-id',
dryRun: true,
});
const expectedError = "sheetName: Test Chart, code: 'testchartcode0', First question should have 'pde-PatientChartingDate' as ID";
const expectedError =
"sheetName: Test Chart, code: 'testchartcode0', First question should have 'pde-PatientChartingDate' as ID";
expect(errors.length).toEqual(1);
expect(errors[0].message).toEqual(expectedError);
});
Expand All @@ -697,7 +698,8 @@ describe('Programs import', () => {
file: 'charting-simple-datetime-invalid-type',
dryRun: true,
});
const expectedError = "sheetName: Test Chart, code: 'PatientChartingDate', First question should be DateTime type";
const expectedError =
"sheetName: Test Chart, code: 'PatientChartingDate', First question should be DateTime type";
expect(errors.length).toEqual(1);
expect(errors[0].message).toEqual(expectedError);
});
Expand All @@ -722,14 +724,22 @@ describe('Programs import', () => {
file: 'charting-complex-main-only-invalid',
dryRun: true,
});
expect(errors).toContainAnError('metadata', 0, 'Complex charts need a core data set survey');
expect(errors).toContainAnError(
'metadata',
0,
'Complex charts need a core data set survey',
);
});
it('Should refuse to import without its main info (ComplexChart)', async () => {
const { errors } = await doImport({
file: 'charting-complex-core-only-invalid',
dryRun: true,
});
expect(errors).toContainAnError('metadata', 0, 'Cannot import a complex chart core without the main survey');
expect(errors).toContainAnError(
'metadata',
0,
'Cannot import a complex chart core without the main survey',
);
});
it('Should refuse to import a complex core survey without special question config types', async () => {
const { errors, stats } = await doImport({
Expand All @@ -738,7 +748,7 @@ describe('Programs import', () => {
});

const errorMessages = [
"Invalid complex chart core questions",
'Invalid complex chart core questions',
"sheetName: Core, code: 'ComplexChartInstanceName', Invalid question type",
"sheetName: Core, code: 'ComplexChartDate', Invalid question type",
"sheetName: Core, code: 'ComplexChartType', Invalid question type",
Expand Down Expand Up @@ -807,7 +817,11 @@ describe('Programs import', () => {
file: 'charting-complex-multiple-invalid',
dryRun: true,
});
expect(errors).toContainAnError('metadata', 0, 'Only one complex chart and complex chart core allowed in a program');
expect(errors).toContainAnError(
'metadata',
0,
'Only one complex chart and complex chart core allowed in a program',
);
});
it('Should refuse to import a complex chart set if it already exists in that program', async () => {
const { Program, Survey } = ctx.store.models;
Expand All @@ -830,7 +844,11 @@ describe('Programs import', () => {
file: 'charting-complex-valid',
dryRun: true,
});
expect(errors).toContainAnError('metadata', 0, 'Complex chart set already exists for this program');
expect(errors).toContainAnError(
'metadata',
0,
'Complex chart set already exists for this program',
);
});
it('Should refuse to import a complex chart survey with isSensitive set to true', async () => {
const { errors } = await doImport({
Expand All @@ -851,7 +869,8 @@ describe('Programs import', () => {
file: 'charting-complex-datetime-invalid-id',
dryRun: true,
});
const expectedError = "sheetName: Test Chart, code: 'testchartcode0', First question should have 'pde-PatientChartingDate' as ID";
const expectedError =
"sheetName: Test Chart, code: 'testchartcode0', First question should have 'pde-PatientChartingDate' as ID";
expect(errors.length).toEqual(1);
expect(errors[0].message).toEqual(expectedError);
});
Expand All @@ -860,7 +879,8 @@ describe('Programs import', () => {
file: 'charting-complex-datetime-invalid-type',
dryRun: true,
});
const expectedError = "sheetName: Test Chart, code: 'PatientChartingDate', First question should be DateTime type";
const expectedError =
"sheetName: Test Chart, code: 'PatientChartingDate', First question should be DateTime type";
expect(errors.length).toEqual(1);
expect(errors[0].message).toEqual(expectedError);
});
Expand All @@ -869,7 +889,7 @@ describe('Programs import', () => {
file: 'charting-complex-core-question-amount-invalid',
dryRun: true,
});
const expectedError = "Invalid complex chart core questions";
const expectedError = 'Invalid complex chart core questions';
expect(errors.length).toEqual(1);
expect(errors[0].message).toEqual(expectedError);
});
Expand All @@ -878,7 +898,7 @@ describe('Programs import', () => {
file: 'charting-complex-core-question-order-invalid',
dryRun: true,
});
const expectedError = "Invalid complex chart core questions";
const expectedError = 'Invalid complex chart core questions';
expect(errors.length).toEqual(1);
expect(errors[0].message).toEqual(expectedError);
});
Expand Down
Loading

0 comments on commit 477f135

Please sign in to comment.