Example #1
0
  /**
   * Parses the MotechEvent and creates a {@link
   * org.motechproject.dhis2.rest.domain.TrackedEntityInstanceDto} which is then sent to the DHIS2
   * server via {@link org.motechproject.dhis2.rest.service.DhisWebService}
   *
   * @param event MotechEvent pertaining to tracked entity instance creation.
   */
  @MotechListener(subjects = EventSubjects.CREATE_ENTITY)
  public void handleCreate(MotechEvent event) {
    LOGGER.debug("Handling CREATE_ENTITY MotechEvent");
    Map<String, Object> params = prepareDhisAttributesMap(event.getParameters());
    String externalUUID = (String) params.remove(EventParams.EXTERNAL_ID);
    TrackedEntityInstanceDto trackedEntityInstance = createTrackedEntityInstanceFromParams(params);

    LOGGER.debug("Sending request to create entity to the DHIS Web Service");
    DhisStatusResponse response = dhisWebService.createTrackedEntityInstance(trackedEntityInstance);

    LOGGER.trace("Received response from the DHIS server. Status: {}", response.getStatus());
    if (response.getStatus() == DhisStatus.SUCCESS || response.getStatus() == DhisStatus.OK) {
      trackedEntityInstanceMappingService.create(externalUUID, response.getReference());
    }
  }
Example #2
0
  /**
   * Parses the event and creates a{@link org.motechproject.dhis2.rest.domain.DataValueSetDto}which
   * is then sent to the DHIS2 server via {@link
   * org.motechproject.dhis2.rest.service.DhisWebService}
   *
   * @param event
   */
  @MotechListener(subjects = EventSubjects.SEND_DATA_VALUE_SET)
  public void handleDataValueSet(MotechEvent event) {
    Map<String, Object> params = prepareDhisAttributesMap(event.getParameters());
    String dataSet = (String) params.get(EventParams.DATA_SET);
    String completeDate = (String) params.get(EventParams.COMPLETE_DATE);
    String period = (String) params.get(EventParams.PERIOD);
    String orgUnitId = (String) params.get(EventParams.LOCATION);
    String categoryOptionCombo = (String) params.get(EventParams.CATEGORY_OPTION_COMBO);
    String comment = (String) params.get(EventParams.COMMENT);
    String attributeOptionCombo = (String) params.get(EventParams.ATTRIBUTE_OPTION_COMBO);
    Map<String, Object> dataValues = (Map<String, Object>) params.get(EventParams.DATA_VALUES);

    List<DataValueDto> dataValueDtos = new ArrayList<>();

    for (Object o : dataValues.entrySet()) {
      Entry pair = (Entry) o;
      String dataElement = (String) pair.getKey();
      String dataElementId = dataElementService.findByName(dataElement).getUuid();
      String value = (String) pair.getValue();
      DataValueDto dataValueDto = new DataValueDto();
      dataValueDto.setDataElement(dataElementId);
      dataValueDto.setValue(value);

      dataValueDtos.add(dataValueDto);
    }

    DataValueSetDto dataValueSetDto = new DataValueSetDto();
    dataValueSetDto.setDataSet(dataSet);
    dataValueSetDto.setPeriod(period);
    dataValueSetDto.setCompleteDate(completeDate);
    dataValueSetDto.setOrgUnit(orgUnitId);
    dataValueSetDto.setDataValues(dataValueDtos);
    dataValueSetDto.setAttributeOptionCombo(attributeOptionCombo);
    dataValueSetDto.setCategoryOptionCombo(categoryOptionCombo);
    dataValueSetDto.setComment(comment);
    dhisWebService.sendDataValueSet(dataValueSetDto);
  }
Example #3
0
  /**
   * Parses the event and creates a {@link org.motechproject.dhis2.rest.domain.DataValueDto} which
   * is then sent to the DHIS2 server via {@link
   * org.motechproject.dhis2.rest.service.DhisWebService}
   *
   * @param event
   */
  @MotechListener(subjects = EventSubjects.SEND_DATA_VALUE)
  public void handleDataValue(MotechEvent event) {

    Map<String, Object> params = event.getParameters();

    DataElement dataElement =
        dataElementService.findByName((String) params.get(EventParams.DATA_ELEMENT));

    if (dataElement == null) {
      throw new DataElementNotFoundException(
          "The data element "
              + params.get(EventParams.DATA_ELEMENT)
              + " that was sent did not match any values imported from DHIS2. Please make sure that the "
              + "data element field matches a data element name in the DHIS2 module");
    }

    String orgUnitId = (String) params.get(EventParams.LOCATION);
    String period = (String) params.get(EventParams.PERIOD);
    String value = (String) params.get(EventParams.VALUE);
    String categoryOptionCombo = (String) params.get(EventParams.CATEGORY_OPTION_COMBO);
    String comment = (String) params.get(EventParams.COMMENT);

    DataValueDto dataValueDto = new DataValueDto();
    dataValueDto.setDataElement(dataElement.getUuid());
    dataValueDto.setValue(value);
    dataValueDto.setOrgUnit(orgUnitId);
    dataValueDto.setPeriod(period);
    dataValueDto.setCategoryOptionCombo(categoryOptionCombo);
    dataValueDto.setComment(comment);

    DataValueSetDto dataValueSetDto = new DataValueSetDto();
    List<DataValueDto> dataValueDtos = new ArrayList<>();
    dataValueDtos.add(dataValueDto);
    dataValueSetDto.setDataValues(dataValueDtos);

    dhisWebService.sendDataValueSet(dataValueSetDto);
  }
Example #4
0
 /**
  * Parses the MotechEvent and creates a {@link org.motechproject.dhis2.rest.domain.DhisEventDto}
  * which is then sent to the DHIS2 server via {@link
  * org.motechproject.dhis2.rest.service.DhisWebService}
  *
  * @param event MotechEvent pertaining to a DHIS2 program stage event.
  */
 @MotechListener(subjects = {EventSubjects.UPDATE_PROGRAM_STAGE})
 public void handleStageUpdate(MotechEvent event) {
   Map<String, Object> params = prepareDhisAttributesMap(event.getParameters());
   DhisEventDto dhisEventDto = createDhisEventFromParams(params);
   dhisWebService.createEvent(dhisEventDto);
 }
Example #5
0
 /**
  * Parses the MotechEvent and creates a {@link org.motechproject.dhis2.rest.domain.EnrollmentDto}
  * which is then sent to the DHIS2 server via {@link
  * org.motechproject.dhis2.rest.service.DhisWebService}
  *
  * @param event MotechEvent pertaining to enrolling a tracked entity instance in a program.
  */
 @MotechListener(subjects = {EventSubjects.ENROLL_IN_PROGRAM})
 public void handleEnrollment(MotechEvent event) {
   Map<String, Object> params = prepareDhisAttributesMap(event.getParameters());
   EnrollmentDto enrollment = createEnrollmentFromParams(params);
   dhisWebService.createEnrollment(enrollment);
 }