use of org.hisp.dhis.category.CategoryOptionCombo in project dhis2-core by dhis2.
the class J2MEDataValueSMSListener method registerCompleteDataSet.
private void registerCompleteDataSet(DataSet dataSet, Period period, OrganisationUnit organisationUnit, String storedBy) {
// TODO
CategoryOptionCombo optionCombo = dataElementCategoryService.getDefaultCategoryOptionCombo();
if (registrationService.getCompleteDataSetRegistration(dataSet, period, organisationUnit, optionCombo) == null) {
Date now = new Date();
CompleteDataSetRegistration registration = new CompleteDataSetRegistration(dataSet, period, organisationUnit, optionCombo, now, storedBy, now, storedBy, true);
registration.setPeriodName(registration.getPeriod().toString());
registrationService.saveCompleteDataSetRegistration(registration);
}
}
use of org.hisp.dhis.category.CategoryOptionCombo in project dhis2-core by dhis2.
the class J2MEDataValueSMSListener method storeDataValue.
private void storeDataValue(IncomingSms sms, OrganisationUnit orgUnit, Map<String, String> parsedMessage, SMSCode code, SMSCommand command, Period period) {
String upperCaseCode = code.getCode().toUpperCase();
String sender = sms.getOriginator();
String storedBy = SmsUtils.getUser(sender, command, Collections.singletonList(getUser(sms))).getUsername();
if (StringUtils.isBlank(storedBy)) {
storedBy = "[unknown] from [" + sender + "]";
}
CategoryOptionCombo optionCombo = dataElementCategoryService.getCategoryOptionCombo(code.getOptionId().getId());
DataValue dv = dataValueService.getDataValue(code.getDataElement(), period, orgUnit, optionCombo);
String value = parsedMessage.get(upperCaseCode);
if (!StringUtils.isEmpty(value)) {
boolean newDataValue = false;
if (dv == null) {
dv = new DataValue();
dv.setCategoryOptionCombo(optionCombo);
dv.setSource(orgUnit);
dv.setDataElement(code.getDataElement());
dv.setPeriod(period);
dv.setComment("");
newDataValue = true;
}
if (ValueType.BOOLEAN == dv.getDataElement().getValueType()) {
if ("Y".equals(value.toUpperCase()) || "YES".equals(value.toUpperCase())) {
value = "true";
} else if ("N".equals(value.toUpperCase()) || "NO".equals(value.toUpperCase())) {
value = "false";
}
}
dv.setValue(value);
dv.setLastUpdated(new java.util.Date());
dv.setStoredBy(storedBy);
if (ValidationUtils.dataValueIsValid(value, dv.getDataElement()) != null) {
// not a valid value for data element
return;
}
if (newDataValue) {
dataValueService.addDataValue(dv);
} else {
dataValueService.updateDataValue(dv);
}
}
}
use of org.hisp.dhis.category.CategoryOptionCombo in project dhis2-core by dhis2.
the class J2MEDataValueSMSListener method sendSuccessFeedback.
private void sendSuccessFeedback(String sender, SMSCommand command, Map<String, String> parsedMessage, Period period, OrganisationUnit orgunit) {
String reportBack = "Thank you! Values entered: ";
String notInReport = "Missing values for: ";
boolean missingElements = false;
for (SMSCode code : command.getCodes()) {
CategoryOptionCombo optionCombo = dataElementCategoryService.getCategoryOptionCombo(code.getOptionId().getId());
DataValue dv = dataValueService.getDataValue(code.getDataElement(), period, orgunit, optionCombo);
if (dv == null && !StringUtils.isEmpty(code.getCode())) {
notInReport += code.getCode() + ",";
missingElements = true;
} else if (dv != null) {
String value = dv.getValue();
if (ValueType.BOOLEAN == dv.getDataElement().getValueType()) {
if ("true".equals(value)) {
value = "Yes";
} else if ("false".equals(value)) {
value = "No";
}
}
reportBack += code.getCode() + "=" + value + " ";
}
}
notInReport = notInReport.substring(0, notInReport.length() - 1);
if (missingElements) {
reportBack += notInReport;
}
if (command.getSuccessMessage() != null && !StringUtils.isEmpty(command.getSuccessMessage())) {
reportBack = command.getSuccessMessage();
}
smsSender.sendMessage(null, reportBack, sender);
}
use of org.hisp.dhis.category.CategoryOptionCombo in project dhis2-core by dhis2.
the class AbstractEventService method getEvent.
@Transactional(readOnly = true)
@Override
public Event getEvent(ProgramStageInstance programStageInstance, boolean isSynchronizationQuery, boolean skipOwnershipCheck) {
if (programStageInstance == null) {
return null;
}
Event event = new Event();
event.setEvent(programStageInstance.getUid());
if (programStageInstance.getProgramInstance().getEntityInstance() != null) {
event.setTrackedEntityInstance(programStageInstance.getProgramInstance().getEntityInstance().getUid());
}
event.setFollowup(programStageInstance.getProgramInstance().getFollowup());
event.setEnrollmentStatus(EnrollmentStatus.fromProgramStatus(programStageInstance.getProgramInstance().getStatus()));
event.setStatus(programStageInstance.getStatus());
event.setEventDate(DateUtils.getIso8601NoTz(programStageInstance.getExecutionDate()));
event.setDueDate(DateUtils.getIso8601NoTz(programStageInstance.getDueDate()));
event.setStoredBy(programStageInstance.getStoredBy());
event.setCompletedBy(programStageInstance.getCompletedBy());
event.setCompletedDate(DateUtils.getIso8601NoTz(programStageInstance.getCompletedDate()));
event.setCreated(DateUtils.getIso8601NoTz(programStageInstance.getCreated()));
event.setCreatedByUserInfo(programStageInstance.getCreatedByUserInfo());
event.setLastUpdatedByUserInfo(programStageInstance.getLastUpdatedByUserInfo());
event.setCreatedAtClient(DateUtils.getIso8601NoTz(programStageInstance.getCreatedAtClient()));
event.setLastUpdated(DateUtils.getIso8601NoTz(programStageInstance.getLastUpdated()));
event.setLastUpdatedAtClient(DateUtils.getIso8601NoTz(programStageInstance.getLastUpdatedAtClient()));
event.setGeometry(programStageInstance.getGeometry());
event.setDeleted(programStageInstance.isDeleted());
if (programStageInstance.getAssignedUser() != null) {
event.setAssignedUser(programStageInstance.getAssignedUser().getUid());
event.setAssignedUserUsername(programStageInstance.getAssignedUser().getUsername());
event.setAssignedUserDisplayName(programStageInstance.getAssignedUser().getName());
}
User user = currentUserService.getCurrentUser();
OrganisationUnit ou = programStageInstance.getOrganisationUnit();
List<String> errors = trackerAccessManager.canRead(user, programStageInstance, skipOwnershipCheck);
if (!errors.isEmpty()) {
throw new IllegalQueryException(errors.toString());
}
if (ou != null) {
event.setOrgUnit(ou.getUid());
event.setOrgUnitName(ou.getName());
}
Program program = programStageInstance.getProgramInstance().getProgram();
event.setProgram(program.getUid());
event.setEnrollment(programStageInstance.getProgramInstance().getUid());
event.setProgramStage(programStageInstance.getProgramStage().getUid());
CategoryOptionCombo attributeOptionCombo = programStageInstance.getAttributeOptionCombo();
if (attributeOptionCombo != null) {
event.setAttributeOptionCombo(attributeOptionCombo.getUid());
event.setAttributeCategoryOptions(String.join(";", attributeOptionCombo.getCategoryOptions().stream().map(CategoryOption::getUid).collect(Collectors.toList())));
}
if (programStageInstance.getProgramInstance().getEntityInstance() != null) {
event.setTrackedEntityInstance(programStageInstance.getProgramInstance().getEntityInstance().getUid());
}
Collection<EventDataValue> dataValues;
if (!isSynchronizationQuery) {
dataValues = programStageInstance.getEventDataValues();
} else {
Set<String> dataElementsToSync = programStageInstance.getProgramStage().getProgramStageDataElements().stream().filter(psde -> !psde.getSkipSynchronization()).map(psde -> psde.getDataElement().getUid()).collect(Collectors.toSet());
dataValues = programStageInstance.getEventDataValues().stream().filter(dv -> dataElementsToSync.contains(dv.getDataElement())).collect(Collectors.toSet());
}
for (EventDataValue dataValue : dataValues) {
if (getDataElement(user.getUid(), dataValue.getDataElement())) {
DataValue value = new DataValue();
value.setCreated(DateUtils.getIso8601NoTz(dataValue.getCreated()));
value.setCreatedByUserInfo(dataValue.getCreatedByUserInfo());
value.setLastUpdated(DateUtils.getIso8601NoTz(dataValue.getLastUpdated()));
value.setLastUpdatedByUserInfo(dataValue.getLastUpdatedByUserInfo());
value.setDataElement(dataValue.getDataElement());
value.setValue(dataValue.getValue());
value.setProvidedElsewhere(dataValue.getProvidedElsewhere());
value.setStoredBy(dataValue.getStoredBy());
event.getDataValues().add(value);
} else {
log.info("Can not find a Data Element having UID [" + dataValue.getDataElement() + "]");
}
}
event.getNotes().addAll(NoteHelper.convertNotes(programStageInstance.getComments()));
event.setRelationships(programStageInstance.getRelationshipItems().stream().filter(Objects::nonNull).map((r) -> relationshipService.getRelationship(r.getRelationship(), RelationshipParams.FALSE, user)).collect(Collectors.toSet()));
return event;
}
use of org.hisp.dhis.category.CategoryOptionCombo in project dhis2-core by dhis2.
the class ProgramStageInstanceSupplier method getCatOptionCombo.
private CategoryOptionCombo getCatOptionCombo(ResultSet rs) throws SQLException {
CategoryOptionCombo coc = new CategoryOptionCombo();
coc.setUid(rs.getString("coc_uid"));
return coc;
}
Aggregations