Skip to content

Commit

Permalink
Craft API for aggregating daily aggregated data
Browse files Browse the repository at this point in the history
  • Loading branch information
josephatJ committed Jul 30, 2024
1 parent 2f9fe0e commit c47830d
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import com.Adapter.icare.Domains.Datastore;
import com.Adapter.icare.Services.DatastoreService;
import com.google.common.collect.Maps;
import javassist.NotFoundException;
import org.apache.commons.beanutils.BeanUtils;
import org.springframework.web.bind.annotation.*;
Expand Down Expand Up @@ -134,8 +135,18 @@ public Map<String, Object> getAggregateVisits(@RequestBody Map<String, Objec
}
}
}

results.put("data", data);
return results;
}

@GetMapping("dailyAggregatedData")
public Map<String, Object> getAggregateDataByStartDateAndEndDate(@RequestParam(value = "id") String id,
@RequestParam(value = "startDate") String startDate,
@RequestParam(value = "endDate") String endDate
) throws Exception {
Map<String, Object> results = Maps.newHashMap();
List<Map<String, Object>> dailyAggregatedDataList = datastoreService.getAggregateDataFromDailyAggregatedData(id,startDate,endDate);
results.put("data", dailyAggregatedDataList);
return results;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public class Datastore extends BaseEntity implements Serializable {
@Column(name = "data_key", nullable = false)
private String dataKey;


@Column(name = "value", columnDefinition = "json", nullable = false)
@Convert(converter = HashMapConverter.class)
private Map<String, Object> value;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,16 @@
package com.Adapter.icare.Repository;

import com.Adapter.icare.Domains.Datastore;
import org.hibernate.query.NativeQuery;
import org.jetbrains.annotations.NotNull;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;
import java.sql.Timestamp;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Repository
public interface DatastoreRepository extends JpaRepository<Datastore, Long> {

@PersistenceContext
EntityManager entityManager = null;

List<Datastore> findAll();

@Query(value = "SELECT * FROM datastore WHERE uuid=:uuid",nativeQuery = true)
Expand Down Expand Up @@ -87,4 +77,9 @@ public interface DatastoreRepository extends JpaRepository<Datastore, Long> {
" ) AS subquery " +
" ) > 0",nativeQuery = true)
List<Map<String, Object>> getDatastoreAggregateByDatesAndAgeGroupAndGenderAndDiagnosis(String startDate, String endDate, String ageType, Integer startAge, Integer endAge, String gender, String mappingsNamespace, String mappingsKey);


@Query(value = "SELECT datastore.value FROM datastore WHERE namespace =:namespace " +
"AND JSON_EXTRACT(value, '$.startDate') >= :startDate AND JSON_EXTRACT(value, '$.endDate') <= :endDate",nativeQuery = true)
List<Map<String, Object>> getAggregateDataByStartDateAndEndDate(String namespace, String startDate, String endDate);
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,8 @@ public List<Map<String, Object>> getAggregatedData(String startDate, String endD
return new ArrayList<Map<String, Object>>();
}
}

public List<Map<String, Object>> getAggregateDataFromDailyAggregatedData(String id, String startDate, String endDate) throws Exception {
return datastoreRepository.getAggregateDataByStartDateAndEndDate(id,startDate,endDate);
}
}

0 comments on commit c47830d

Please sign in to comment.