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