-
Notifications
You must be signed in to change notification settings - Fork 342
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Skip mandatory data value validation for UPDATE [DHIS2-17560] #17835
Changes from all commits
4fa229d
73b7d37
fa0bbb9
5f7adf7
64f40ef
e047ccd
2b39767
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,7 @@ | |
import java.util.List; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
import javax.annotation.Nonnull; | ||
import org.hisp.dhis.common.CodeGenerator; | ||
import org.hisp.dhis.common.ValueType; | ||
import org.hisp.dhis.common.ValueTypedDimensionalItemObject; | ||
|
@@ -99,24 +100,48 @@ public static List<Note> validateNotes( | |
return notes; | ||
} | ||
|
||
public static List<MetadataIdentifier> validateMandatoryDataValue( | ||
ProgramStage programStage, Event event, List<MetadataIdentifier> mandatoryDataElements) { | ||
List<MetadataIdentifier> notPresentMandatoryDataElements = Lists.newArrayList(); | ||
|
||
public static List<MetadataIdentifier> validateDeletionMandatoryDataValue( | ||
Event event, ProgramStage programStage, List<MetadataIdentifier> mandatoryDataElements) { | ||
if (!needsToValidateDataValues(event, programStage)) { | ||
return notPresentMandatoryDataElements; | ||
return List.of(); | ||
} | ||
Set<MetadataIdentifier> eventDataElements = | ||
event.getDataValues().stream() | ||
.filter(dv -> dv.getValue() == null) | ||
.map(DataValue::getDataElement) | ||
.collect(Collectors.toSet()); | ||
|
||
return mandatoryDataElements.stream().filter(eventDataElements::contains).toList(); | ||
} | ||
|
||
public static List<MetadataIdentifier> validateMandatoryDataValue( | ||
TrackerBundle bundle, | ||
Event event, | ||
ProgramStage programStage, | ||
List<MetadataIdentifier> mandatoryDataElements) { | ||
if (!areDataValuesBeingCreated(bundle, event, programStage)) { | ||
return List.of(); | ||
} | ||
|
||
Set<MetadataIdentifier> eventDataElements = | ||
event.getDataValues().stream().map(DataValue::getDataElement).collect(Collectors.toSet()); | ||
|
||
for (MetadataIdentifier mandatoryDataElement : mandatoryDataElements) { | ||
if (!eventDataElements.contains(mandatoryDataElement)) { | ||
notPresentMandatoryDataElements.add(mandatoryDataElement); | ||
} | ||
return mandatoryDataElements.stream().filter(de -> !eventDataElements.contains(de)).toList(); | ||
} | ||
|
||
public static boolean areDataValuesBeingCreated( | ||
TrackerBundle bundle, Event event, ProgramStage programStage) { | ||
if (!needsToValidateDataValues(event, programStage)) { | ||
return false; | ||
} | ||
|
||
if (bundle.getStrategy(event).isCreate()) { | ||
return true; | ||
} | ||
|
||
return notPresentMandatoryDataElements; | ||
EventStatus savedStatus = bundle.getPreheat().getEvent(event.getUid()).getStatus(); | ||
return EventStatus.STATUSES_WITHOUT_DATA_VALUES.contains(savedStatus) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do the event statuses There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes they do. They have the exact same behaviour as |
||
&& EventStatus.STATUSES_WITH_DATA_VALUES.contains(event.getStatus()); | ||
} | ||
|
||
public static boolean needsToValidateDataValues(Event event, ProgramStage programStage) { | ||
|
@@ -167,8 +192,8 @@ public static boolean eventExist(TrackerBundle bundle, String eventUid) { | |
} | ||
|
||
public static <T extends ValueTypedDimensionalItemObject> void validateOptionSet( | ||
Reporter reporter, TrackerDto dto, T optionalObject, String value) { | ||
if (value == null || !optionalObject.hasOptionSet()) { | ||
Reporter reporter, TrackerDto dto, T optionalObject, @Nonnull String value) { | ||
if (!optionalObject.hasOptionSet()) { | ||
return; | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
out of the scope of this PR, but why do we skip the validation if the event status is
SCHEDULE
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A
SCHEDULE
event is created at some point in time but it is meant to happen later at some point, so when it is created it is kind ofempty
and it doesn't make sense to require mandatory data values at that point.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and in that case, are we covered if I create and event this way, and then I provide the values later on?
what I mean by that is, at the moment I provide the values, do we treat it as an import strategy
CREATE
again to make sure all mandatory fields are set?if it's something different than
CREATE
, then I guess I could have mandatory values set to null, couldn't I?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh no, you are right.
At the moment if you create a schedule event without the mandatory datavalues and later you just change the status of the event then you can have an empty mandatory datavalues were they are meant to be present.
Will need to check how we manage the transition from a status to another