Search in sources :

Example 46 with TrackedEntityType

use of org.hisp.dhis.trackedentity.TrackedEntityType in project dhis2-core by dhis2.

the class EventSecurityImportValidationTest method setupMetadata.

private void setupMetadata() {
    organisationUnitA = createOrganisationUnit('A');
    organisationUnitB = createOrganisationUnit('B');
    manager.save(organisationUnitA);
    manager.save(organisationUnitB);
    organisationUnitA.setPublicAccess(AccessStringHelper.FULL);
    manager.update(organisationUnitA);
    dataElementA = createDataElement('A');
    dataElementB = createDataElement('B');
    dataElementA.setValueType(ValueType.INTEGER);
    dataElementB.setValueType(ValueType.INTEGER);
    manager.save(dataElementA);
    manager.save(dataElementB);
    programStageA = createProgramStage('A', 0);
    programStageB = createProgramStage('B', 0);
    programStageB.setRepeatable(true);
    manager.save(programStageA);
    manager.save(programStageB);
    programA = createProgram('A', new HashSet<>(), organisationUnitA);
    programA.setProgramType(ProgramType.WITH_REGISTRATION);
    trackedEntityType = createTrackedEntityType('A');
    trackedEntityTypeService.addTrackedEntityType(trackedEntityType);
    TrackedEntityType trackedEntityTypeFromProgram = createTrackedEntityType('C');
    trackedEntityTypeService.addTrackedEntityType(trackedEntityTypeFromProgram);
    manager.save(programA);
    ProgramStageDataElement programStageDataElement = new ProgramStageDataElement();
    programStageDataElement.setDataElement(dataElementA);
    programStageDataElement.setProgramStage(programStageA);
    programStageDataElementService.addProgramStageDataElement(programStageDataElement);
    programStageA.getProgramStageDataElements().add(programStageDataElement);
    programStageA.setProgram(programA);
    programStageDataElement = new ProgramStageDataElement();
    programStageDataElement.setDataElement(dataElementB);
    programStageDataElement.setProgramStage(programStageB);
    programStageDataElementService.addProgramStageDataElement(programStageDataElement);
    programStageB.getProgramStageDataElements().add(programStageDataElement);
    programStageB.setProgram(programA);
    programStageB.setMinDaysFromStart(2);
    programA.getProgramStages().add(programStageA);
    programA.getProgramStages().add(programStageB);
    programA.setTrackedEntityType(trackedEntityType);
    trackedEntityType.setPublicAccess(AccessStringHelper.DATA_READ_WRITE);
    manager.update(programStageA);
    manager.update(programStageB);
    manager.update(programA);
    maleA = createTrackedEntityInstance('A', organisationUnitA);
    maleB = createTrackedEntityInstance(organisationUnitB);
    femaleA = createTrackedEntityInstance(organisationUnitA);
    femaleB = createTrackedEntityInstance(organisationUnitB);
    maleA.setTrackedEntityType(trackedEntityType);
    maleB.setTrackedEntityType(trackedEntityType);
    femaleA.setTrackedEntityType(trackedEntityType);
    femaleB.setTrackedEntityType(trackedEntityType);
    manager.save(maleA);
    manager.save(maleB);
    manager.save(femaleA);
    manager.save(femaleB);
    int testYear = Calendar.getInstance().get(Calendar.YEAR) - 1;
    Date dateMar20 = getDate(testYear, 3, 20);
    Date dateApr10 = getDate(testYear, 4, 10);
    ProgramInstance programInstance = programInstanceService.enrollTrackedEntityInstance(maleA, programA, dateMar20, dateApr10, organisationUnitA, "MNWZ6hnuhSX");
    programInstanceService.addProgramInstance(programInstance);
    trackedEntityProgramOwnerService.updateTrackedEntityProgramOwner(maleA.getUid(), programA.getUid(), organisationUnitA.getUid());
    manager.update(programA);
    User user = userService.getUser(USER_5);
    OrganisationUnit qfUVllTs6cS = organisationUnitService.getOrganisationUnit("QfUVllTs6cS");
    user.addOrganisationUnit(qfUVllTs6cS);
    user.addOrganisationUnit(organisationUnitA);
    User adminUser = userService.getUser(ADMIN_USER_UID);
    adminUser.addOrganisationUnit(organisationUnitA);
    Program p = programService.getProgram("prabcdefghA");
    p.addOrganisationUnit(qfUVllTs6cS);
    programService.updateProgram(p);
    manager.update(user);
    manager.update(adminUser);
}
Also used : ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement) TrackedEntityType(org.hisp.dhis.trackedentity.TrackedEntityType) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) User(org.hisp.dhis.user.User) Program(org.hisp.dhis.program.Program) ProgramInstance(org.hisp.dhis.program.ProgramInstance) Date(java.util.Date) HashSet(java.util.HashSet)

Example 47 with TrackedEntityType

use of org.hisp.dhis.trackedentity.TrackedEntityType in project dhis2-core by dhis2.

the class PreCheckDataRelationsValidationHookTest method verifyValidationFailsWhenEnrollmentAndProgramTeiTypeDontMatchAndTEIIsInPayload.

@Test
void verifyValidationFailsWhenEnrollmentAndProgramTeiTypeDontMatchAndTEIIsInPayload() {
    OrganisationUnit orgUnit = organisationUnit(ORG_UNIT_ID);
    when(ctx.getOrganisationUnit(ORG_UNIT_ID)).thenReturn(orgUnit);
    when(ctx.getProgram(PROGRAM_UID)).thenReturn(programWithRegistration(PROGRAM_UID, orgUnit, trackedEntityType(TEI_TYPE_ID)));
    when(ctx.getProgramWithOrgUnitsMap()).thenReturn(Collections.singletonMap(PROGRAM_UID, Collections.singletonList(ORG_UNIT_ID)));
    when(ctx.getTrackedEntityInstance(TEI_ID)).thenReturn(null);
    TrackedEntity trackedEntity = TrackedEntity.builder().trackedEntity(TEI_ID).trackedEntityType(ANOTHER_TEI_TYPE_ID).build();
    bundle.setTrackedEntities(Collections.singletonList(trackedEntity));
    Enrollment enrollment = Enrollment.builder().enrollment(CodeGenerator.generateUid()).program(PROGRAM_UID).orgUnit(ORG_UNIT_ID).trackedEntity(TEI_ID).build();
    hook.validateEnrollment(reporter, enrollment);
    assertTrue(reporter.hasErrorReport(r -> r.getErrorCode() == TrackerErrorCode.E1022));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) CategoryService(org.hisp.dhis.category.CategoryService) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) CategoryOption(org.hisp.dhis.category.CategoryOption) TrackerIdentifier(org.hisp.dhis.tracker.TrackerIdentifier) RelationshipConstraint(org.hisp.dhis.relationship.RelationshipConstraint) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) ProgramInstance(org.hisp.dhis.program.ProgramInstance) ReferenceTrackerEntity(org.hisp.dhis.tracker.preheat.ReferenceTrackerEntity) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) TrackedEntity(org.hisp.dhis.tracker.domain.TrackedEntity) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance) Category(org.hisp.dhis.category.Category) RelationshipItem(org.hisp.dhis.tracker.domain.RelationshipItem) TrackerBundle(org.hisp.dhis.tracker.bundle.TrackerBundle) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Test(org.junit.jupiter.api.Test) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) ProgramType(org.hisp.dhis.program.ProgramType) Optional(java.util.Optional) TrackedEntityType(org.hisp.dhis.trackedentity.TrackedEntityType) CategoryCombo(org.hisp.dhis.category.CategoryCombo) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) DataDimensionType(org.hisp.dhis.common.DataDimensionType) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Mock(org.mockito.Mock) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) Relationship(org.hisp.dhis.tracker.domain.Relationship) Program(org.hisp.dhis.program.Program) Enrollment(org.hisp.dhis.tracker.domain.Enrollment) TrackerIdentifierParams(org.hisp.dhis.tracker.TrackerIdentifierParams) TrackerImportValidationContext(org.hisp.dhis.tracker.validation.TrackerImportValidationContext) RelationshipType(org.hisp.dhis.relationship.RelationshipType) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) TRACKED_ENTITY_INSTANCE(org.hisp.dhis.relationship.RelationshipEntity.TRACKED_ENTITY_INSTANCE) RelationshipEntity(org.hisp.dhis.relationship.RelationshipEntity) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) Event(org.hisp.dhis.tracker.domain.Event) TrackerErrorReport(org.hisp.dhis.tracker.report.TrackerErrorReport) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) ProgramStage(org.hisp.dhis.program.ProgramStage) Mockito.verify(org.mockito.Mockito.verify) TrackerErrorCode(org.hisp.dhis.tracker.report.TrackerErrorCode) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) Matchers.hasItem(org.hamcrest.Matchers.hasItem) CodeGenerator(org.hisp.dhis.common.CodeGenerator) Collections(java.util.Collections) TrackerPreheat(org.hisp.dhis.tracker.preheat.TrackerPreheat) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) TrackedEntity(org.hisp.dhis.tracker.domain.TrackedEntity) Enrollment(org.hisp.dhis.tracker.domain.Enrollment) Test(org.junit.jupiter.api.Test) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Example 48 with TrackedEntityType

use of org.hisp.dhis.trackedentity.TrackedEntityType in project dhis2-core by dhis2.

the class PreCheckDataRelationsValidationHookTest method verifyValidationFailsWhenEnrollmentAndProgramTeiTypeDontMatch.

@Test
void verifyValidationFailsWhenEnrollmentAndProgramTeiTypeDontMatch() {
    OrganisationUnit orgUnit = organisationUnit(ORG_UNIT_ID);
    when(ctx.getOrganisationUnit(ORG_UNIT_ID)).thenReturn(orgUnit);
    when(ctx.getProgram(PROGRAM_UID)).thenReturn(programWithRegistration(PROGRAM_UID, orgUnit, trackedEntityType(TEI_TYPE_ID)));
    when(ctx.getProgramWithOrgUnitsMap()).thenReturn(Collections.singletonMap(PROGRAM_UID, Collections.singletonList(ORG_UNIT_ID)));
    TrackedEntityType anotherTrackedEntityType = trackedEntityType(TEI_ID, 'B');
    when(ctx.getTrackedEntityInstance(TEI_ID)).thenReturn(trackedEntityInstance(TEI_ID, anotherTrackedEntityType, orgUnit));
    Enrollment enrollment = Enrollment.builder().enrollment(CodeGenerator.generateUid()).program(PROGRAM_UID).orgUnit(ORG_UNIT_ID).trackedEntity(TEI_ID).build();
    hook.validateEnrollment(reporter, enrollment);
    assertTrue(reporter.hasErrorReport(r -> r.getErrorCode() == TrackerErrorCode.E1022));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) CategoryService(org.hisp.dhis.category.CategoryService) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) CategoryOption(org.hisp.dhis.category.CategoryOption) TrackerIdentifier(org.hisp.dhis.tracker.TrackerIdentifier) RelationshipConstraint(org.hisp.dhis.relationship.RelationshipConstraint) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) ProgramInstance(org.hisp.dhis.program.ProgramInstance) ReferenceTrackerEntity(org.hisp.dhis.tracker.preheat.ReferenceTrackerEntity) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) TrackedEntity(org.hisp.dhis.tracker.domain.TrackedEntity) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance) Category(org.hisp.dhis.category.Category) RelationshipItem(org.hisp.dhis.tracker.domain.RelationshipItem) TrackerBundle(org.hisp.dhis.tracker.bundle.TrackerBundle) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Test(org.junit.jupiter.api.Test) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) ProgramType(org.hisp.dhis.program.ProgramType) Optional(java.util.Optional) TrackedEntityType(org.hisp.dhis.trackedentity.TrackedEntityType) CategoryCombo(org.hisp.dhis.category.CategoryCombo) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) DataDimensionType(org.hisp.dhis.common.DataDimensionType) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Mock(org.mockito.Mock) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) Relationship(org.hisp.dhis.tracker.domain.Relationship) Program(org.hisp.dhis.program.Program) Enrollment(org.hisp.dhis.tracker.domain.Enrollment) TrackerIdentifierParams(org.hisp.dhis.tracker.TrackerIdentifierParams) TrackerImportValidationContext(org.hisp.dhis.tracker.validation.TrackerImportValidationContext) RelationshipType(org.hisp.dhis.relationship.RelationshipType) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) TRACKED_ENTITY_INSTANCE(org.hisp.dhis.relationship.RelationshipEntity.TRACKED_ENTITY_INSTANCE) RelationshipEntity(org.hisp.dhis.relationship.RelationshipEntity) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) Event(org.hisp.dhis.tracker.domain.Event) TrackerErrorReport(org.hisp.dhis.tracker.report.TrackerErrorReport) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) ProgramStage(org.hisp.dhis.program.ProgramStage) Mockito.verify(org.mockito.Mockito.verify) TrackerErrorCode(org.hisp.dhis.tracker.report.TrackerErrorCode) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) Matchers.hasItem(org.hamcrest.Matchers.hasItem) CodeGenerator(org.hisp.dhis.common.CodeGenerator) Collections(java.util.Collections) TrackerPreheat(org.hisp.dhis.tracker.preheat.TrackerPreheat) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) TrackedEntityType(org.hisp.dhis.trackedentity.TrackedEntityType) Enrollment(org.hisp.dhis.tracker.domain.Enrollment) Test(org.junit.jupiter.api.Test) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Example 49 with TrackedEntityType

use of org.hisp.dhis.trackedentity.TrackedEntityType in project dhis2-core by dhis2.

the class PreCheckUpdatableFieldsValidationHookTest method trackedEntityInstance.

private TrackedEntityInstance trackedEntityInstance() {
    TrackedEntityType trackedEntityType = new TrackedEntityType();
    trackedEntityType.setUid(TRACKED_ENTITY_TYPE_ID);
    TrackedEntityInstance trackedEntityInstance = new TrackedEntityInstance();
    trackedEntityInstance.setUid(TRACKED_ENTITY_ID);
    trackedEntityInstance.setTrackedEntityType(trackedEntityType);
    return trackedEntityInstance;
}
Also used : TrackedEntityType(org.hisp.dhis.trackedentity.TrackedEntityType) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance)

Example 50 with TrackedEntityType

use of org.hisp.dhis.trackedentity.TrackedEntityType in project dhis2-core by dhis2.

the class TrackedEntityAttributeValidationHookTest method shouldPassValidation.

@Test
void shouldPassValidation() {
    TrackedEntityAttribute trackedEntityAttribute = new TrackedEntityAttribute();
    trackedEntityAttribute.setUid("uid");
    trackedEntityAttribute.setValueType(ValueType.TEXT);
    when(validationContext.getTrackedEntityAttribute(anyString())).thenReturn(trackedEntityAttribute);
    when(validationContext.getTrackedEntityType(anyString())).thenReturn(new TrackedEntityType());
    TrackedEntity trackedEntity = TrackedEntity.builder().attributes(Collections.singletonList(Attribute.builder().attribute("uid").value("value").build())).trackedEntityType("trackedEntityType").build();
    ValidationErrorReporter reporter = new ValidationErrorReporter(validationContext);
    trackedEntityAttributeValidationHook.validateTrackedEntity(reporter, trackedEntity);
    assertFalse(reporter.hasErrors());
    assertEquals(0, reporter.getReportList().size());
}
Also used : TrackedEntityType(org.hisp.dhis.trackedentity.TrackedEntityType) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) TrackedEntity(org.hisp.dhis.tracker.domain.TrackedEntity) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) Test(org.junit.jupiter.api.Test)

Aggregations

TrackedEntityType (org.hisp.dhis.trackedentity.TrackedEntityType)57 Test (org.junit.jupiter.api.Test)27 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)22 Program (org.hisp.dhis.program.Program)19 ValidationErrorReporter (org.hisp.dhis.tracker.report.ValidationErrorReporter)16 User (org.hisp.dhis.user.User)16 TrackedEntityInstance (org.hisp.dhis.trackedentity.TrackedEntityInstance)15 TrackedEntity (org.hisp.dhis.tracker.domain.TrackedEntity)15 TrackedEntityAttribute (org.hisp.dhis.trackedentity.TrackedEntityAttribute)12 ProgramInstance (org.hisp.dhis.program.ProgramInstance)11 Date (java.util.Date)10 HashSet (java.util.HashSet)10 ProgramStage (org.hisp.dhis.program.ProgramStage)8 CategoryCombo (org.hisp.dhis.category.CategoryCombo)6 ProgramStageDataElement (org.hisp.dhis.program.ProgramStageDataElement)6 RelationshipType (org.hisp.dhis.relationship.RelationshipType)6 TrackedEntityTypeAttribute (org.hisp.dhis.trackedentity.TrackedEntityTypeAttribute)6 Collectors (java.util.stream.Collectors)5 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)5 CategoryOption (org.hisp.dhis.category.CategoryOption)5