Skip to content

Commit

Permalink
RESTWS-930: Avoid appending extraneous encounter providers to encount…
Browse files Browse the repository at this point in the history
…er (#598)
  • Loading branch information
icrc-psousa authored Feb 20, 2024
1 parent 417b277 commit ef08d07
Showing 1 changed file with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.openmrs.api.context.Context;
import org.openmrs.module.webservices.rest.web.RestConstants;
import org.openmrs.module.webservices.rest.web.annotation.PropertyGetter;
import org.openmrs.module.webservices.rest.web.annotation.PropertySetter;
import org.openmrs.module.webservices.rest.web.annotation.Resource;
import org.openmrs.module.webservices.rest.web.representation.DefaultRepresentation;
import org.openmrs.module.webservices.rest.web.representation.FullRepresentation;
Expand All @@ -23,6 +24,7 @@
import org.openmrs.module.webservices.rest.web.response.ResourceDoesNotSupportOperationException;

import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;

/**
Expand Down Expand Up @@ -93,6 +95,23 @@ public static Set<EncounterProvider> getActiveEncounterProviders(Encounter insta
}
return providers;
}

@PropertySetter("encounterProviders")
public void setEncounterProviders(Encounter instance, List<EncounterProvider> encounterProviders) {
for (EncounterProvider newEncounterProvider : encounterProviders) {
boolean isProviderAlreadyPresent = false;
for (EncounterProvider existingProvider : instance.getEncounterProviders()) {
if (existingProvider.getProvider().getUuid().equals(newEncounterProvider.getProvider().getUuid())
&& existingProvider.getEncounterRole().getUuid().equals(newEncounterProvider.getEncounterRole().getUuid())) {
isProviderAlreadyPresent = true;
break;
}
}
if (!isProviderAlreadyPresent) {
instance.getEncounterProviders().add(newEncounterProvider);
}
}
}

/**
* @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getResourceVersion()
Expand Down

0 comments on commit ef08d07

Please sign in to comment.