Skip to content

Commit

Permalink
#1193 - display the full subject when approval list view.
Browse files Browse the repository at this point in the history
  • Loading branch information
petmongrels committed Dec 8, 2023
1 parent dda0354 commit e5d3b5a
Show file tree
Hide file tree
Showing 14 changed files with 225 additions and 152 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class EntityApprovalServiceTest extends BaseIntegrationTest {
entityTypeUuid: this.metadata.subjectType.uuid,
approvalStatus: this.metadata.approvedStatus
}));
const subject1 = db.create(Individual, TestSubjectFactory.createWithDefaults({
db.create(Individual, TestSubjectFactory.createWithDefaults({
uuid: subject1Id,
subjectType: this.metadata.subjectType,
address: this.organisationData.addressLevel,
Expand All @@ -48,7 +48,7 @@ class EntityApprovalServiceTest extends BaseIntegrationTest {
entityTypeUuid: this.metadata.subjectType.uuid,
approvalStatus: this.metadata.approvedStatus
}));
const subject2 = db.create(Individual, TestSubjectFactory.createWithDefaults({
db.create(Individual, TestSubjectFactory.createWithDefaults({
uuid: subject2Id,
subjectType: this.metadata.subjectType,
address: this.organisationData.addressLevel2,
Expand All @@ -58,7 +58,7 @@ class EntityApprovalServiceTest extends BaseIntegrationTest {
approvalStatuses: [subject2EAS]
}));

const subject3 = db.create(Individual, TestSubjectFactory.createWithDefaults({
this.subject3 = db.create(Individual, TestSubjectFactory.createWithDefaults({
uuid: subject3Id,
subjectType: this.metadata.subjectType,
address: this.organisationData.addressLevel2,
Expand All @@ -73,22 +73,22 @@ class EntityApprovalServiceTest extends BaseIntegrationTest {
entityTypeUuid: this.metadata.program.uuid,
approvalStatus: this.metadata.approvedStatus
}));
const programEnrolment = db.create(ProgramEnrolment, TestProgramEnrolmentFactory.create({
const enrolment = db.create(ProgramEnrolment, TestProgramEnrolmentFactory.create({
uuid: enrolmentId,
program: this.metadata.program,
subject: subject3,
subject: this.subject3,
enrolmentDateTime: moment().add(-10, "day").toDate(),
latestEntityApprovalStatus: null,
observations: [TestObsFactory.create({concept: this.concept, valueJSON: JSON.stringify(this.concept.getValueWrapperFor("DEFPRG"))})],
approvalStatuses: [enrolmentEAS]
}));
this.subject3.addEnrolment(enrolment);
});

this.service = this.getService(EntityApprovalStatusService);
}

getSubjectEASes() {
this.logQueries();
const subjects = this.service.getAllSubjects(this.metadata.approvedStatus.status, null);
assert.equal(subjects.length, 3);
assert.equal(subjects[0].firstName, "ABC");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import UserInfoServiceTest from "./UserInfoServiceTest";
import RealmProxyTest from "./RealmProxyTest";
import ReportCardServiceIntegrationTest from "./ReportCardServiceIntegrationTest";
import EntityApprovalServiceTest from "./EntityApprovalServiceTest";
import IndividualIntegrationTest from "./model/IndividualIntegrationTest";

const itemCommonStyle = {
padding: 10,
Expand Down Expand Up @@ -63,7 +64,7 @@ class IntegrationTestApp extends Component {
super(props, context);
FileSystem.init();
this.getBean = this.getBean.bind(this);
this.integrationTestRunner = new IntegrationTestRunner(EntityApprovalServiceTest, ReportCardServiceIntegrationTest, UserInfoServiceTest, DatabaseTest, PersonRegisterActionsIntegrationTest, UtilTest, RealmProxyTest);
this.integrationTestRunner = new IntegrationTestRunner(IndividualIntegrationTest, EntityApprovalServiceTest, ReportCardServiceIntegrationTest, UserInfoServiceTest, DatabaseTest, PersonRegisterActionsIntegrationTest, UtilTest, RealmProxyTest);
this.state = {isInitialisationDone: false, integrationTests: this.integrationTestRunner.testSuite};
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import BaseIntegrationTest from "../BaseIntegrationTest";
import TestOrganisationService from "../service/TestOrganisationService";
import {Concept, EntityApprovalStatus, Individual, ProgramEnrolment} from "openchs-models";
import TestConceptFactory from "../../test/model/TestConceptFactory";
import TestMetadataService from "../service/TestMetadataService";
import General from "../../src/utility/General";
import TestEntityApprovalStatusFactory from "../../test/model/approval/TestEntityApprovalStatusFactory";
import TestSubjectFactory from "../../test/model/txn/TestSubjectFactory";
import TestObsFactory from "../../test/model/TestObsFactory";
import TestProgramEnrolmentFactory from "../../test/model/txn/TestProgramEnrolmentFactory";
import moment from "moment";
import {assert} from "chai";

class IndividualIntegrationTest extends BaseIntegrationTest {
setup(): this {
super.setup();
this.executeInWrite((db) => {
this.organisationData = TestOrganisationService.setupOrganisation(db);
this.concept = db.create(Concept, TestConceptFactory.createWithDefaults({dataType: Concept.dataType.Text}));
this.metadata = TestMetadataService.create(db);
});
}

getMemberEntitiesWithLatestStatus() {
this.executeInWrite((db) => {
const subject1Id = General.randomUUID();
const enrolmentId = General.randomUUID();

const subject1EAS = db.create(EntityApprovalStatus, TestEntityApprovalStatusFactory.create({
entityType: EntityApprovalStatus.entityType.Subject,
entityUUID: subject1Id,
entityTypeUuid: this.metadata.subjectType.uuid,
approvalStatus: this.metadata.approvedStatus
}));
this.subject = db.create(Individual, TestSubjectFactory.createWithDefaults({
uuid: subject1Id,
subjectType: this.metadata.subjectType,
address: this.organisationData.addressLevel,
firstName: "XYZ",
lastName: "bar",
observations: [TestObsFactory.create({concept: this.concept, valueJSON: JSON.stringify(this.concept.getValueWrapperFor("ABC"))})],
approvalStatuses: [subject1EAS]
}));
const enrolmentEAS = db.create(EntityApprovalStatus, TestEntityApprovalStatusFactory.create({
entityType: EntityApprovalStatus.entityType.ProgramEnrolment,
entityUUID: enrolmentId,
entityTypeUuid: this.metadata.program.uuid,
approvalStatus: this.metadata.approvedStatus
}));
const enrolment = db.create(ProgramEnrolment, TestProgramEnrolmentFactory.create({
uuid: enrolmentId,
program: this.metadata.program,
subject: this.subject,
enrolmentDateTime: moment().add(-10, "day").toDate(),
observations: [TestObsFactory.create({concept: this.concept, valueJSON: JSON.stringify(this.concept.getValueWrapperFor("DEFPRG"))})],
approvalStatuses: [enrolmentEAS]
}));
this.subject.addEnrolment(enrolment);
});
assert.equal(this.subject.getMemberEntitiesWithLatestStatus(this.metadata.approvedStatus.status).length, 2);
}

getMemberEntitiesWithLatestStatus_WithoutApprovalStatuses() {
this.executeInWrite((db) => {
const subject1Id = General.randomUUID();
const enrolmentId = General.randomUUID();

this.subject = db.create(Individual, TestSubjectFactory.createWithDefaults({
uuid: subject1Id,
subjectType: this.metadata.subjectType,
address: this.organisationData.addressLevel,
firstName: "XYZ",
lastName: "bar",
observations: [TestObsFactory.create({concept: this.concept, valueJSON: JSON.stringify(this.concept.getValueWrapperFor("ABC"))})]
}));
const enrolment = db.create(ProgramEnrolment, TestProgramEnrolmentFactory.create({
uuid: enrolmentId,
program: this.metadata.program,
subject: this.subject,
enrolmentDateTime: moment().add(-10, "day").toDate(),
observations: [TestObsFactory.create({concept: this.concept, valueJSON: JSON.stringify(this.concept.getValueWrapperFor("DEFPRG"))})]
}));
this.subject.addEnrolment(enrolment);
});
assert.equal(this.subject.getMemberEntitiesWithLatestStatus(this.metadata.approvedStatus.status).length, 0);
}
}

export default IndividualIntegrationTest;
2 changes: 1 addition & 1 deletion packages/openchs-android/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"lodash": "4.17.21",
"moment": "2.29.4",
"native-base": "3.4.9",
"openchs-models": "1.30.92",
"openchs-models": "1.30.95",
"prop-types": "15.8.1",
"react": "18.2.0",
"react-native": "0.72.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class CustomDashboardActions {
const standardReportCardType = reportCard.standardReportCardType;
const viewName = CustomDashboardActions._getViewName(standardReportCardType);
if (!_.isNil(result)) {
setTimeout(() => action.onApprovalItemsResults(result, result.length, status, viewName), 0);
setTimeout(() => action.onApprovalItemsResults(result, status, viewName, standardReportCardType && standardReportCardType.getApprovalStatusForType()), 0);
}
}
return newState;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,16 @@
import BaseService from "../BaseService";
import Service from "../../framework/bean/Service";
import {ReportCard, StandardReportCardType, ApprovalStatus} from "avni-models";
import {ReportCard, StandardReportCardType, ApprovalStatus} from "openchs-models";
import EntityApprovalStatusService from "../EntityApprovalStatusService";
import RuleEvaluationService from "../RuleEvaluationService";
import IndividualService from "../IndividualService";
import CommentService from "../comment/CommentService";
import _ from "lodash";
import TaskService from "../task/TaskService";
import General from "../../utility/General";
import {JSONStringify} from "../../utility/JsonStringify";

function getApprovalStatusForType(type) {
const typeToStatusMap = {
[StandardReportCardType.type.PendingApproval]: ApprovalStatus.statuses.Pending,
[StandardReportCardType.type.Approved]: ApprovalStatus.statuses.Approved,
[StandardReportCardType.type.Rejected]: ApprovalStatus.statuses.Rejected,
};
return typeToStatusMap[type];
}

@Service("reportCardService")
class ReportCardService extends BaseService {

constructor(db, context) {
super(db, context);
}
Expand All @@ -30,8 +19,8 @@ class ReportCardService extends BaseService {
return ReportCard.schema.name;
}

getCountForApprovalCardsType(type, reportFilters) {
const approvalStatus_status = getApprovalStatusForType(type);
getCountForApprovalCardsType(standardReportCardType, reportFilters) {
const approvalStatus_status = standardReportCardType.getApprovalStatusForType();
const {result} = this.getService(EntityApprovalStatusService).getAllEntitiesForReports(approvalStatus_status, reportFilters)
return {
primaryValue: _.map(result, ({data}) => data.length).reduce((total, l) => total + l, 0),
Expand All @@ -40,8 +29,8 @@ class ReportCardService extends BaseService {
};
}

getResultForApprovalCardsType(type, reportFilters) {
const approvalStatus_status = getApprovalStatusForType(type);
getResultForApprovalCardsType(standardReportCardType, reportFilters) {
const approvalStatus_status = standardReportCardType.getApprovalStatusForType();
return this.getService(EntityApprovalStatusService).getAllSubjects(approvalStatus_status, reportFilters);
}

Expand Down Expand Up @@ -114,7 +103,7 @@ class ReportCardService extends BaseService {
case _.isNil(standardReportCardType) :
return this.getService(RuleEvaluationService).getDashboardCardCount(reportCard, reportFilters);
case standardReportCardType.isApprovalType() :
return this.getCountForApprovalCardsType(standardReportCardType.name, reportFilters);
return this.getCountForApprovalCardsType(standardReportCardType, reportFilters);
case standardReportCardType.isDefaultType() :
return this.getCountForDefaultCardsType(standardReportCardType.name, reportFilters);
case standardReportCardType.isCommentType() :
Expand All @@ -135,7 +124,7 @@ class ReportCardService extends BaseService {
return {status: null, result};
}
case standardReportCardType.isApprovalType() :
return {status: null, result: this.getResultForApprovalCardsType(standardReportCardType.name, reportFilters)};
return {status: null, result: this.getResultForApprovalCardsType(standardReportCardType, reportFilters)};
case standardReportCardType.isDefaultType() :
return this.getResultForDefaultCardsType(standardReportCardType.name, reportFilters);
case standardReportCardType.isCommentType() : {
Expand Down
4 changes: 2 additions & 2 deletions packages/openchs-android/src/utility/CHSNavigator.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ class CHSNavigator {
}
}

static navigateToApprovalDetailsView(source, entity, schema) {
TypedTransition.from(source).with({entity, schema}).to(ApprovalDetailsView, true);
static navigateToApprovalDetailsView(source, entity) {
TypedTransition.from(source).with({entity}).to(ApprovalDetailsView, true);
}

static navigateToPhoneNumberVerificationView(source, next, observation, onSuccess, onSkip) {
Expand Down
2 changes: 1 addition & 1 deletion packages/openchs-android/src/utility/ErrorHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default class ErrorHandler {
const frameArray = x.map((row) => Object.defineProperty(row, 'fileName', {
value: `${row.fileName}:${row.lineNumber || 0}:${row.columnNumber || 0}`
}));
General.logDebug('ErrorHandler', `Notifying Bugsnag ${error}`);
General.logDebug('ErrorHandler', `Notifying Bugsnag (if release stage) ${error}`);
bugsnag.notify(error, (report) => report.metadata.frameArray = frameArray);
errorCallback(error, JSON.stringify(frameArray));
});
Expand Down
Loading

0 comments on commit e5d3b5a

Please sign in to comment.