Skip to content

Commit

Permalink
Added field for AgeCount
Browse files Browse the repository at this point in the history
  • Loading branch information
sushantpatil1214 committed Oct 4, 2024
1 parent ac8cbfc commit eafa50b
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ private Behavior<Event> getAgeGroupCountHandler(final GetAgeGroupCountRequest re
String startDob = request.searchAgeCountFields.startDate();
String endDob = request.searchAgeCountFields.endDate();
LOGGER.info("startDob: {}, endDob: {}", startDob, endDob);
getCount = libMPI.getAgeGroupCount(startDob, endDob);
getCount = libMPI.getAgeGroupCount(request.searchAgeCountFields);
request.replyTo.tell(new GetAgeGroupCountResponse(getCount));
} catch (Exception e) {
LOGGER.error(e.getLocalizedMessage(), e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,9 @@ public String getFieldCount(final ApiModels.CountFields countFields) {
return client.getFieldCount(countFields);
}

public long getAgeGroupCount(final String startDate, final String endDate) {
public long getAgeGroupCount(final ApiModels.SearchAgeCountFields searchAgeCountFields) {
client.connect();
return client.getAgeGroupCount(startDate, endDate);
return client.getAgeGroupCount(searchAgeCountFields);
}

public List<String> getAllList(final ApiModels.AllList allListRequest) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ List<ExpandedSourceId> findExpandedSourceIdList(

String getFieldCount(ApiModels.CountFields countFields);

long getAgeGroupCount(String startDate, String endDate);
long getAgeGroupCount(ApiModels.SearchAgeCountFields searchAgeCountFields);

List<String> getAllList(ApiModels.AllList allListRequest);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1260,17 +1260,20 @@ private static class InvalidOperatorException extends Exception {
* @param endDate The end date of the age range (inclusive)
* @return A string containing the JSON response with the count
*/
public static long getAgeGroupCount(final String startDate, final String endDate) {
public static long getAgeGroupCount(final ApiModels.SearchAgeCountFields searchAgeCountFields) {
// Constructing the query string
String field = searchAgeCountFields.field();
String startDate = searchAgeCountFields.startDate(); // Empty means no start date
String endDate = searchAgeCountFields.endDate();
String query = String.format(Locale.ROOT,
"""
{
list(func: has(GoldenRecord.dob)) @filter(ge(GoldenRecord.dob, "%s") AND le(GoldenRecord.dob, "%s")) {
list(func: has(GoldenRecord.%s)) @filter(ge(GoldenRecord.%s, "%s") AND le(GoldenRecord.%s, "%s")) {
count(uid)
}
}
""",
startDate, endDate); // Order of %s matches the date range
field, field, startDate, field, endDate); // Order of %s matches the date range
try {
LOGGER.info("Query: {}", query);
return getCount(query);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ public String getFieldCount(final ApiModels.CountFields countFields) {
return DgraphQueries.getFieldCount(countFields);
}

public long getAgeGroupCount(final String startDate, final String endDate) {
return DgraphQueries.getAgeGroupCount(startDate, endDate);
public long getAgeGroupCount(final ApiModels.SearchAgeCountFields searchAgeCountFields) {
return DgraphQueries.getAgeGroupCount(searchAgeCountFields);
}

public List<String> getAllList(final ApiModels.AllList allList) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,8 @@ public record CountFields(
@JsonInclude(JsonInclude.Include.NON_NULL)
public record SearchAgeCountFields(
String startDate,
String endDate
String endDate,
String field
) {
}

Expand Down
2 changes: 1 addition & 1 deletion documentation/JeMPI.postman_collection.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"header": [],
"body": {
"mode": "raw",
"raw": "{\n \"startDate\": \"20231005\", \n \"endDate\": \"20241001\" \n}",
"raw": "{\n \"startDate\": \"10001005\", \n \"endDate\": \"20241001\",\n \"field\": \"dob\"\n}",
"options": {
"raw": {
"language": "json"
Expand Down

0 comments on commit eafa50b

Please sign in to comment.