Skip to content

Commit

Permalink
#1181 - test metadata service
Browse files Browse the repository at this point in the history
  • Loading branch information
petmongrels committed Dec 6, 2023
1 parent 57470d8 commit 8a7275d
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import TestProgramEncounterFactory from '../test/model/txn/TestProgramEncounterF
import TestChecklistService from "./service/TestChecklistService";
import TestOrganisationService from "./service/TestOrganisationService";
import TestConceptFactory from "../test/model/TestConceptFactory";
import TestMetadataService from "./service/TestMetadataService";

function getCount(test, card, reportFilters) {
return test.reportCardService.getReportCardCount(card, reportFilters).primaryValue
Expand All @@ -44,15 +45,7 @@ class ReportCardServiceIntegrationTest extends BaseIntegrationTest {
this.executeInWrite((db) => {
this.organisationData = TestOrganisationService.setupOrganisation(db);
this.concept = db.create(Concept, TestConceptFactory.createWithDefaults({dataType: Concept.dataType.Text}));

this.subjectType = db.create(SubjectType, TestSubjectTypeFactory.createWithDefaults({type: SubjectType.types.Person, name: 'Beneficiary'}));
const program = db.create(Program, TestProgramFactory.create({name: 'Child'}));
const programEncounterType = db.create(EncounterType, TestEncounterTypeFactory.create({name: "Birth form"}));
const encounterType = db.create(EncounterType, TestEncounterTypeFactory.create({name: "Bar"}));
const approvalStatus = db.create(ApprovalStatus, TestApprovalStatusFactory.create({}));
const enrolmentApprovalStatus = db.create(ApprovalStatus, TestApprovalStatusFactory.create({}));
const pendingStatus = db.create(ApprovalStatus, TestApprovalStatusFactory.create({status: ApprovalStatus.statuses.Pending}));
const programEncRejectedStatus = db.create(ApprovalStatus, TestApprovalStatusFactory.create({status: ApprovalStatus.statuses.Rejected}));
this.metadata = TestMetadataService.create(db);

const subject1Id = General.randomUUID();
const subject2Id = General.randomUUID();
Expand All @@ -66,18 +59,18 @@ class ReportCardServiceIntegrationTest extends BaseIntegrationTest {
const subject1EAS = db.create(EntityApprovalStatus, TestEntityApprovalStatusFactory.create({
entityType: EntityApprovalStatus.entityType.Subject,
entityUUID: subject1Id,
entityTypeUuid: this.subjectType.uuid,
approvalStatus: approvalStatus
entityTypeUuid: this.metadata.subjectType.uuid,
approvalStatus: this.metadata.approvalStatus
}));
const encEAS = db.create(EntityApprovalStatus, TestEntityApprovalStatusFactory.create({
entityType: EntityApprovalStatus.entityType.Encounter,
entityUUID: encounterId1,
entityTypeUuid: encounterType.uuid,
approvalStatus: pendingStatus
entityTypeUuid: this.metadata.encounterType.uuid,
approvalStatus: this.metadata.pendingStatus
}));
const subject1 = db.create(Individual, TestSubjectFactory.createWithDefaults({
uuid: subject1Id,
subjectType: this.subjectType,
subjectType: this.metadata.subjectType,
address: this.organisationData.addressLevel,
firstName: "foo",
lastName: "bar",
Expand All @@ -89,7 +82,7 @@ class ReportCardServiceIntegrationTest extends BaseIntegrationTest {
uuid: encounterId1,
earliestVisitDateTime: moment().add(-2, "day").toDate(),
maxVisitDateTime: moment().add(2, "day").toDate(),
encounterType: encounterType,
encounterType: this.metadata.encounterType,
approvalStatuses: [encEAS],
latestEntityApprovalStatus: null,
subject: subject1
Expand All @@ -99,33 +92,33 @@ class ReportCardServiceIntegrationTest extends BaseIntegrationTest {
uuid: encounterId2,
earliestVisitDateTime: moment().add(-10, "day").toDate(),
maxVisitDateTime: moment().add(-5, "day").toDate(),
encounterType: encounterType,
encounterType: this.metadata.encounterType,
approvalStatuses: [],
latestEntityApprovalStatus: null,
subject: subject1
})));

const programEnrolment1 = db.create(ProgramEnrolment, TestProgramEnrolmentFactory.create({
uuid: programEnrolmentId1,
program,
program: this.metadata.program,
subject: subject1,
enrolmentDateTime: moment().toDate(),
latestEntityApprovalStatus: null,
observations: [TestObsFactory.create({concept: this.concept, valueJSON: JSON.stringify(this.concept.getValueWrapperFor("ABCPRG"))})],
approvalStatuses: []
}));

TestChecklistService.createChecklist( programEnrolment1, db);
TestChecklistService.createChecklist(programEnrolment1, db);

const subject2EAS = db.create(EntityApprovalStatus, TestEntityApprovalStatusFactory.create({
entityType: EntityApprovalStatus.entityType.Subject,
entityUUID: subject2Id,
entityTypeUuid: this.subjectType.uuid,
approvalStatus: pendingStatus
entityTypeUuid: this.metadata.subjectType.uuid,
approvalStatus: this.metadata.pendingStatus
}));
const subject2 = db.create(Individual, TestSubjectFactory.createWithDefaults({
uuid: subject2Id,
subjectType: this.subjectType,
subjectType: this.metadata.subjectType,
address: this.organisationData.addressLevel2,
firstName: "foo2",
lastName: "bar2",
Expand All @@ -136,19 +129,19 @@ class ReportCardServiceIntegrationTest extends BaseIntegrationTest {
const enrolmentEAS = db.create(EntityApprovalStatus, TestEntityApprovalStatusFactory.create({
entityType: EntityApprovalStatus.entityType.ProgramEnrolment,
entityUUID: programEnrolmentId2,
entityTypeUuid: program.uuid,
approvalStatus: enrolmentApprovalStatus
entityTypeUuid: this.metadata.program.uuid,
approvalStatus: this.metadata.enrolmentApprovalStatus
}));
const programEnc2EAS = db.create(EntityApprovalStatus, TestEntityApprovalStatusFactory.create({
entityType: EntityApprovalStatus.entityType.ProgramEncounter,
entityUUID: programEncounterId2,
entityTypeUuid: programEncounterType.uuid,
approvalStatus: programEncRejectedStatus
entityTypeUuid: this.metadata.programEncounterType.uuid,
approvalStatus: this.metadata.rejectedStatus
}));

const programEnrolment2 = db.create(ProgramEnrolment, TestProgramEnrolmentFactory.create({
uuid: programEnrolmentId2,
program,
program: this.metadata.program,
subject: subject2,
enrolmentDateTime: moment().add(-10, "day").toDate(),
latestEntityApprovalStatus: null,
Expand All @@ -160,10 +153,10 @@ class ReportCardServiceIntegrationTest extends BaseIntegrationTest {

programEnrolment2.addEncounter(db.create(ProgramEncounter, TestProgramEncounterFactory.create({
uuid: programEncounterId1,
encounterDateTime: moment().add(-2, "day").toDate(),
encounterDateTime: moment().add(-2, "day").toDate(),
earliestVisitDateTime: moment().add(-10, "day").toDate(),
maxVisitDateTime: moment().add(-5, "day").toDate(),
encounterType: programEncounterType,
encounterType: this.metadata.programEncounterType,
programEnrolment: programEnrolment2,
approvalStatuses: [],
latestEntityApprovalStatus: null
Expand All @@ -174,7 +167,7 @@ class ReportCardServiceIntegrationTest extends BaseIntegrationTest {
encounterDateTime: moment().toDate(),
earliestVisitDateTime: moment().add(-2, "day").toDate(),
maxVisitDateTime: moment().add(2, "day").toDate(),
encounterType: programEncounterType,
encounterType: this.metadata.programEncounterType,
programEnrolment: programEnrolment2,
approvalStatuses: [programEnc2EAS],
latestEntityApprovalStatus: programEnc2EAS
Expand All @@ -191,19 +184,31 @@ class ReportCardServiceIntegrationTest extends BaseIntegrationTest {
const dueChecklistCardType = db.create(StandardReportCardType, TestStandardReportCardTypeFactory.create({name: StandardReportCardType.type.DueChecklist}));
this.approvedCard = db.create(ReportCard, TestReportCardFactory.create({name: "approvedCard", standardReportCardType: approvedCardType}));
this.pendingCard = db.create(ReportCard, TestReportCardFactory.create({name: "pendingCard", standardReportCardType: pendingCardType}));
this.scheduledVisitsCard = db.create(ReportCard, TestReportCardFactory.create({name: "scheduledVisitsCard", standardReportCardType: scheduledVisitsCardType}));
this.scheduledVisitsCard = db.create(ReportCard, TestReportCardFactory.create({
name: "scheduledVisitsCard",
standardReportCardType: scheduledVisitsCardType
}));
this.overdueVisitsCard = db.create(ReportCard, TestReportCardFactory.create({name: "overdueVisitsCard", standardReportCardType: overdueVisitsCardType}));
this.latestVisitsCard = db.create(ReportCard, TestReportCardFactory.create({name: "latestVisitsCard", standardReportCardType: latestVisitsCardType}));
this.latestRegistrationsCard = db.create(ReportCard, TestReportCardFactory.create({name: "latestRegistrationsCard", standardReportCardType: latestRegistrationsCardType}));
this.latestEnrolmentsCard = db.create(ReportCard, TestReportCardFactory.create({name: "latestEnrolmentsCard", standardReportCardType: latestEnrolmentsCardType}));
this.latestRegistrationsCard = db.create(ReportCard, TestReportCardFactory.create({
name: "latestRegistrationsCard",
standardReportCardType: latestRegistrationsCardType
}));
this.latestEnrolmentsCard = db.create(ReportCard, TestReportCardFactory.create({
name: "latestEnrolmentsCard",
standardReportCardType: latestEnrolmentsCardType
}));
this.totalCard = db.create(ReportCard, TestReportCardFactory.create({name: "totalCard", standardReportCardType: totalCardType}));
this.dueChecklistCard = db.create(ReportCard, TestReportCardFactory.create({name: "dueChecklistCard", standardReportCardType: dueChecklistCardType}));
});

this.reportCardService = this.getService(ReportCardService);
this.addressSelected = TestDashboardReportFilterFactory.create({type: CustomFilter.type.Address, filterValue: [this.organisationData.addressLevel]});
this.address2Selected = TestDashboardReportFilterFactory.create({type: CustomFilter.type.Address, filterValue: [this.organisationData.addressLevel2]});
this.twoAddressSelected = TestDashboardReportFilterFactory.create({type: CustomFilter.type.Address, filterValue: [this.organisationData.addressLevel, this.organisationData.addressLevel2]});
this.twoAddressSelected = TestDashboardReportFilterFactory.create({
type: CustomFilter.type.Address,
filterValue: [this.organisationData.addressLevel, this.organisationData.addressLevel2]
});
}

getResultForApprovalCardsType() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import {ApprovalStatus, EncounterType, Program, SubjectType} from "openchs-models";
import TestSubjectTypeFactory from "../../test/model/TestSubjectTypeFactory";
import TestProgramFactory from "../../test/model/TestProgramFactory";
import TestEncounterTypeFactory from "../../test/model/TestEncounterTypeFactory";
import TestApprovalStatusFactory from "../../test/model/approval/TestApprovalStatusFactory";

class TestMetadataService {
static create(db) {
const metadata = {};
metadata.subjectType = db.create(SubjectType, TestSubjectTypeFactory.createWithDefaults({type: SubjectType.types.Person, name: 'Beneficiary'}));
metadata.program = db.create(Program, TestProgramFactory.create({name: 'Child'}));
metadata.programEncounterType = db.create(EncounterType, TestEncounterTypeFactory.create({name: "Birth form"}));
metadata.encounterType = db.create(EncounterType, TestEncounterTypeFactory.create({name: "Bar"}));
metadata.approvalStatus = db.create(ApprovalStatus, TestApprovalStatusFactory.create({}));
metadata.enrolmentApprovalStatus = db.create(ApprovalStatus, TestApprovalStatusFactory.create({}));
metadata.pendingStatus = db.create(ApprovalStatus, TestApprovalStatusFactory.create({status: ApprovalStatus.statuses.Pending}));
metadata.rejectedStatus = db.create(ApprovalStatus, TestApprovalStatusFactory.create({status: ApprovalStatus.statuses.Rejected}));
return metadata;
}
}

export default TestMetadataService;

0 comments on commit 8a7275d

Please sign in to comment.