Search in sources :

Example 46 with Program

use of org.hisp.dhis.program.Program in project dhis2-core by dhis2.

the class DefaultTrackerOwnershipManager method hasAccessUsingContext.

@Override
@Transactional(readOnly = true)
public boolean hasAccessUsingContext(User user, String trackedEntityInstanceUid, String programUid, EventContext eventContext) {
    Program program = eventContext.getProgramsByUid().get(programUid);
    if (canSkipOwnershipCheck(user, program)) {
        return true;
    }
    EventContext.TrackedEntityOuInfo trackedEntityOuInfo = eventContext.getTrackedEntityOuInfoByUid().get(trackedEntityInstanceUid);
    if (trackedEntityOuInfo == null) {
        return true;
    }
    OrganisationUnit ou = Optional.ofNullable(eventContext.getOrgUnitByTeiUidAndProgramUidPairs().get(Pair.of(trackedEntityInstanceUid, programUid))).map(organisationUnitUid -> eventContext.getOrgUnitsByUid().get(organisationUnitUid)).orElseGet(() -> organisationUnitService.getOrganisationUnit(trackedEntityOuInfo.getOrgUnitId()));
    if (program.isOpen() || program.isAudited()) {
        return organisationUnitService.isInUserSearchHierarchyCached(user, ou);
    } else {
        return organisationUnitService.isInUserHierarchyCached(user, ou) || hasTemporaryAccess(trackedEntityOuInfo, program, user);
    }
}
Also used : EventContext(org.hisp.dhis.dxf2.events.event.EventContext) LongSupplier(java.util.function.LongSupplier) OrganisationUnitService(org.hisp.dhis.organisationunit.OrganisationUnitService) EventContext(org.hisp.dhis.dxf2.events.event.EventContext) ProgramTempOwner(org.hisp.dhis.program.ProgramTempOwner) Supplier(java.util.function.Supplier) Program(org.hisp.dhis.program.Program) ProgramOwnershipHistoryService(org.hisp.dhis.program.ProgramOwnershipHistoryService) Pair(org.apache.commons.lang3.tuple.Pair) CurrentUserServiceTarget(org.hisp.dhis.user.CurrentUserServiceTarget) Service(org.springframework.stereotype.Service) User(org.hisp.dhis.user.User) ProgramTempOwnerService(org.hisp.dhis.program.ProgramTempOwnerService) CHANGELOG_TRACKER(org.hisp.dhis.external.conf.ConfigurationKey.CHANGELOG_TRACKER) ProgramOwnershipHistory(org.hisp.dhis.program.ProgramOwnershipHistory) DhisConfigurationProvider(org.hisp.dhis.external.conf.DhisConfigurationProvider) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) ProgramTempOwnershipAuditService(org.hisp.dhis.program.ProgramTempOwnershipAuditService) AccessDeniedException(org.springframework.security.access.AccessDeniedException) CacheProvider(org.hisp.dhis.cache.CacheProvider) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) Slf4j(lombok.extern.slf4j.Slf4j) CurrentUserService(org.hisp.dhis.user.CurrentUserService) Environment(org.springframework.core.env.Environment) Cache(org.hisp.dhis.cache.Cache) ProgramType(org.hisp.dhis.program.ProgramType) Optional(java.util.Optional) Hibernate(org.hibernate.Hibernate) ProgramTempOwnershipAudit(org.hisp.dhis.program.ProgramTempOwnershipAudit) Transactional(org.springframework.transaction.annotation.Transactional) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) Program(org.hisp.dhis.program.Program) Transactional(org.springframework.transaction.annotation.Transactional)

Example 47 with Program

use of org.hisp.dhis.program.Program in project dhis2-core by dhis2.

the class TrackedEntityRegistrationSMSListener method postProcess.

// -------------------------------------------------------------------------
// IncomingSmsListener implementation
// -------------------------------------------------------------------------
@Override
protected void postProcess(IncomingSms sms, SMSCommand smsCommand, Map<String, String> parsedMessage) {
    String message = sms.getText();
    Date date = SmsUtils.lookForDate(message);
    String senderPhoneNumber = StringUtils.replace(sms.getOriginator(), "+", "");
    Collection<OrganisationUnit> orgUnits = getOrganisationUnits(sms);
    Program program = smsCommand.getProgram();
    OrganisationUnit orgUnit = SmsUtils.selectOrganisationUnit(orgUnits, parsedMessage, smsCommand);
    if (!programService.hasOrgUnit(program, orgUnit)) {
        sendFeedback(SMSCommand.NO_OU_FOR_PROGRAM, senderPhoneNumber, WARNING);
        throw new SMSParserException(SMSCommand.NO_OU_FOR_PROGRAM);
    }
    TrackedEntityInstance trackedEntityInstance = new TrackedEntityInstance();
    trackedEntityInstance.setOrganisationUnit(orgUnit);
    trackedEntityInstance.setTrackedEntityType(trackedEntityTypeService.getTrackedEntityByName(smsCommand.getProgram().getTrackedEntityType().getName()));
    Set<TrackedEntityAttributeValue> patientAttributeValues = new HashSet<>();
    smsCommand.getCodes().stream().filter(code -> parsedMessage.containsKey(code.getCode())).forEach(code -> {
        TrackedEntityAttributeValue trackedEntityAttributeValue = this.createTrackedEntityAttributeValue(parsedMessage, code, trackedEntityInstance);
        patientAttributeValues.add(trackedEntityAttributeValue);
    });
    long trackedEntityInstanceId = 0;
    if (patientAttributeValues.size() > 0) {
        trackedEntityInstanceId = trackedEntityInstanceService.createTrackedEntityInstance(trackedEntityInstance, patientAttributeValues);
    } else {
        sendFeedback("No TrackedEntityAttribute found", senderPhoneNumber, WARNING);
    }
    TrackedEntityInstance tei = trackedEntityInstanceService.getTrackedEntityInstance(trackedEntityInstanceId);
    programInstanceService.enrollTrackedEntityInstance(tei, smsCommand.getProgram(), new Date(), date, orgUnit);
    sendFeedback(StringUtils.defaultIfBlank(smsCommand.getSuccessMessage(), SUCCESS_MESSAGE + tei.getUid()), senderPhoneNumber, INFO);
    update(sms, SmsMessageStatus.PROCESSED, true);
}
Also used : MessageSender(org.hisp.dhis.message.MessageSender) CategoryService(org.hisp.dhis.category.CategoryService) TrackedEntityTypeService(org.hisp.dhis.trackedentity.TrackedEntityTypeService) Date(java.util.Date) TrackedEntityAttributeValue(org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue) StringUtils(org.apache.commons.lang3.StringUtils) Program(org.hisp.dhis.program.Program) HashSet(java.util.HashSet) ProgramStageInstanceService(org.hisp.dhis.program.ProgramStageInstanceService) SmsMessageStatus(org.hisp.dhis.sms.incoming.SmsMessageStatus) SMSParserException(org.hisp.dhis.sms.parse.SMSParserException) Map(java.util.Map) Qualifier(org.springframework.beans.factory.annotation.Qualifier) IncomingSmsService(org.hisp.dhis.sms.incoming.IncomingSmsService) ParserType(org.hisp.dhis.sms.parse.ParserType) SmsUtils(org.hisp.dhis.system.util.SmsUtils) UserService(org.hisp.dhis.user.UserService) Collection(java.util.Collection) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance) Set(java.util.Set) IncomingSms(org.hisp.dhis.sms.incoming.IncomingSms) TrackedEntityInstanceService(org.hisp.dhis.trackedentity.TrackedEntityInstanceService) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) Component(org.springframework.stereotype.Component) SMSCommandService(org.hisp.dhis.sms.command.SMSCommandService) CurrentUserService(org.hisp.dhis.user.CurrentUserService) ProgramInstanceService(org.hisp.dhis.program.ProgramInstanceService) SMSCode(org.hisp.dhis.sms.command.code.SMSCode) ProgramService(org.hisp.dhis.program.ProgramService) SMSCommand(org.hisp.dhis.sms.command.SMSCommand) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) Transactional(org.springframework.transaction.annotation.Transactional) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) Program(org.hisp.dhis.program.Program) SMSParserException(org.hisp.dhis.sms.parse.SMSParserException) TrackedEntityAttributeValue(org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance) Date(java.util.Date) HashSet(java.util.HashSet)

Example 48 with Program

use of org.hisp.dhis.program.Program in project dhis2-core by dhis2.

the class DefaultTrackedEntityProgramOwnerService method createOrUpdateTrackedEntityProgramOwner.

@Override
@Transactional
public void createOrUpdateTrackedEntityProgramOwner(String teiUid, String programUid, String orgUnitUid) {
    TrackedEntityInstance entityInstance = trackedEntityInstanceService.getTrackedEntityInstance(teiUid);
    Program program = programService.getProgram(programUid);
    if (entityInstance == null) {
        return;
    }
    TrackedEntityProgramOwner teiProgramOwner = trackedEntityProgramOwnerStore.getTrackedEntityProgramOwner(entityInstance.getId(), program.getId());
    OrganisationUnit ou = orgUnitService.getOrganisationUnit(orgUnitUid);
    if (ou == null) {
        return;
    }
    if (teiProgramOwner == null) {
        trackedEntityProgramOwnerStore.save(buildTrackedEntityProgramOwner(entityInstance, program, ou));
    } else {
        teiProgramOwner = updateTrackedEntityProgramOwner(teiProgramOwner, ou);
        trackedEntityProgramOwnerStore.update(teiProgramOwner);
    }
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) Program(org.hisp.dhis.program.Program) Transactional(org.springframework.transaction.annotation.Transactional)

Example 49 with Program

use of org.hisp.dhis.program.Program in project dhis2-core by dhis2.

the class DefaultTrackedEntityProgramOwnerService method createTrackedEntityProgramOwner.

@Override
@Transactional
public void createTrackedEntityProgramOwner(String teiUid, String programUid, String orgUnitUid) {
    TrackedEntityInstance entityInstance = trackedEntityInstanceService.getTrackedEntityInstance(teiUid);
    if (entityInstance == null) {
        return;
    }
    Program program = programService.getProgram(programUid);
    if (program == null) {
        return;
    }
    OrganisationUnit ou = orgUnitService.getOrganisationUnit(orgUnitUid);
    if (ou == null) {
        return;
    }
    trackedEntityProgramOwnerStore.save(buildTrackedEntityProgramOwner(entityInstance, program, ou));
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) Program(org.hisp.dhis.program.Program) Transactional(org.springframework.transaction.annotation.Transactional)

Example 50 with Program

use of org.hisp.dhis.program.Program in project dhis2-core by dhis2.

the class DefaultTrackedEntityProgramOwnerService method updateTrackedEntityProgramOwner.

@Override
@Transactional
public void updateTrackedEntityProgramOwner(String teiUid, String programUid, String orgUnitUid) {
    TrackedEntityInstance entityInstance = trackedEntityInstanceService.getTrackedEntityInstance(teiUid);
    if (entityInstance == null) {
        return;
    }
    Program program = programService.getProgram(programUid);
    if (program == null) {
        return;
    }
    TrackedEntityProgramOwner teProgramOwner = trackedEntityProgramOwnerStore.getTrackedEntityProgramOwner(entityInstance.getId(), program.getId());
    if (teProgramOwner == null) {
        return;
    }
    OrganisationUnit ou = orgUnitService.getOrganisationUnit(orgUnitUid);
    if (ou == null) {
        return;
    }
    teProgramOwner = updateTrackedEntityProgramOwner(teProgramOwner, ou);
    trackedEntityProgramOwnerStore.update(teProgramOwner);
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) Program(org.hisp.dhis.program.Program) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Program (org.hisp.dhis.program.Program)344 Test (org.junit.jupiter.api.Test)160 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)123 ProgramStage (org.hisp.dhis.program.ProgramStage)109 ProgramInstance (org.hisp.dhis.program.ProgramInstance)79 TrackedEntityInstance (org.hisp.dhis.trackedentity.TrackedEntityInstance)68 Date (java.util.Date)47 Collectors (java.util.stream.Collectors)44 User (org.hisp.dhis.user.User)44 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)42 TrackedEntityType (org.hisp.dhis.trackedentity.TrackedEntityType)42 BeforeEach (org.junit.jupiter.api.BeforeEach)42 TrackedEntityAttribute (org.hisp.dhis.trackedentity.TrackedEntityAttribute)41 ValidationErrorReporter (org.hisp.dhis.tracker.report.ValidationErrorReporter)41 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)40 DhisConvenienceTest.createProgram (org.hisp.dhis.DhisConvenienceTest.createProgram)39 CategoryCombo (org.hisp.dhis.category.CategoryCombo)39 DataElement (org.hisp.dhis.dataelement.DataElement)39 Event (org.hisp.dhis.tracker.domain.Event)38 Enrollment (org.hisp.dhis.tracker.domain.Enrollment)37