Skip to content
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

TRUNK-5007: Enable the ExistingOrNewVisitAssignmentHandler to handle wild cards for encounter type to visit type. #4603

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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 @@ -112,14 +112,15 @@ private static VisitType loadVisitType(EncounterType encounterType) throws APIEx

VisitService visitService = Context.getVisitService();
String targetEncounterTypeId = encounterType.getId().toString();
String targetEncounterTypeUuid = encounterType.getUuid();

String[] mappings = value.split(",");
for (String mapping : mappings) {
int index = mapping.indexOf(':');
if (index > 0) {
String encounterTypeIdOrUuid = mapping.substring(0, index).trim();
if (targetEncounterTypeId.equals(encounterTypeIdOrUuid)
|| encounterType.getUuid().equals(encounterTypeIdOrUuid)) {
if ("default".equals(encounterTypeIdOrUuid) || targetEncounterTypeId.equals(encounterTypeIdOrUuid)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you describe what you are trying to achieve with default?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I understood from the ticket TRUNK-5007 and ticket EA-116 is that the default wildcard should be used if no specific encounter type is matched and beforeCreateEncounter() from ExistingOrNewVisitAssignmentHandler should be able to handle the default wildcard EncounterType from the globalPropertymappings value.

|| targetEncounterTypeUuid.equals(encounterTypeIdOrUuid)) {
String visitTypeIdOrUuid = mapping.substring(index + 1).trim();
VisitType visitType;
if (StringUtils.isNumeric(visitTypeIdOrUuid)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,77 @@ public void beforeCreateEncounter_shouldResolveEncounterAndVisitTypeUuidsAsGloba
assertEquals(Context.getVisitService().getVisitTypeByUuid(visitTypeUuid), encounter.getVisit()
.getVisitType());
}

/**
* @see org.openmrs.api.handler.ExistingOrNewVisitAssignmentHandler#beforeCreateEncounter(Encounter)
*/
@Test
public void beforeCreateEncounter_shouldResolveDefaultWildCardEncounterTypeAndVisitTypeIdMappingGlobalPropertyValues() {
Encounter encounter = Context.getEncounterService().getEncounter(1);
assertNull(encounter.getVisit());

Calendar calendar = Calendar.getInstance();
calendar.setTime(encounter.getEncounterDatetime());
calendar.set(Calendar.YEAR, 1900);

encounter.setEncounterDatetime(calendar.getTime());

GlobalProperty gp = new GlobalProperty(OpenmrsConstants.GP_ENCOUNTER_TYPE_TO_VISIT_TYPE_MAPPING, "default:2");
Context.getAdministrationService().saveGlobalProperty(gp);

new ExistingOrNewVisitAssignmentHandler().beforeCreateEncounter(encounter);

assertNotNull(encounter.getVisit());
assertEquals(Context.getVisitService().getVisitType(2), encounter.getVisit().getVisitType());
}

/**
* @see org.openmrs.api.handler.ExistingOrNewVisitAssignmentHandler#beforeCreateEncounter(Encounter)
*/
@Test
public void beforeCreateEncounter_shouldResolveDefaultWildCardEncounterTypeAndVisitTypeUuidMappingGlobalPropertyValues() {
Encounter encounter = Context.getEncounterService().getEncounter(1);
assertNull(encounter.getVisit());

Calendar calendar = Calendar.getInstance();
calendar.setTime(encounter.getEncounterDatetime());
calendar.set(Calendar.YEAR, 1900);

encounter.setEncounterDatetime(calendar.getTime());

GlobalProperty gp = new GlobalProperty(OpenmrsConstants.GP_ENCOUNTER_TYPE_TO_VISIT_TYPE_MAPPING,
"default:c0c579b0-8e59-401d-8a4a-976a0b183519");
Context.getAdministrationService().saveGlobalProperty(gp);

new ExistingOrNewVisitAssignmentHandler().beforeCreateEncounter(encounter);

assertNotNull(encounter.getVisit());
assertEquals(Context.getVisitService().getVisitTypeByUuid("c0c579b0-8e59-401d-8a4a-976a0b183519"),
encounter.getVisit().getVisitType());
}

/**
* @see org.openmrs.api.handler.ExistingOrNewVisitAssignmentHandler#beforeCreateEncounter(Encounter)
*/
@Test
public void beforeCreateEncounter_shouldResolveDefaultWildCardEncounterTypeMappingsOverrideGlobalPropertyValues() {
Encounter encounter = Context.getEncounterService().getEncounter(1);
assertNull(encounter.getVisit());

Calendar calendar = Calendar.getInstance();
calendar.setTime(encounter.getEncounterDatetime());
calendar.set(Calendar.YEAR, 1900);

encounter.setEncounterDatetime(calendar.getTime());

GlobalProperty gp = new GlobalProperty(OpenmrsConstants.GP_ENCOUNTER_TYPE_TO_VISIT_TYPE_MAPPING,
"3:4, 5:2, default:c0c579b0-8e59-401d-8a4a-976a0b183519, 2:2");
Context.getAdministrationService().saveGlobalProperty(gp);

new ExistingOrNewVisitAssignmentHandler().beforeCreateEncounter(encounter);

assertNotNull(encounter.getVisit());
assertEquals(Context.getVisitService().getVisitTypeByUuid("c0c579b0-8e59-401d-8a4a-976a0b183519"),
encounter.getVisit().getVisitType());
}
}
Loading