Search in sources :

Example 41 with TrackedEntityType

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

the class RelationshipTrackerConverterServiceTest method setUpTest.

@Override
protected void setUpTest() throws IOException {
    preCreateInjectAdminUserWithoutPersistence();
    renderService = _renderService;
    userService = _userService;
    TrackedEntityType trackedEntityType = createTrackedEntityType('A');
    trackedEntityTypeService.addTrackedEntityType(trackedEntityType);
    Program program = createProgram('A');
    programService.addProgram(program);
    ProgramStage programStage = createProgramStage('A', program);
    programStageService.saveProgramStage(programStage);
    TrackedEntityAttribute trackedEntityAttribute = createTrackedEntityAttribute('A');
    OrganisationUnit organisationUnit = createOrganisationUnit('A');
    organisationUnitService.addOrganisationUnit(organisationUnit);
    TrackedEntityInstance trackedEntityInstance = createTrackedEntityInstance('A', organisationUnit, trackedEntityAttribute);
    trackedEntityInstance.setUid(TEI);
    ProgramInstance programInstance = new ProgramInstance();
    programInstance.setEnrollmentDate(new Date());
    programInstance.setProgram(program);
    programInstance.setUid(ENROLLMENT);
    ProgramStageInstance programStageInstance = new ProgramStageInstance();
    programStageInstance.setUid(EVENT);
    programStageInstance.setProgramInstance(programInstance);
    programStageInstance.setProgramStage(programStage);
    trackedEntityInstanceService.addTrackedEntityInstance(trackedEntityInstance);
    programInstanceService.addProgramInstance(programInstance);
    programStageInstanceService.addProgramStageInstance(programStageInstance);
    RelationshipType relationshipTypeA = createTeiToEnrollmentRelationshipType('A', program, trackedEntityType, false);
    relationshipTypeA.setUid(TEI_TO_ENROLLMENT_RELATIONSHIP_TYPE);
    RelationshipType relationshipTypeB = createTeiToEventRelationshipType('B', program, trackedEntityType, false);
    relationshipTypeB.setUid(TEI_TO_EVENT_RELATIONSHIP_TYPE);
    relationshipTypeService.addRelationshipType(relationshipTypeA);
    relationshipTypeService.addRelationshipType(relationshipTypeB);
    TrackerImportParams trackerImportParams = renderService.fromJson(new ClassPathResource("tracker/relationships.json").getInputStream(), TrackerImportParams.class);
    User adminUser = createAndInjectAdminUser();
    trackerImportParams.setUser(adminUser);
    trackerBundle = trackerBundleService.create(trackerImportParams);
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) Program(org.hisp.dhis.program.Program) User(org.hisp.dhis.user.User) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) ProgramInstance(org.hisp.dhis.program.ProgramInstance) RelationshipType(org.hisp.dhis.relationship.RelationshipType) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance) Date(java.util.Date) ClassPathResource(org.springframework.core.io.ClassPathResource) TrackedEntityType(org.hisp.dhis.trackedentity.TrackedEntityType) TrackerImportParams(org.hisp.dhis.tracker.TrackerImportParams) ProgramStage(org.hisp.dhis.program.ProgramStage) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance)

Example 42 with TrackedEntityType

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

the class TrackerPreheatServiceIntegration method setUpTest.

@Override
public void setUpTest() throws Exception {
    userService = _userService;
    // Set up placeholder OU; We add Code for testing idScheme.
    OrganisationUnit ouA = createOrganisationUnit('A');
    ouA.setCode("OUA");
    organisationUnitService.addOrganisationUnit(ouA);
    // Set up placeholder TET
    TrackedEntityType tetA = createTrackedEntityType('A');
    tetA.setUid(TET_UID);
    trackedEntityTypeService.addTrackedEntityType(tetA);
    // Set up attribute for program, to be used for testing idScheme.
    Attribute attributeA = createAttribute('A');
    attributeA.setUid(ATTRIBUTE_UID);
    attributeA.setUnique(true);
    attributeA.setProgramAttribute(true);
    attributeService.addAttribute(attributeA);
    // Set up placeholder Program, with attributeValue
    Program programA = createProgram('A');
    programA.addOrganisationUnit(ouA);
    programA.setTrackedEntityType(tetA);
    programA.setProgramType(ProgramType.WITH_REGISTRATION);
    programA.setAttributeValues(Sets.newHashSet(new AttributeValue("PROGRAM1", attributeA)));
    programService.addProgram(programA);
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) TrackedEntityType(org.hisp.dhis.trackedentity.TrackedEntityType) AttributeValue(org.hisp.dhis.attribute.AttributeValue) Program(org.hisp.dhis.program.Program) Attribute(org.hisp.dhis.attribute.Attribute)

Example 43 with TrackedEntityType

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

the class PreCheckMetaValidationHook method validateTrackedEntity.

@Override
public void validateTrackedEntity(ValidationErrorReporter reporter, TrackedEntity tei) {
    TrackerImportValidationContext context = reporter.getValidationContext();
    OrganisationUnit organisationUnit = context.getOrganisationUnit(tei.getOrgUnit());
    if (organisationUnit == null) {
        reporter.addError(tei, TrackerErrorCode.E1049, tei.getOrgUnit());
    }
    TrackedEntityType entityType = context.getTrackedEntityType(tei.getTrackedEntityType());
    if (entityType == null) {
        reporter.addError(tei, E1005, tei.getTrackedEntityType());
    }
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) TrackedEntityType(org.hisp.dhis.trackedentity.TrackedEntityType) TrackerImportValidationContext(org.hisp.dhis.tracker.validation.TrackerImportValidationContext)

Example 44 with TrackedEntityType

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

the class TrackedEntityAttributeValidationHook method validateTrackedEntity.

@Override
public void validateTrackedEntity(ValidationErrorReporter reporter, TrackedEntity trackedEntity) {
    TrackedEntityType trackedEntityType = reporter.getValidationContext().getTrackedEntityType(trackedEntity.getTrackedEntityType());
    TrackerImportValidationContext context = reporter.getValidationContext();
    TrackedEntityInstance tei = context.getTrackedEntityInstance(trackedEntity.getTrackedEntity());
    OrganisationUnit organisationUnit = context.getOrganisationUnit(trackedEntity.getOrgUnit());
    validateMandatoryAttributes(reporter, trackedEntity, trackedEntityType);
    validateAttributes(reporter, trackedEntity, tei, organisationUnit, trackedEntityType);
}
Also used : TrackedEntityType(org.hisp.dhis.trackedentity.TrackedEntityType) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) TrackerImportValidationContext(org.hisp.dhis.tracker.validation.TrackerImportValidationContext) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance)

Example 45 with TrackedEntityType

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

the class TrackedEntityAttributeValidationHook method validateAttributes.

protected void validateAttributes(ValidationErrorReporter reporter, TrackedEntity trackedEntity, TrackedEntityInstance tei, OrganisationUnit orgUnit, TrackedEntityType trackedEntityType) {
    checkNotNull(trackedEntity, TrackerImporterAssertErrors.TRACKED_ENTITY_CANT_BE_NULL);
    checkNotNull(trackedEntityType, TrackerImporterAssertErrors.TRACKED_ENTITY_TYPE_CANT_BE_NULL);
    Map<String, TrackedEntityAttributeValue> valueMap = new HashMap<>();
    if (tei != null) {
        valueMap = tei.getTrackedEntityAttributeValues().stream().collect(Collectors.toMap(v -> v.getAttribute().getUid(), v -> v));
    }
    for (Attribute attribute : trackedEntity.getAttributes()) {
        TrackedEntityAttribute tea = reporter.getValidationContext().getTrackedEntityAttribute(attribute.getAttribute());
        if (tea == null) {
            reporter.addError(trackedEntity, E1006, attribute.getAttribute());
            continue;
        }
        if (attribute.getValue() == null) {
            Optional<TrackedEntityTypeAttribute> optionalTea = Optional.of(trackedEntityType).map(tet -> tet.getTrackedEntityTypeAttributes().stream()).flatMap(tetAtts -> tetAtts.filter(teaAtt -> teaAtt.getTrackedEntityAttribute().getUid().equals(attribute.getAttribute()) && teaAtt.isMandatory() != null && teaAtt.isMandatory()).findFirst());
            if (optionalTea.isPresent())
                reporter.addError(trackedEntity, E1076, TrackedEntityAttribute.class.getSimpleName(), attribute.getAttribute());
            continue;
        }
        validateAttributeValue(reporter, trackedEntity, tea, attribute.getValue());
        validateAttrValueType(reporter, trackedEntity, attribute, tea);
        validateOptionSet(reporter, trackedEntity, tea, attribute.getValue());
        validateAttributeUniqueness(reporter, trackedEntity, attribute.getValue(), tea, tei, orgUnit);
        validateFileNotAlreadyAssigned(reporter, trackedEntity, attribute, valueMap);
    }
}
Also used : Attribute(org.hisp.dhis.tracker.domain.Attribute) Constant(org.hisp.dhis.tracker.util.Constant) HashMap(java.util.HashMap) TrackedEntityAttributeValue(org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) E1084(org.hisp.dhis.tracker.report.TrackerErrorCode.E1084) E1085(org.hisp.dhis.tracker.report.TrackerErrorCode.E1085) TRACKED_ENTITY_ATTRIBUTE_VALUE_CANT_BE_NULL(org.hisp.dhis.tracker.validation.hooks.TrackerImporterAssertErrors.TRACKED_ENTITY_ATTRIBUTE_VALUE_CANT_BE_NULL) TrackerImportValidationContext(org.hisp.dhis.tracker.validation.TrackerImportValidationContext) Map(java.util.Map) E1090(org.hisp.dhis.tracker.report.TrackerErrorCode.E1090) ATTRIBUTE_CANT_BE_NULL(org.hisp.dhis.tracker.validation.hooks.TrackerImporterAssertErrors.ATTRIBUTE_CANT_BE_NULL) BaseIdentifiableObject(org.hisp.dhis.common.BaseIdentifiableObject) DhisConfigurationProvider(org.hisp.dhis.external.conf.DhisConfigurationProvider) FileResource(org.hisp.dhis.fileresource.FileResource) TrackedEntity(org.hisp.dhis.tracker.domain.TrackedEntity) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) E1077(org.hisp.dhis.tracker.report.TrackerErrorCode.E1077) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance) E1076(org.hisp.dhis.tracker.report.TrackerErrorCode.E1076) Set(java.util.Set) E1112(org.hisp.dhis.tracker.report.TrackerErrorCode.E1112) TrackedAttributeValidationService(org.hisp.dhis.tracker.validation.service.attribute.TrackedAttributeValidationService) Collectors(java.util.stream.Collectors) TrackedEntityTypeAttribute(org.hisp.dhis.trackedentity.TrackedEntityTypeAttribute) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) ValidationUtils.dataValueIsValid(org.hisp.dhis.system.util.ValidationUtils.dataValueIsValid) Component(org.springframework.stereotype.Component) E1009(org.hisp.dhis.tracker.report.TrackerErrorCode.E1009) E1006(org.hisp.dhis.tracker.report.TrackerErrorCode.E1006) Optional(java.util.Optional) TrackedEntityType(org.hisp.dhis.trackedentity.TrackedEntityType) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) HashMap(java.util.HashMap) Attribute(org.hisp.dhis.tracker.domain.Attribute) TrackedEntityTypeAttribute(org.hisp.dhis.trackedentity.TrackedEntityTypeAttribute) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) TrackedEntityAttributeValue(org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue) TrackedEntityTypeAttribute(org.hisp.dhis.trackedentity.TrackedEntityTypeAttribute)

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