This repository has been archived by the owner on Sep 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
3311: Refactored visits/encounter listeners into advice classes (#8)
- Loading branch information
1 parent
4cec7e0
commit 7c8b942
Showing
11 changed files
with
106 additions
and
1,051 deletions.
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
api/src/main/java/org/openmrs/module/cflcore/advice/UpdateEncounterAdvice.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* This Source Code Form is subject to the terms of the Mozilla Public License, | ||
* v. 2.0. If a copy of the MPL was not distributed with this file, You can | ||
* obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under | ||
* the terms of the Healthcare Disclaimer located at http://openmrs.org/license. | ||
* <p> | ||
* Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS | ||
* graphic logo is a trademark of OpenMRS Inc. | ||
*/ | ||
|
||
package org.openmrs.module.cflcore.advice; | ||
|
||
import org.openmrs.Encounter; | ||
import org.openmrs.Visit; | ||
import org.openmrs.api.context.Context; | ||
import org.openmrs.module.cflcore.api.service.ConfigService; | ||
import org.openmrs.module.cflcore.api.service.VaccinationService; | ||
import org.openmrs.module.cflcore.api.util.VisitUtil; | ||
import org.springframework.aop.AfterReturningAdvice; | ||
import java.lang.reflect.Method; | ||
import java.util.Date; | ||
|
||
public class UpdateEncounterAdvice implements AfterReturningAdvice { | ||
|
||
private static final String SAVE_ENCOUNTER_METHOD_NAME = "saveEncounter"; | ||
|
||
@Override | ||
public void afterReturning(Object o, Method method, Object[] objects, Object o1) { | ||
if (SAVE_ENCOUNTER_METHOD_NAME.equals(method.getName())) { | ||
Encounter encounter = (Encounter) objects[0]; | ||
updateEncounterVisit(encounter.getVisit()); | ||
createFutureVisits(encounter); | ||
} | ||
} | ||
|
||
private void updateEncounterVisit(Visit encounterVisit) { | ||
if (encounterVisit != null) { | ||
encounterVisit.setDateChanged(new Date()); | ||
encounterVisit.setChangedBy(Context.getAuthenticatedUser()); | ||
Context.getVisitService().saveVisit(encounterVisit); | ||
} | ||
} | ||
|
||
private void createFutureVisits(Encounter newEncounter) { | ||
if (isVaccinationEncounter(newEncounter) && newEncounter.getVisit() != null) { | ||
final Visit updatedVisit = newEncounter.getVisit(); | ||
final String visitStatus = VisitUtil.getVisitStatus(updatedVisit); | ||
|
||
if (visitStatus.equals(VisitUtil.getOccurredVisitStatus())) { | ||
Context.getService(VaccinationService.class) | ||
.createFutureVisits(updatedVisit, newEncounter.getEncounterDatetime()); | ||
} | ||
} | ||
} | ||
|
||
private boolean isVaccinationEncounter(Encounter newEncounter) { | ||
return getConfigService() | ||
.getVaccinationEncounterTypeUUIDs() | ||
.contains(newEncounter.getEncounterType().getUuid()); | ||
} | ||
|
||
private ConfigService getConfigService() { | ||
return Context.getService(ConfigService.class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 0 additions & 43 deletions
43
...a/org/openmrs/module/cflcore/api/event/listener/subscribable/EncounterActionListener.java
This file was deleted.
Oops, something went wrong.
95 changes: 0 additions & 95 deletions
95
.../openmrs/module/cflcore/api/event/listener/subscribable/VaccinationEncounterListener.java
This file was deleted.
Oops, something went wrong.
48 changes: 0 additions & 48 deletions
48
.../java/org/openmrs/module/cflcore/api/event/listener/subscribable/VisitActionListener.java
This file was deleted.
Oops, something went wrong.
45 changes: 0 additions & 45 deletions
45
...va/org/openmrs/module/cflcore/api/event/listener/subscribable/VisitEncounterListener.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.