Search in sources :

Example 16 with EventDataValue

use of org.hisp.dhis.eventdatavalue.EventDataValue in project dhis2-core by dhis2.

the class EventTrackerConverterServiceTest method eventDataValue.

private EventDataValue eventDataValue(String dataElement, String value) {
    EventDataValue eventDataValue = new EventDataValue();
    eventDataValue.setDataElement(dataElement);
    eventDataValue.setValue(value);
    return eventDataValue;
}
Also used : EventDataValue(org.hisp.dhis.eventdatavalue.EventDataValue)

Example 17 with EventDataValue

use of org.hisp.dhis.eventdatavalue.EventDataValue in project dhis2-core by dhis2.

the class JsonEventDataValueSetBinaryType method convertEventDataValuesMapIntoSet.

public static Set<EventDataValue> convertEventDataValuesMapIntoSet(Map<String, EventDataValue> data) {
    Set<EventDataValue> eventDataValues = new HashSet<>();
    for (Map.Entry<String, EventDataValue> entry : data.entrySet()) {
        EventDataValue eventDataValue = entry.getValue();
        eventDataValue.setDataElement(entry.getKey());
        eventDataValues.add(eventDataValue);
    }
    return eventDataValues;
}
Also used : EventDataValue(org.hisp.dhis.eventdatavalue.EventDataValue) Map(java.util.Map) HashMap(java.util.HashMap) HashSet(java.util.HashSet)

Example 18 with EventDataValue

use of org.hisp.dhis.eventdatavalue.EventDataValue in project dhis2-core by dhis2.

the class CompressionSMSListener method saveNewEvent.

protected List<Object> saveNewEvent(String eventUid, OrganisationUnit orgUnit, ProgramStage programStage, ProgramInstance programInstance, IncomingSms sms, CategoryOptionCombo aoc, User user, List<SmsDataValue> values, SmsEventStatus eventStatus, Date eventDate, Date dueDate, GeoPoint coordinates) {
    ArrayList<Object> errorUids = new ArrayList<>();
    ProgramStageInstance programStageInstance;
    if (programStageInstanceService.programStageInstanceExists(eventUid)) {
        programStageInstance = programStageInstanceService.getProgramStageInstance(eventUid);
    } else {
        programStageInstance = new ProgramStageInstance();
        programStageInstance.setUid(eventUid);
    }
    programStageInstance.setOrganisationUnit(orgUnit);
    programStageInstance.setProgramStage(programStage);
    programStageInstance.setProgramInstance(programInstance);
    programStageInstance.setExecutionDate(eventDate);
    programStageInstance.setDueDate(dueDate);
    programStageInstance.setAttributeOptionCombo(aoc);
    programStageInstance.setStoredBy(user.getUsername());
    UserInfoSnapshot currentUserInfo = UserInfoSnapshot.from(user);
    programStageInstance.setCreatedByUserInfo(currentUserInfo);
    programStageInstance.setLastUpdatedByUserInfo(currentUserInfo);
    programStageInstance.setStatus(getCoreEventStatus(eventStatus));
    programStageInstance.setGeometry(convertGeoPointToGeometry(coordinates));
    if (eventStatus.equals(SmsEventStatus.COMPLETED)) {
        programStageInstance.setCompletedBy(user.getUsername());
        programStageInstance.setCompletedDate(new Date());
    }
    Map<DataElement, EventDataValue> dataElementsAndEventDataValues = new HashMap<>();
    if (values != null) {
        for (SmsDataValue dv : values) {
            Uid deid = dv.getDataElement();
            String val = dv.getValue();
            DataElement de = dataElementService.getDataElement(deid.getUid());
            // TODO: Is this the correct way of handling errors here?
            if (de == null) {
                log.warn(String.format("Given data element [%s] could not be found. Continuing with submission...", deid));
                errorUids.add(deid);
                continue;
            } else if (val == null || StringUtils.isEmpty(val)) {
                log.warn(String.format("Value for atttribute [%s] is null or empty. Continuing with submission...", deid));
                continue;
            }
            EventDataValue eventDataValue = new EventDataValue(deid.getUid(), dv.getValue(), currentUserInfo);
            eventDataValue.setAutoFields();
            dataElementsAndEventDataValues.put(de, eventDataValue);
        }
    }
    programStageInstanceService.saveEventDataValuesAndSaveProgramStageInstance(programStageInstance, dataElementsAndEventDataValues);
    return errorUids;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Date(java.util.Date) DataElement(org.hisp.dhis.dataelement.DataElement) Uid(org.hisp.dhis.smscompression.models.Uid) SmsDataValue(org.hisp.dhis.smscompression.models.SmsDataValue) UserInfoSnapshot(org.hisp.dhis.program.UserInfoSnapshot) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) EventDataValue(org.hisp.dhis.eventdatavalue.EventDataValue) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance)

Example 19 with EventDataValue

use of org.hisp.dhis.eventdatavalue.EventDataValue in project dhis2-core by dhis2.

the class TrackedEntityDataValueAuditStoreTest method setUpTest.

@Override
public void setUpTest() {
    OrganisationUnit organisationUnit = createOrganisationUnit('A');
    organisationUnitService.addOrganisationUnit(organisationUnit);
    Program program = createProgram('A', new HashSet<>(), organisationUnit);
    programService.addProgram(program);
    ProgramStage stageA = new ProgramStage("StageA", program);
    stageA.setSortOrder(1);
    programStageService.saveProgramStage(stageA);
    ProgramStage stageB = new ProgramStage("StageB", program);
    stageB.setSortOrder(2);
    programStageService.saveProgramStage(stageB);
    Set<ProgramStage> programStages = new HashSet<>();
    programStages.add(stageA);
    programStages.add(stageB);
    program.setProgramStages(programStages);
    programService.updateProgram(program);
    dataElementA = createDataElement('A');
    dataElementB = createDataElement('B');
    dataElementService.addDataElement(dataElementA);
    dataElementService.addDataElement(dataElementB);
    TrackedEntityInstance entityInstance = createTrackedEntityInstance(organisationUnit);
    entityInstanceService.addTrackedEntityInstance(entityInstance);
    ProgramInstance programInstance = programInstanceService.enrollTrackedEntityInstance(entityInstance, program, new Date(), new Date(), organisationUnit);
    stageInstance = programStageInstanceService.createProgramStageInstance(programInstance, stageA, new Date(), new Date(), organisationUnit);
    dataValueA = new EventDataValue(dataElementA.getUid(), "1", UserInfoTestHelper.testUserInfo("test-user"));
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) Program(org.hisp.dhis.program.Program) ProgramInstance(org.hisp.dhis.program.ProgramInstance) ProgramStage(org.hisp.dhis.program.ProgramStage) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance) EventDataValue(org.hisp.dhis.eventdatavalue.EventDataValue) Date(java.util.Date) HashSet(java.util.HashSet)

Example 20 with EventDataValue

use of org.hisp.dhis.eventdatavalue.EventDataValue in project dhis2-core by dhis2.

the class ProgramNotificationMessageRendererTest method setUpTest.

@Override
protected void setUpTest() throws Exception {
    DateTime testDate1 = DateTime.now();
    testDate1.withTimeAtStartOfDay();
    testDate1 = testDate1.minusDays(70);
    Date incidentDate = testDate1.toDate();
    DateTime testDate2 = DateTime.now();
    testDate2.withTimeAtStartOfDay();
    Date enrollmentDate = testDate2.toDate();
    dataElementA = createDataElement('A', ValueType.TEXT, AggregationType.NONE, DataElementDomain.TRACKER);
    dataElementA.setUid(dataElementUid);
    dataElementB = createDataElement('B', ValueType.TEXT, AggregationType.NONE, DataElementDomain.TRACKER);
    dataElementB.setUid("DEB-UID");
    dataElementService.addDataElement(dataElementA);
    dataElementService.addDataElement(dataElementB);
    trackedEntityAttributeA = createTrackedEntityAttribute('A');
    trackedEntityAttributeA.setUid(trackedEntityAttributeUid);
    trackedEntityAttributeB = createTrackedEntityAttribute('B');
    attributeService.addTrackedEntityAttribute(trackedEntityAttributeA);
    attributeService.addTrackedEntityAttribute(trackedEntityAttributeB);
    organisationUnitA = createOrganisationUnit('A');
    organisationUnitA.setUid(orgUnitUid);
    organisationUnitService.addOrganisationUnit(organisationUnitA);
    programA = createProgram('A', new HashSet<>(), organisationUnitA);
    programA.setUid(programUid);
    programService.addProgram(programA);
    programTrackedEntityAttributeA = createProgramTrackedEntityAttribute(programA, trackedEntityAttributeA);
    programTrackedEntityAttributeB = createProgramTrackedEntityAttribute(programA, trackedEntityAttributeB);
    programTrackedEntityAttributeStore.save(programTrackedEntityAttributeA);
    programTrackedEntityAttributeStore.save(programTrackedEntityAttributeB);
    programA.setProgramAttributes(Arrays.asList(programTrackedEntityAttributeA, programTrackedEntityAttributeB));
    programService.updateProgram(programA);
    programStageA = createProgramStage('A', programA);
    programStageA.setUid(programStageUid);
    programStageService.saveProgramStage(programStageA);
    programStageDataElementA = createProgramStageDataElement(programStageA, dataElementA, 1);
    programStageDataElementB = createProgramStageDataElement(programStageA, dataElementB, 2);
    programStageDataElementService.addProgramStageDataElement(programStageDataElementA);
    programStageDataElementService.addProgramStageDataElement(programStageDataElementB);
    programStageA.setProgramStageDataElements(Sets.newHashSet(programStageDataElementA, programStageDataElementB));
    programStageService.updateProgramStage(programStageA);
    programA.setProgramStages(Sets.newHashSet(programStageA));
    programService.updateProgram(programA);
    trackedEntityInstanceA = createTrackedEntityInstance(organisationUnitA);
    trackedEntityInstanceA.setUid(trackedEntityUid);
    entityInstanceService.addTrackedEntityInstance(trackedEntityInstanceA);
    trackedEntityAttributeValueA = new TrackedEntityAttributeValue(trackedEntityAttributeA, trackedEntityInstanceA, "attribute-test");
    trackedEntityAttributeValueService.addTrackedEntityAttributeValue(trackedEntityAttributeValueA);
    trackedEntityInstanceA.setTrackedEntityAttributeValues(Sets.newHashSet(trackedEntityAttributeValueA));
    entityInstanceService.updateTrackedEntityInstance(trackedEntityInstanceA);
    // ProgramInstance to be provided in message renderer
    programInstanceA = programInstanceService.enrollTrackedEntityInstance(trackedEntityInstanceA, programA, enrollmentDate, incidentDate, organisationUnitA);
    programInstanceA.setUid(enrollmentUid);
    programInstanceService.updateProgramInstance(programInstanceA);
    // ProgramStageInstance to be provided in message renderer
    programStageInstanceA = new ProgramStageInstance(programInstanceA, programStageA);
    programStageInstanceA.setOrganisationUnit(organisationUnitA);
    programStageInstanceA.setDueDate(enrollmentDate);
    programStageInstanceA.setExecutionDate(new Date());
    programStageInstanceA.setUid("PSI-UID");
    eventDataValueA = new EventDataValue();
    eventDataValueA.setDataElement(dataElementA.getUid());
    eventDataValueA.setAutoFields();
    eventDataValueA.setValue("dataElementA-Text");
    eventDataValueB = new EventDataValue();
    eventDataValueB.setDataElement(dataElementB.getUid());
    eventDataValueB.setAutoFields();
    eventDataValueB.setValue("dataElementB-Text");
    programStageInstanceA.setEventDataValues(Sets.newHashSet(eventDataValueA, eventDataValueB));
    programStageInstanceService.addProgramStageInstance(programStageInstanceA);
    programInstanceA.getProgramStageInstances().add(programStageInstanceA);
    programInstanceService.updateProgramInstance(programInstanceA);
    programNotificationTemplate = new ProgramNotificationTemplate();
    programNotificationTemplate.setName("Test-PNT");
    programNotificationTemplate.setMessageTemplate("message_template");
    programNotificationTemplate.setDeliveryChannels(Sets.newHashSet(DeliveryChannel.SMS));
    programNotificationTemplate.setSubjectTemplate("subject_template");
    programNotificationTemplate.setNotificationTrigger(NotificationTrigger.PROGRAM_RULE);
    programNotificationTemplate.setAutoFields();
    programNotificationTemplate.setUid("PNT-1");
    programNotificationTemplateStore.save(programNotificationTemplate);
}
Also used : ProgramNotificationTemplate(org.hisp.dhis.program.notification.ProgramNotificationTemplate) TrackedEntityAttributeValue(org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue) EventDataValue(org.hisp.dhis.eventdatavalue.EventDataValue) DateTime(org.joda.time.DateTime) Date(java.util.Date) BaseNotificationMessageRenderer.formatDate(org.hisp.dhis.notification.BaseNotificationMessageRenderer.formatDate) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance) HashSet(java.util.HashSet)

Aggregations

EventDataValue (org.hisp.dhis.eventdatavalue.EventDataValue)35 ProgramStageInstance (org.hisp.dhis.program.ProgramStageInstance)21 DataElement (org.hisp.dhis.dataelement.DataElement)14 Date (java.util.Date)10 HashSet (java.util.HashSet)10 Test (org.junit.jupiter.api.Test)9 DataValue (org.hisp.dhis.tracker.domain.DataValue)8 HashMap (java.util.HashMap)7 Event (org.hisp.dhis.tracker.domain.Event)7 User (org.hisp.dhis.user.User)7 ArrayList (java.util.ArrayList)6 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)6 Set (java.util.Set)5 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)5 ProgramInstance (org.hisp.dhis.program.ProgramInstance)5 Map (java.util.Map)4 Collectors (java.util.stream.Collectors)4 WorkContext (org.hisp.dhis.dxf2.events.importer.context.WorkContext)4 EventStatus (org.hisp.dhis.event.EventStatus)4 Program (org.hisp.dhis.program.Program)4