Skip to content

Commit

Permalink
fix dataElementIdScheme param
Browse files Browse the repository at this point in the history
  • Loading branch information
teleivo committed Nov 12, 2024
1 parent 593b595 commit 69d0040
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ private Event getEvent(
.orgUnitMode(OrganisationUnitSelectionMode.ACCESSIBLE)
.events(Set.of(eventUid))
.eventParams(eventParams)
.idSchemeParams(idSchemeParams)
.build();
events = getEvents(operationParams, new PageParams(1, 1, false));
} catch (BadRequestException e) {
Expand Down Expand Up @@ -247,7 +248,8 @@ public List<Event> getEvents(@Nonnull EventOperationParams operationParams)
}

@Override
public Page<Event> getEvents(EventOperationParams operationParams, PageParams pageParams)
public Page<Event> getEvents(
@Nonnull EventOperationParams operationParams, @Nonnull PageParams pageParams)
throws BadRequestException, ForbiddenException {
EventQueryParams queryParams = paramsMapper.map(operationParams, getCurrentUserDetails());
return eventStore.getEvents(queryParams, pageParams);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ FileResourceStream getFileResourceImage(UID event, UID dataElement, ImageFileDim

/**
* Get event matching given {@code UID} under the privileges of the currently authenticated user.
* Metadata identifiers will use the {@code idScheme} defined by {@link TrackerIdSchemeParams}.
* Use {@link #getEvent(UID, EventParams)} instead to also get the events relationships.
*/
Event getEvent(UID uid, @Nonnull TrackerIdSchemeParams idSchemeParams)
Expand All @@ -81,14 +82,14 @@ Event getEvent(UID uid, @Nonnull TrackerIdSchemeParams idSchemeParams)

/**
* Get event matching given {@code UID} and params under the privileges of the currently
* authenticated user.
* authenticated user. Metadata identifiers will use the {@code idScheme} defined by {@link
* TrackerIdSchemeParams}.
*/
Event getEvent(UID uid, @Nonnull TrackerIdSchemeParams idSchemeParams, EventParams eventParams)
throws NotFoundException, ForbiddenException;

/**
* Get all events matching given params under the privileges of the currently authenticated user.
* Metadata identifiers will use the {@code idScheme} defined by {@link TrackerIdSchemeParams}.
*/
@Nonnull
List<Event> getEvents(@Nonnull EventOperationParams params)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -411,15 +411,31 @@ private List<Event> fetchEvents(EventQueryParams queryParams, PageParams pagePar
for (String uid : dataValuesObject.names()) {
JsonObject dataValueJson = dataValuesObject.getObject(uid);
EventDataValue eventDataValue = new EventDataValue();
// TODO(ivo) EventDataValues are different than other data. It has no reference to
// metadata but only a String field. To support idSchemes on export we can either
// set the String to uid, code, name or the attribute value of given attribute:uid
// or we need to refactor the type to use either a reference to DataElement or to
// use the MedatadataIdentifier. I assume String was chosen to allow storing this
// as JSONB
eventDataValue.setDataElement(
dataValueJson.getString("dataElementCode").string(""));
// eventDataValue.setDataElement(uid);
switch (queryParams.getIdSchemeParams().getDataElementIdScheme().getIdScheme()) {
case CODE:
eventDataValue.setDataElement(
dataValueJson.getString("dataElementCode").string(""));
break;
case NAME:
eventDataValue.setDataElement(
dataValueJson.getString("dataElementName").string(""));
break;
case ATTRIBUTE:
String attributeUid =
queryParams
.getIdSchemeParams()
.getDataElementIdScheme()
.getAttributeUid();
JsonObject attributeValue =
dataValueJson
.getObject("dataElementAttributeValues")
.getObject(attributeUid);
eventDataValue.setDataElement(attributeValue.getString("value").string(""));
break;
default:
eventDataValue.setDataElement(uid);
break;
}
eventDataValue.setValue(dataValueJson.getString("value").string(""));
eventDataValue.setProvidedElsewhere(
dataValueJson.getBoolean("providedElsewhere").booleanValue(false));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,11 +256,10 @@ void shouldExportMetadataUsingGivenIdScheme(TrackerIdSchemeParam idSchemeParam)

public static Stream<TrackerIdSchemeParam> shouldExportMetadataUsingGivenIdSchemeProvider() {
return Stream.of(
// TrackerIdSchemeParam.UID,
// TrackerIdSchemeParam.CODE,
// TrackerIdSchemeParam.NAME,
TrackerIdSchemeParam.NAME);
// TrackerIdSchemeParam.ofAttribute(METADATA_ATTRIBUTE));
TrackerIdSchemeParam.UID,
TrackerIdSchemeParam.CODE,
TrackerIdSchemeParam.NAME,
TrackerIdSchemeParam.ofAttribute(METADATA_ATTRIBUTE));
}

/**
Expand Down
Loading

0 comments on commit 69d0040

Please sign in to comment.