Skip to content

Commit

Permalink
avniproject#762 | Enums added
Browse files Browse the repository at this point in the history
  • Loading branch information
ombhardwajj committed Aug 22, 2024
1 parent bb9a681 commit b9dc476
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.avni.server.domain.metabase;

public enum TableType {
INDIVIDUAL("Individual"),
HOUSEHOLD("Household"),
GROUP("Group"),
PERSON("Person"),
PROGRAM_ENCOUNTER("ProgramEncounter"),
PROGRAM_ENROLMENT("ProgramEnrolment");

private final String typeName;

TableType(String typeName) {
this.typeName = typeName;
}

public String getTypeName() {
return typeName;
}

public static TableType fromString(String typeName) {
for (TableType type : TableType.values()) {
if (type.getTypeName().equalsIgnoreCase(typeName)) {
return type;
}
}
throw new IllegalArgumentException("Unknown table type: " + typeName);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.avni.server.service.metabase;
ckage org.avni.server.service.metabase;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
Expand Down Expand Up @@ -129,29 +129,33 @@ public List<String> getSubjectTypeNames() {
JsonNode rows = tableMetadata.path("data").path("rows");
for (JsonNode row : rows) {
String type = row.get(2).asText();
if (Arrays.asList("Individual", "Household", "Group", "Person").contains(type)) {
if (Arrays.asList(TableType.INDIVIDUAL.getTypeName(), TableType.HOUSEHOLD.getTypeName(), TableType.GROUP.getTypeName(), TableType.PERSON.getTypeName()).contains(type)) {
String rawName = row.get(1).asText();
subjectTypeNames.add(formatName(rawName));
}
}
System.out.println("The subject type names::" + subjectTypeNames);
return subjectTypeNames;
}


public List<String> getProgramAndEncounterNames() {
JsonNode tableMetadata = getTableMetadata();
List<String> programNames = new ArrayList<>();

JsonNode rows = tableMetadata.path("data").path("rows");
for (JsonNode row : rows) {
String type = row.get(2).asText();
if (Arrays.asList("ProgramEncounter", "ProgramEnrolment").contains(type)) {
if (Arrays.asList(TableType.PROGRAM_ENCOUNTER.getTypeName(), TableType.PROGRAM_ENROLMENT.getTypeName()).contains(type)) {
String rawName = row.get(1).asText();
programNames.add(formatName(rawName));
}
}
System.out.println("The program and encounter::" + programNames);
return programNames;
}


private List<String> extractTableNames(JsonNode databaseDetails) {
List<String> tableNames = new ArrayList<>();
JsonNode tablesArray = databaseDetails.path("tables");
Expand Down

0 comments on commit b9dc476

Please sign in to comment.