Skip to content

Commit

Permalink
avniproject/avni-webapp#1337 | Filter table names by org_schema_name
Browse files Browse the repository at this point in the history
  • Loading branch information
himeshr committed Dec 11, 2024
1 parent 13058da commit f2e749f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

public enum DatasetColumn {
NAME(1),
TYPE(2);
TYPE(2),
SCHEMA_NAME(3);

private final int index;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
import org.avni.server.domain.metabase.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Arrays;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -81,10 +82,12 @@ public List<String> getSubjectTypeNames() {

for (List<String> row : rows) {
String type = row.get(DatasetColumn.TYPE.getIndex());
if (type.equalsIgnoreCase(TableType.INDIVIDUAL.getTypeName()) ||
type.equalsIgnoreCase(TableType.HOUSEHOLD.getTypeName()) ||
type.equalsIgnoreCase(TableType.GROUP.getTypeName()) ||
type.equalsIgnoreCase(TableType.PERSON.getTypeName())) {
String schemaName = row.get(DatasetColumn.SCHEMA_NAME.getIndex());
if (schemaName.equalsIgnoreCase(getGlobalDatabase().getName()) &&
(type.equalsIgnoreCase(TableType.INDIVIDUAL.getTypeName()) ||
type.equalsIgnoreCase(TableType.HOUSEHOLD.getTypeName()) ||
type.equalsIgnoreCase(TableType.GROUP.getTypeName()) ||
type.equalsIgnoreCase(TableType.PERSON.getTypeName()))) {
subjectTypeNames.add(row.get(DatasetColumn.NAME.getIndex()));
}
}
Expand All @@ -98,18 +101,20 @@ public List<String> getProgramAndEncounterNames() {
DatasetResponse datasetResponse = databaseRepository.findAll(fetchedMetadataTable, getGlobalDatabase());
List<List<String>> rows = datasetResponse.getData().getRows();

List<String> programNames = new ArrayList<>();
List<String> programAndEncounterNames = new ArrayList<>();

for (List<String> row : rows) {
String type = row.get(DatasetColumn.TYPE.getIndex());
if (type.equalsIgnoreCase(TableType.PROGRAM_ENCOUNTER.getTypeName()) ||
type.equalsIgnoreCase(TableType.ENCOUNTER.getTypeName()) ||
type.equalsIgnoreCase(TableType.PROGRAM_ENROLMENT.getTypeName())) {
programNames.add(row.get(DatasetColumn.NAME.getIndex()));
String schemaName = row.get(DatasetColumn.SCHEMA_NAME.getIndex());
if (schemaName.equalsIgnoreCase(getGlobalDatabase().getName()) &&
(type.equalsIgnoreCase(TableType.PROGRAM_ENCOUNTER.getTypeName()) ||
type.equalsIgnoreCase(TableType.ENCOUNTER.getTypeName()) ||
type.equalsIgnoreCase(TableType.PROGRAM_ENROLMENT.getTypeName()))) {
programAndEncounterNames.add(row.get(DatasetColumn.NAME.getIndex()));
}
}

return programNames;
return programAndEncounterNames;
}

private void createQuestionsForEntities(List<String> entityNames, FieldDetails addressFieldDetails, FieldDetails entityFieldDetails) {
Expand Down

0 comments on commit f2e749f

Please sign in to comment.