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);
}
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);
}
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());
}
}
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);
}
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);
}
}
Aggregations