use of de.symeda.sormas.api.EntityDto in project SORMAS-Project by hzi-braunschweig.
the class ImmunizationFacadeEjb method linkRecoveryImmunizationToSearchedCase.
@Override
public boolean linkRecoveryImmunizationToSearchedCase(String specificCaseSearchValue, ImmunizationDto immunization) {
CaseCriteria criteria = new CaseCriteria();
criteria.setPerson(immunization.getPerson());
criteria.setDisease(immunization.getDisease());
criteria.setOutcome(CaseOutcome.RECOVERED);
String foundCaseUuid = caseFacade.getUuidByUuidEpidNumberOrExternalId(specificCaseSearchValue, criteria);
if (foundCaseUuid != null) {
CaseDataDto caseDataDto = caseFacade.getCaseDataByUuid(foundCaseUuid);
List<String> samples = sampleFacade.getByCaseUuids(Collections.singletonList(caseDataDto.getUuid())).stream().map(EntityDto::getUuid).collect(Collectors.toList());
List<PathogenTestDto> pathogenTestDto = pathogenTestFacade.getBySampleUuids(samples);
PathogenTestDto relevantPathogenTest = pathogenTestDto.stream().filter(pathogenTest -> pathogenTest.getTestedDisease().equals(caseDataDto.getDisease()) && PathogenTestResultType.POSITIVE.equals(pathogenTest.getTestResult())).sorted(Comparator.comparing(PathogenTestDto::getTestDateTime)).findFirst().orElse(null);
immunization.setRelatedCase(new CaseReferenceDto(foundCaseUuid));
if (relevantPathogenTest != null) {
Date latestPositiveTestResultDate = relevantPathogenTest.getTestDateTime();
if (latestPositiveTestResultDate != null) {
immunization.setPositiveTestResultDate(latestPositiveTestResultDate);
}
Date onsetDate = caseDataDto.getSymptoms().getOnsetDate();
if (onsetDate != null) {
immunization.setLastInfectionDate(onsetDate);
}
Date outcomeDate = caseDataDto.getOutcomeDate();
if (outcomeDate != null) {
immunization.setRecoveryDate(outcomeDate);
}
}
this.save(immunization);
return true;
}
return false;
}
use of de.symeda.sormas.api.EntityDto in project SORMAS-Project by hzi-braunschweig.
the class DataHelperTest method testShortUuid.
@Test
public void testShortUuid() {
EntityDto entityDto = new EntityDto() {
};
entityDto.setUuid("ABCDEF-GHIJKL");
assertEquals("ABCDEF", DataHelper.getShortUuid(entityDto));
ReferenceDto referenceDto = new ReferenceDto() {
};
referenceDto.setUuid("MNOPQR-STUVWX");
assertEquals("MNOPQR", DataHelper.getShortUuid(referenceDto));
assertEquals("UZOUEH", DataHelper.getShortUuid("UZOUEH-HP7DRG-YOJ74F-PXWL2JZ4"));
assertNull(DataHelper.getShortUuid((String) null));
boolean exceptionThrown = false;
try {
assertEquals("A", DataHelper.getShortUuid("A"));
fail("getShortUuid should not be graceful on Uuids that are too short.");
} catch (StringIndexOutOfBoundsException e) {
exceptionThrown = true;
}
assertTrue("getShortUuid should throw StringIndexOutOfBoundsException on Uuids that are too short.", exceptionThrown);
}
use of de.symeda.sormas.api.EntityDto in project SORMAS-Project by hzi-braunschweig.
the class SizeGenerator method getSizeOfFilledDto.
private static void getSizeOfFilledDto(PodamFactory factory, Class<? extends EntityDto> dtoClass) throws JsonProcessingException {
final EntityDto dto = factory.manufacturePojo(dtoClass);
Assert.assertNotNull(dto);
final ObjectMapper objectMapper = new ObjectMapper();
final String json = objectMapper.writeValueAsString(dto);
System.out.println(dtoClass.getSimpleName() + " JSON (UTF-8) size: " + Utf8.encodedLength(json));
}
use of de.symeda.sormas.api.EntityDto in project SORMAS-Project by hzi-braunschweig.
the class InfoFacadeEjb method createEntitySheet.
private void createEntitySheet(XSSFWorkbook workbook, Class<? extends EntityDto> entityClass, String i18nPrefix, EnumSet<EntityColumn> entityColumns, List<ColumnData> extraColumns, Map<String, List<XSSFCell>> extraCells) {
String name = I18nProperties.getCaption(i18nPrefix);
String safeName = WorkbookUtil.createSafeSheetName(name);
XSSFSheet sheet = workbook.createSheet(safeName);
int columnCount = entityColumns.size() + extraColumns.size();
int rowNumber = 0;
// header
XSSFRow headerRow = sheet.createRow(rowNumber++);
entityColumns.forEach(column -> {
int colIndex = Math.max(headerRow.getLastCellNum(), 0);
headerRow.createCell(colIndex).setCellValue(column.toString());
sheet.setColumnWidth(colIndex, column.getWidth());
});
extraColumns.forEach(c -> {
short colIndex = headerRow.getLastCellNum();
headerRow.createCell(colIndex).setCellValue(c.header);
sheet.setColumnWidth(colIndex, c.width);
});
CellStyle defaultCellStyle = workbook.createCellStyle();
defaultCellStyle.setWrapText(true);
List<Class<Enum<?>>> usedEnums = new ArrayList<>();
boolean usesFacilityReference = false;
for (Field field : entityClass.getDeclaredFields()) {
if (java.lang.reflect.Modifier.isStatic(field.getModifiers()))
continue;
FieldData fieldData = new FieldData(field, entityClass, i18nPrefix);
XSSFRow row = sheet.createRow(rowNumber++);
for (EntityColumn c : entityColumns) {
XSSFCell newCell = row.createCell(Math.max(row.getLastCellNum(), 0));
String fieldValue = c.getGetValueFromField(fieldData);
if (fieldValue != null) {
newCell.setCellValue(fieldValue);
}
if (c.hasDefaultStyle()) {
newCell.setCellStyle(defaultCellStyle);
}
Class<?> fieldType = field.getType();
if (fieldType.isEnum()) {
if (!usedEnums.contains(fieldType)) {
@SuppressWarnings("unchecked") Class<Enum<?>> enumType = (Class<Enum<?>>) fieldType;
usedEnums.add(enumType);
}
} else if (Map.class.isAssignableFrom(fieldType)) {
getEnumGenericsOf(field, Map.class).filter(e -> !usedEnums.contains(e)).collect(Collectors.toCollection(() -> usedEnums));
} else if (Collection.class.isAssignableFrom(fieldType)) {
getEnumGenericsOf(field, Collection.class).filter(e -> !usedEnums.contains(e)).collect(Collectors.toCollection(() -> usedEnums));
} else if (FacilityReferenceDto.class.isAssignableFrom(fieldType)) {
usesFacilityReference = true;
}
}
String fieldId = EntityColumn.FIELD_ID.getGetValueFromField(fieldData);
if (extraCells.containsKey(fieldId)) {
extraCells.get(fieldId).forEach((extraCell) -> {
XSSFCell newCell = row.createCell(row.getLastCellNum());
if (extraCell != null) {
newCell.copyCellFrom(extraCell, new CellCopyPolicy.Builder().cellValue(true).cellStyle(false).cellFormula(false).build());
}
});
}
}
// Configure table
AreaReference reference = workbook.getCreationHelper().createAreaReference(new CellReference(0, 0), new CellReference(rowNumber - 1, columnCount - 1));
XssfHelper.configureTable(reference, getSafeTableName(safeName), sheet, XssfHelper.TABLE_STYLE_PRIMARY);
// constant facilities
if (usesFacilityReference) {
rowNumber = createFacilityTable(sheet, rowNumber + 1, defaultCellStyle);
}
// enums
for (Class<Enum<?>> usedEnum : usedEnums) {
rowNumber = createEnumTable(sheet, rowNumber + 1, usedEnum);
}
}
use of de.symeda.sormas.api.EntityDto in project SORMAS-Project by hzi-braunschweig.
the class ImportFacadeEjb method appendListOfFields.
/**
* Builds a list of all fields in the case and its relevant sub entities. IMPORTANT: The order
* is not guaranteed; at the time of writing, clazz.getDeclaredFields() seems to return the
* fields in the order of declaration (which is what we need here), but that could change
* in the future.
*/
private void appendListOfFields(List<ImportColumn> importColumns, Class<?> clazz, String prefix, char separator) {
for (Field field : clazz.getDeclaredFields()) {
if (Modifier.isStatic(field.getModifiers())) {
continue;
}
String currentCountry = configFacade.getCountryCode();
CountryFieldVisibilityChecker visibilityChecker = new CountryFieldVisibilityChecker(currentCountry);
if (!visibilityChecker.isVisible(field)) {
continue;
}
Method readMethod;
try {
readMethod = clazz.getDeclaredMethod("get" + WordUtils.capitalize(field.getName()));
} catch (NoSuchMethodException e) {
try {
readMethod = clazz.getDeclaredMethod("is" + WordUtils.capitalize(field.getName()));
} catch (NoSuchMethodException f) {
continue;
}
}
// Fields without a getter or whose getters are declared in a superclass are ignored
if (readMethod.getDeclaringClass() != clazz) {
continue;
}
// Fields with the @ImportIgnore annotation are ignored
if (readMethod.isAnnotationPresent(ImportIgnore.class)) {
continue;
}
// Fields that are depending on a certain feature type to be active may be ignored
if (readMethod.isAnnotationPresent(DependingOnFeatureType.class)) {
List<FeatureType> activeServerFeatures = featureConfigurationFacade.getActiveServerFeatureTypes();
if (!activeServerFeatures.isEmpty() && !activeServerFeatures.contains(readMethod.getAnnotation(DependingOnFeatureType.class).featureType())) {
continue;
}
}
// List types are ignored
if (Collection.class.isAssignableFrom(field.getType())) {
continue;
}
// Certain field types are ignored
if (field.getType() == UserReferenceDto.class) {
continue;
}
// Other non-infrastructure EntityDto/ReferenceDto classes, recursively call this method to include fields of the sub-entity
if (EntityDto.class.isAssignableFrom(field.getType()) && !isInfrastructureClass(field.getType())) {
appendListOfFields(importColumns, field.getType(), StringUtils.isEmpty(prefix) ? field.getName() + "." : prefix + field.getName() + ".", separator);
} else if (PersonReferenceDto.class.isAssignableFrom(field.getType()) && !isInfrastructureClass(field.getType())) {
appendListOfFields(importColumns, PersonDto.class, StringUtils.isEmpty(prefix) ? field.getName() + "." : prefix + field.getName() + ".", separator);
addPrimaryPhoneAndEmail(separator, importColumns);
} else {
importColumns.add(ImportColumn.from(clazz, prefix + field.getName(), field.getType(), separator));
}
}
}
Aggregations