Beispiel #1
0
  private DhisEventDto createDhisEventFromParams(Map<String, Object> params) {
    DhisEventDto dhisEventDto = new DhisEventDto();

    String registationString = (String) params.remove(EventParams.REGISTRATION);
    boolean registration = registationString.contains("true");

    if (registration) {
      String externalTrackedEntityInstanceId = (String) params.remove(EventParams.EXTERNAL_ID);
      String trackedEntityInstanceId =
          trackedEntityInstanceMappingService.mapFromExternalId(externalTrackedEntityInstanceId);
      dhisEventDto.setTrackedEntityInstance(trackedEntityInstanceId);
    }

    String orgUnitId = (String) params.remove(EventParams.LOCATION);
    String program = (String) params.remove(EventParams.PROGRAM);
    String date = (String) params.remove(EventParams.DATE);
    String stage = (String) params.remove(EventParams.STAGE);

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

    for (Entry<String, Object> entry : params.entrySet()) {
      DataValueDto dataValue = new DataValueDto();
      dataValue.setDataElement(entry.getKey());
      dataValue.setValue((String) entry.getValue());
      dataValues.add(dataValue);
    }

    dhisEventDto.setProgram(program);
    dhisEventDto.setEventDate(date);
    dhisEventDto.setProgramStage(stage);
    dhisEventDto.setOrgUnit(orgUnitId);
    dhisEventDto.setDataValues(dataValues);

    return dhisEventDto;
  }
Beispiel #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);
  }
Beispiel #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);
  }