use of org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue in project dhis2-core by dhis2.
the class ProgramIndicatorServiceTest method setUpTest.
@Override
public void setUpTest() {
OrganisationUnit organisationUnit = createOrganisationUnit('A');
organisationUnitService.addOrganisationUnit(organisationUnit);
// ---------------------------------------------------------------------
// Program
// ---------------------------------------------------------------------
programA = createProgram('A', new HashSet<>(), organisationUnit);
programService.addProgram(programA);
psA = new ProgramStage("StageA", programA);
psA.setSortOrder(1);
programStageService.saveProgramStage(psA);
psB = new ProgramStage("StageB", programA);
psB.setSortOrder(2);
programStageService.saveProgramStage(psB);
Set<ProgramStage> programStages = new HashSet<>();
programStages.add(psA);
programStages.add(psB);
programA.setProgramStages(programStages);
programService.updateProgram(programA);
programB = createProgram('B', new HashSet<>(), organisationUnit);
programService.addProgram(programB);
// ---------------------------------------------------------------------
// Program Stage DE
// ---------------------------------------------------------------------
deA = createDataElement('A');
deA.setDomainType(DataElementDomain.TRACKER);
deB = createDataElement('B');
deB.setDomainType(DataElementDomain.TRACKER);
dataElementService.addDataElement(deA);
dataElementService.addDataElement(deB);
ProgramStageDataElement stageDataElementA = new ProgramStageDataElement(psA, deA, false, 1);
ProgramStageDataElement stageDataElementB = new ProgramStageDataElement(psA, deB, false, 2);
ProgramStageDataElement stageDataElementC = new ProgramStageDataElement(psB, deA, false, 1);
ProgramStageDataElement stageDataElementD = new ProgramStageDataElement(psB, deB, false, 2);
programStageDataElementService.addProgramStageDataElement(stageDataElementA);
programStageDataElementService.addProgramStageDataElement(stageDataElementB);
programStageDataElementService.addProgramStageDataElement(stageDataElementC);
programStageDataElementService.addProgramStageDataElement(stageDataElementD);
// ---------------------------------------------------------------------
// TrackedEntityInstance & Enrollment
// ---------------------------------------------------------------------
TrackedEntityInstance entityInstance = createTrackedEntityInstance('A', organisationUnit);
entityInstanceService.addTrackedEntityInstance(entityInstance);
incidentDate = DateUtils.getMediumDate("2014-10-22");
enrollmentDate = DateUtils.getMediumDate("2014-12-31");
programInstance = programInstanceService.enrollTrackedEntityInstance(entityInstance, programA, enrollmentDate, incidentDate, organisationUnit);
incidentDate = DateUtils.getMediumDate("2014-10-22");
enrollmentDate = DateUtils.getMediumDate("2014-12-31");
programInstance = programInstanceService.enrollTrackedEntityInstance(entityInstance, programA, enrollmentDate, incidentDate, organisationUnit);
// TODO enroll twice?
// ---------------------------------------------------------------------
// TrackedEntityAttribute
// ---------------------------------------------------------------------
atA = createTrackedEntityAttribute('A', ValueType.NUMBER);
atB = createTrackedEntityAttribute('B', ValueType.NUMBER);
attributeService.addTrackedEntityAttribute(atA);
attributeService.addTrackedEntityAttribute(atB);
TrackedEntityAttributeValue attributeValueA = new TrackedEntityAttributeValue(atA, entityInstance, "1");
TrackedEntityAttributeValue attributeValueB = new TrackedEntityAttributeValue(atB, entityInstance, "2");
attributeValueService.addTrackedEntityAttributeValue(attributeValueA);
attributeValueService.addTrackedEntityAttributeValue(attributeValueB);
// ---------------------------------------------------------------------
// TrackedEntityDataValue
// ---------------------------------------------------------------------
ProgramStageInstance stageInstanceA = programStageInstanceService.createProgramStageInstance(programInstance, psA, enrollmentDate, incidentDate, organisationUnit);
ProgramStageInstance stageInstanceB = programStageInstanceService.createProgramStageInstance(programInstance, psB, enrollmentDate, incidentDate, organisationUnit);
Set<ProgramStageInstance> programStageInstances = new HashSet<>();
programStageInstances.add(stageInstanceA);
programStageInstances.add(stageInstanceB);
programInstance.setProgramStageInstances(programStageInstances);
programInstance.setProgram(programA);
TrackedEntityDataValue dataValueA = new TrackedEntityDataValue(stageInstanceA, deA, "3");
TrackedEntityDataValue dataValueB = new TrackedEntityDataValue(stageInstanceA, deB, "1");
TrackedEntityDataValue dataValueC = new TrackedEntityDataValue(stageInstanceB, deA, "5");
TrackedEntityDataValue dataValueD = new TrackedEntityDataValue(stageInstanceB, deB, "7");
dataValueService.saveTrackedEntityDataValue(dataValueA);
dataValueService.saveTrackedEntityDataValue(dataValueB);
dataValueService.saveTrackedEntityDataValue(dataValueC);
dataValueService.saveTrackedEntityDataValue(dataValueD);
// ---------------------------------------------------------------------
// Constant
// ---------------------------------------------------------------------
Constant constantA = createConstant('A', 7.0);
constantService.saveConstant(constantA);
// ---------------------------------------------------------------------
// ProgramIndicator
// ---------------------------------------------------------------------
String expressionA = "( d2:daysBetween(" + KEY_PROGRAM_VARIABLE + "{" + ProgramIndicator.VAR_ENROLLMENT_DATE + "}, " + KEY_PROGRAM_VARIABLE + "{" + ProgramIndicator.VAR_INCIDENT_DATE + "}) ) / " + ProgramIndicator.KEY_CONSTANT + "{" + constantA.getUid() + "}";
indicatorA = createProgramIndicator('A', programA, expressionA, null);
programA.getProgramIndicators().add(indicatorA);
indicatorB = createProgramIndicator('B', programA, "70", null);
programA.getProgramIndicators().add(indicatorB);
indicatorC = createProgramIndicator('C', programA, "0", null);
programA.getProgramIndicators().add(indicatorC);
String expressionD = "0 + A + 4 + " + ProgramIndicator.KEY_PROGRAM_VARIABLE + "{" + ProgramIndicator.VAR_INCIDENT_DATE + "}";
indicatorD = createProgramIndicator('D', programB, expressionD, null);
String expressionE = KEY_DATAELEMENT + "{" + psA.getUid() + "." + deA.getUid() + "} + " + KEY_DATAELEMENT + "{" + psB.getUid() + "." + deA.getUid() + "} - " + KEY_ATTRIBUTE + "{" + atA.getUid() + "} + " + KEY_ATTRIBUTE + "{" + atB.getUid() + "}";
String filterE = KEY_DATAELEMENT + "{" + psA.getUid() + "." + deA.getUid() + "} + " + KEY_ATTRIBUTE + "{" + atA.getUid() + "} > 10";
indicatorE = createProgramIndicator('E', programB, expressionE, filterE);
}
use of org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue in project dhis2-core by dhis2.
the class DhisConvenienceTest method createTrackedEntityInstance.
public static TrackedEntityInstance createTrackedEntityInstance(char uniqueChar, OrganisationUnit organisationUnit, TrackedEntityAttribute attribute) {
TrackedEntityInstance entityInstance = new TrackedEntityInstance();
entityInstance.setAutoFields();
entityInstance.setOrganisationUnit(organisationUnit);
TrackedEntityAttributeValue attributeValue = new TrackedEntityAttributeValue();
attributeValue.setAttribute(attribute);
attributeValue.setEntityInstance(entityInstance);
attributeValue.setValue("Attribute" + uniqueChar);
entityInstance.getTrackedEntityAttributeValues().add(attributeValue);
return entityInstance;
}
use of org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue in project dhis2-core by dhis2.
the class ProgramStageInstanceServiceTest method setUpTest.
@Override
public void setUpTest() {
mockFormat = new MockI18nFormat();
organisationUnitA = createOrganisationUnit('A');
organisationUnitService.addOrganisationUnit(organisationUnitA);
organisationUnitB = createOrganisationUnit('B');
organisationUnitService.addOrganisationUnit(organisationUnitB);
entityInstanceA = createTrackedEntityInstance('A', organisationUnitA);
entityInstanceService.addTrackedEntityInstance(entityInstanceA);
entityInstanceB = createTrackedEntityInstance('B', organisationUnitB);
entityInstanceService.addTrackedEntityInstance(entityInstanceB);
TrackedEntityAttribute attribute = createTrackedEntityAttribute('A');
attribute.setValueType(ValueType.PHONE_NUMBER);
attributeService.addTrackedEntityAttribute(attribute);
TrackedEntityAttributeValue attributeValue = createTrackedEntityAttributeValue('A', entityInstanceA, attribute);
attributeValue.setValue("123456789");
attributeValueService.addTrackedEntityAttributeValue(attributeValue);
entityInstanceA.getTrackedEntityAttributeValues().add(attributeValue);
entityInstanceService.updateTrackedEntityInstance(entityInstanceA);
/**
* Program A
*/
programA = createProgram('A', new HashSet<>(), organisationUnitA);
programService.addProgram(programA);
stageA = createProgramStage('A', 0);
stageA.setProgram(programA);
stageA.setSortOrder(1);
programStageService.saveProgramStage(stageA);
stageB = new ProgramStage("B", programA);
stageB.setSortOrder(2);
programStageService.saveProgramStage(stageB);
Set<ProgramStage> programStages = new HashSet<>();
programStages.add(stageA);
programStages.add(stageB);
programA.setProgramStages(programStages);
programService.updateProgram(programA);
dataElementA = createDataElement('A');
dataElementB = createDataElement('B');
dataElementService.addDataElement(dataElementA);
dataElementService.addDataElement(dataElementB);
stageDataElementA = new ProgramStageDataElement(stageA, dataElementA, false, 1);
stageDataElementB = new ProgramStageDataElement(stageA, dataElementB, false, 2);
stageDataElementC = new ProgramStageDataElement(stageB, dataElementA, false, 1);
stageDataElementD = new ProgramStageDataElement(stageB, dataElementB, false, 2);
programStageDataElementService.addProgramStageDataElement(stageDataElementA);
programStageDataElementService.addProgramStageDataElement(stageDataElementB);
programStageDataElementService.addProgramStageDataElement(stageDataElementC);
programStageDataElementService.addProgramStageDataElement(stageDataElementD);
/**
* Program B
*/
Program programB = createProgram('B', new HashSet<>(), organisationUnitB);
programService.addProgram(programB);
stageC = new ProgramStage("C", programB);
stageC.setSortOrder(1);
programStageService.saveProgramStage(stageC);
stageD = new ProgramStage("D", programB);
stageB.setSortOrder(2);
stageC.setRepeatable(true);
programStageService.saveProgramStage(stageD);
programStages = new HashSet<>();
programStages.add(stageC);
programStages.add(stageD);
programB.setProgramStages(programStages);
programService.updateProgram(programB);
/**
* Program Instance and Program Stage Instance
*/
DateTime testDate1 = DateTime.now();
testDate1.withTimeAtStartOfDay();
testDate1 = testDate1.minusDays(70);
incidenDate = testDate1.toDate();
DateTime testDate2 = DateTime.now();
testDate2.withTimeAtStartOfDay();
enrollmentDate = testDate2.toDate();
programInstanceA = new ProgramInstance(enrollmentDate, incidenDate, entityInstanceA, programA);
programInstanceA.setUid("UID-PIA");
programInstanceService.addProgramInstance(programInstanceA);
programInstanceB = new ProgramInstance(enrollmentDate, incidenDate, entityInstanceB, programB);
programInstanceService.addProgramInstance(programInstanceB);
programStageInstanceA = new ProgramStageInstance(programInstanceA, stageA);
programStageInstanceA.setDueDate(enrollmentDate);
programStageInstanceA.setUid("UID-A");
programStageInstanceB = new ProgramStageInstance(programInstanceA, stageB);
programStageInstanceB.setDueDate(enrollmentDate);
programStageInstanceB.setUid("UID-B");
programStageInstanceC = new ProgramStageInstance(programInstanceB, stageC);
programStageInstanceC.setDueDate(enrollmentDate);
programStageInstanceC.setUid("UID-C");
programStageInstanceD1 = new ProgramStageInstance(programInstanceB, stageD);
programStageInstanceD1.setDueDate(enrollmentDate);
programStageInstanceD1.setUid("UID-D1");
programStageInstanceD2 = new ProgramStageInstance(programInstanceB, stageD);
programStageInstanceD2.setDueDate(enrollmentDate);
programStageInstanceD2.setUid("UID-D2");
}
use of org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue in project dhis2-core by dhis2.
the class ActivityReportingServiceImpl method handleLostToFollowUp.
@SuppressWarnings("finally")
@Override
public Notification handleLostToFollowUp(LostEvent lostEvent) throws NotAllowedException {
Notification notification = new Notification();
try {
ProgramStageInstance programStageInstance = programStageInstanceService.getProgramStageInstance(lostEvent.getId());
programStageInstance.setDueDate(DateUtils.getMediumDate(lostEvent.getDueDate()));
programStageInstance.setStatus(EventStatus.fromInt(lostEvent.getStatus()));
if (lostEvent.getComment() != null) {
List<MessageConversation> conversationList = new ArrayList<>();
MessageConversation conversation = new MessageConversation(lostEvent.getName(), currentUserService.getCurrentUser(), MessageType.PRIVATE);
conversation.addMessage(new Message(lostEvent.getComment(), null, currentUserService.getCurrentUser()));
conversation.setRead(true);
conversationList.add(conversation);
programStageInstance.setMessageConversations(conversationList);
messageService.saveMessageConversation(conversation);
}
programStageInstanceService.updateProgramStageInstance(programStageInstance);
// send SMS
if (programStageInstance.getProgramInstance().getEntityInstance().getTrackedEntityAttributeValues() != null && lostEvent.getSMS() != null) {
List<User> recipientsList = new ArrayList<>();
for (TrackedEntityAttributeValue attrValue : programStageInstance.getProgramInstance().getEntityInstance().getTrackedEntityAttributeValues()) {
if (ValueType.PHONE_NUMBER == attrValue.getAttribute().getValueType()) {
User user = new User();
user.setPhoneNumber(attrValue.getValue());
recipientsList.add(user);
}
}
Set<User> recipients = new HashSet<>();
recipients.addAll(recipientsList);
smsSender.sendMessage(lostEvent.getName(), lostEvent.getSMS(), null, currentUserService.getCurrentUser(), recipients, false);
}
notification.setMessage("Success");
} catch (Exception e) {
e.printStackTrace();
notification.setMessage("Fail");
} finally {
return notification;
}
}
use of org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue in project dhis2-core by dhis2.
the class ActivityReportingServiceImpl method findVisitSchedule.
@Override
public String findVisitSchedule(int orgUnitId, int programId, String info) throws NotAllowedException {
String status = info.substring(0, info.indexOf("$"));
String fromDays = info.substring(info.indexOf("$") + 1, info.indexOf("/"));
String toDays = info.substring(info.indexOf("/") + 1);
// Event Status
EventStatus eventStatus = null;
if (status.equals("Schedule in future")) {
eventStatus = EventStatus.SCHEDULE;
} else if (status.equals("Overdue")) {
eventStatus = EventStatus.OVERDUE;
} else if (status.equals("Incomplete")) {
eventStatus = EventStatus.VISITED;
} else if (status.equals("Completed")) {
eventStatus = EventStatus.COMPLETED;
} else if (status.equals("Skipped")) {
eventStatus = EventStatus.SKIPPED;
}
// From/To Date
Date fromDate = getDate(-1, fromDays);
Date toDate = getDate(1, toDays);
TrackedEntityInstanceQueryParams param = new TrackedEntityInstanceQueryParams();
List<TrackedEntityAttribute> trackedEntityAttributeList = new ArrayList<>(attributeService.getTrackedEntityAttributesByDisplayOnVisitSchedule(true));
for (TrackedEntityAttribute trackedEntityAttribute : trackedEntityAttributeList) {
QueryItem queryItem = new QueryItem(trackedEntityAttribute);
param.addAttribute(queryItem);
}
param.setProgram(programService.getProgram(programId));
param.addOrganisationUnit(organisationUnitService.getOrganisationUnit(orgUnitId));
param.setEventStatus(eventStatus);
param.setEventStartDate(fromDate);
param.setEventEndDate(toDate);
Grid programStageInstanceGrid = entityInstanceService.getTrackedEntityInstancesGrid(param);
List<List<Object>> listOfListProgramStageInstance = programStageInstanceGrid.getRows();
if (listOfListProgramStageInstance.size() == 0) {
throw NotAllowedException.NO_EVENT_FOUND;
}
String eventsInfo = "";
for (List<Object> row : listOfListProgramStageInstance) {
TrackedEntityInstance instance = entityInstanceService.getTrackedEntityInstance((String) row.get(0));
Collection<TrackedEntityAttribute> displayAttributes = attributeService.getTrackedEntityAttributesDisplayInList();
eventsInfo += instance.getId() + "/";
String displayName = "";
for (TrackedEntityAttribute displayAttribute : displayAttributes) {
TrackedEntityAttributeValue value = attValueService.getTrackedEntityAttributeValue(instance, displayAttribute);
if (value != null) {
displayName += value.getValue() + " ";
}
}
eventsInfo += displayName.trim() + "$";
}
return eventsInfo;
}
Aggregations