Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,7 @@ private Object getObservationValue(FormElement formElement, String answerValue,
return handleDateValue(answerValue, errorMsgs, concept);
case DateTime:
return handleDateTimeValue(answerValue, errorMsgs, concept);
case Image:
case ImageV2:
case Video:
case Image, ImageV2, Video, Signature:
return handleMediaValue(formElement, answerValue, errorMsgs, oldValue);
case Subject:
return individualService.getObservationValueForUpload(formElement, answerValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ private void validateAnswer(Concept question, FormElement formElement, Object va
if (value == null || (value instanceof String && ((String) value).trim().isEmpty())) {
return;
}

ConceptDataType dataType = ConceptDataType.valueOf(question.getDataType());
switch (dataType) {
case Coded:
Expand Down Expand Up @@ -182,8 +182,7 @@ private void validateAnswer(Concept question, FormElement formElement, Object va
case PhoneNumber:
validatePhoneNumberValue(question, value, errorMessages);
break;
case Image:
case ImageV2:
case Image, ImageV2, Signature:
validateImageValue(question, value, errorMessages);
break;
default:
Expand All @@ -193,7 +192,7 @@ private void validateAnswer(Concept question, FormElement formElement, Object va

private void validateCodedValue(Concept question, Object value, List<String> errorMessages) {
if (question.getConceptAnswers().stream().noneMatch(ans -> ans.getAnswerConcept().getUuid().equals(value))) {
errorMessages.add(String.format("Concept answer '%s' not found in Concept '%s' (%s)",
errorMessages.add(String.format("Concept answer '%s' not found in Concept '%s' (%s)",
value, question.getName(), question.getUuid()));
}
}
Expand Down Expand Up @@ -257,9 +256,9 @@ private void validateSubjectValue(Concept question, Object value, List<String> e
if (keyValues != null && keyValues.containsKey(KeyType.subjectTypeUUID)) {
KeyValue keyValue = keyValues.get(KeyType.subjectTypeUUID);
String subjectTypeUuid = keyValue.getValue().toString();

SubjectType subjectType = subjectTypeRepository.findByUuid(subjectTypeUuid);

if (subjectType != null && individualRepository.findByLegacyIdOrUuidAndSubjectType((String) value, subjectType) == null) {
errorMessages.add(formatErrorMessage(question, value));
}
Expand All @@ -278,33 +277,33 @@ private void validateLocationValue(Concept question, Object value, List<String>
if (keyValues != null && keyValues.containsKey(KeyType.lowestAddressLevelTypeUUIDs)) {
KeyValue keyValue = keyValues.get(KeyType.lowestAddressLevelTypeUUIDs);
Object keyValueObj = keyValue.getValue();

if (keyValueObj instanceof List<?>) {
// Safe cast with instanceof check
@SuppressWarnings("unchecked")
List<String> lowestLevelUuids = (List<String>) keyValueObj;

List<AddressLevelType> lowestLevels = lowestLevelUuids.stream()
.map(addressLevelTypeRepository::findByUuid)
.filter(Objects::nonNull)
.toList();

boolean isValid = lowestLevels.stream()
.map(AddressLevelType::getAddressLevels)
.flatMap(Collection::stream)
.map(AddressLevel::getUuid)
.toList()
.contains(value);

if (!isValid) {
errorMessages.add(formatErrorMessage(question, value));
}
} else {
errorMessages.add(String.format("Invalid lowest address level type for concept '%s'",
errorMessages.add(String.format("Invalid lowest address level type for concept '%s'",
question.getName()));
}
} else {
errorMessages.add(String.format("Missing lowest address level type for concept '%s'",
errorMessages.add(String.format("Missing lowest address level type for concept '%s'",
question.getName()));
}
} catch (Exception e) {
Expand All @@ -330,8 +329,8 @@ private void validateImageValue(Concept question, Object value, List<String> err
URL dummyUrl = s3Service.generateMediaUploadUrl("dummy.jpg", HttpMethod.PUT);
// Use non-deprecated constructor for URL
URL imageUrl = new URI(value.toString()).toURL();
if (!Objects.equals(dummyUrl.getProtocol(), imageUrl.getProtocol()) ||

if (!Objects.equals(dummyUrl.getProtocol(), imageUrl.getProtocol()) ||
!Objects.equals(dummyUrl.getHost(), imageUrl.getHost())) {
errorMessages.add(formatErrorMessage(question, value));
}
Expand Down Expand Up @@ -362,7 +361,7 @@ private void splitQuestionGroupValueIfRequiredAndThenValidate(FormElement formEl
validateCollectionItem(formElement, qGroupValue, formMapping, errorMessages);
}
}

private void validateChildObservation(FormElement questionGroupFormElement, Map<String, Object> qGroupValueInstance, FormMapping formMapping, List<String> errorMessages) {
LinkedHashMap<String, FormElement> formElements = formMappingService.getEntityConceptMapForSpecificQuestionGroupFormElement(questionGroupFormElement, formMapping, INCLUDE_VOIDED_FORM_ELEMENTS);
List<ObservationRequest> observationRequests = qGroupValueInstance.entrySet().stream().map(this::createObservationRequest).collect(Collectors.toList());
Expand All @@ -379,14 +378,14 @@ private void validateChildObservation(FormElement questionGroupFormElement, Map<

validateConceptValuesAreOfRequiredType(observationRequests, formElements, formMapping, errorMessages);
}

private void validateCollectionItem(FormElement formElement, Object item, FormMapping formMapping, List<String> errorMessages) {
if (item instanceof Map) {
@SuppressWarnings("unchecked")
Map<String, Object> valueMap = (Map<String, Object>) item;
validateChildObservation(formElement, valueMap, formMapping, errorMessages);
} else {
errorMessages.add(String.format("Invalid question group value type for concept '%s'",
errorMessages.add(String.format("Invalid question group value type for concept '%s'",
formElement.getConcept().getName()));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ public enum ConceptDataType {
Audio,
File,
QuestionGroup,
Encounter;
Encounter,
Signature;

private static final List<ConceptDataType> dateTypes = Arrays.asList(Date, DateTime, Duration, Time);
public static final List<ConceptDataType> dashboardFilterSupportedTypes = Arrays.asList(Numeric, Text, Notes, Coded, Date, DateTime, Time, Id, Location);
public static final List<ConceptDataType> mediaDataTypes = Arrays.asList(Image, ImageV2, Video, File, Audio);
public static final List<ConceptDataType> mediaDataTypes = Arrays.asList(Image, ImageV2, Video, File, Audio, Signature);
public static final List<ConceptDataType> multiSelectTypes = Arrays.asList(Coded, Subject, Image, ImageV2, Video, File, Encounter);

public static boolean dateType(String dataType) {
Expand Down