Skip to content

Commit

Permalink
Make default encounter role configurable through GP
Browse files Browse the repository at this point in the history
  • Loading branch information
icrc-psousa committed Jul 2, 2024
1 parent 16bea46 commit af66ac6
Showing 1 changed file with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.openmrs.EncounterProvider;
import org.openmrs.EncounterRole;
import org.openmrs.api.EncounterService;
import org.openmrs.module.fhir2.api.FhirGlobalPropertyService;
import org.openmrs.module.fhir2.api.dao.FhirPractitionerDao;
import org.openmrs.module.fhir2.api.translators.EncounterParticipantTranslator;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -28,12 +29,17 @@
@Setter(AccessLevel.PACKAGE)
public class EncounterParticipantTranslatorImpl extends BaseReferenceHandlingTranslator implements EncounterParticipantTranslator {

private static final String DEFAULT_ENCOUNTER_ROLE_UUID = "fhir2.encounterParticipantComponentUuid";

@Autowired
private FhirPractitionerDao practitionerDao;

@Autowired
private EncounterService encounterService;

@Autowired
private FhirGlobalPropertyService globalPropertyService;

@Override
public Encounter.EncounterParticipantComponent toFhirResource(@Nonnull EncounterProvider encounterProvider) {
if (encounterProvider == null || encounterProvider.getVoided()) {
Expand Down Expand Up @@ -62,10 +68,18 @@ public EncounterProvider toOpenmrsType(@Nonnull EncounterProvider encounterProvi
}

protected EncounterRole getDefaultEncounterRole() {
EncounterRole role = encounterService.getEncounterRoleByName("Unknown");
String defaultEncounterRoleUuid = globalPropertyService.getGlobalProperty(DEFAULT_ENCOUNTER_ROLE_UUID);

String encounterRoleUuid = (defaultEncounterRoleUuid != null && !defaultEncounterRoleUuid.isEmpty())
? defaultEncounterRoleUuid
: EncounterRole.UNKNOWN_ENCOUNTER_ROLE_UUID;

EncounterRole role = encounterService.getEncounterRoleByUuid(encounterRoleUuid);

if (role == null) {
throw new IllegalStateException("Missing encounter role named 'Unknown'");
throw new IllegalStateException("Default encounter role not found: " + encounterRoleUuid);
}

return role;
}
}

0 comments on commit af66ac6

Please sign in to comment.