-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RA-1397 - Ensure all data submitted by registrationapp are saved with…
…in a transaction (#136)
- Loading branch information
Showing
7 changed files
with
382 additions
and
54 deletions.
There are no files selected for viewing
105 changes: 105 additions & 0 deletions
105
api/src/main/java/org/openmrs/module/registrationapp/api/RegistrationAppData.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,105 @@ | ||
/* | ||
* 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. | ||
* | ||
* Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS | ||
* graphic logo is a trademark of OpenMRS Inc. | ||
*/ | ||
package org.openmrs.module.registrationapp.api; | ||
|
||
import org.openmrs.Encounter; | ||
import org.openmrs.Location; | ||
import org.openmrs.Obs; | ||
import org.openmrs.module.registrationapp.action.AfterPatientCreatedAction; | ||
import org.openmrs.module.registrationcore.RegistrationData; | ||
|
||
import java.io.Serializable; | ||
import java.util.ArrayList; | ||
import java.util.Date; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
/** | ||
* Encapsulates the data that may be collected and saved within a patient registration transaction | ||
*/ | ||
public class RegistrationAppData implements Serializable { | ||
|
||
private Date registrationDate; | ||
private Location registrationLocation; | ||
private RegistrationData registrationData; | ||
private Encounter registrationEncounter; | ||
private List<Obs> registrationObs; | ||
private List<AfterPatientCreatedAction> afterPatientCreatedActions; | ||
private Map<String, String[]> parameters; | ||
|
||
public RegistrationAppData() { | ||
} | ||
|
||
public Date getRegistrationDate() { | ||
return registrationDate; | ||
} | ||
|
||
public void setRegistrationDate(Date registrationDate) { | ||
this.registrationDate = registrationDate; | ||
} | ||
|
||
public Location getRegistrationLocation() { | ||
return registrationLocation; | ||
} | ||
|
||
public void setRegistrationLocation(Location registrationLocation) { | ||
this.registrationLocation = registrationLocation; | ||
} | ||
|
||
public RegistrationData getRegistrationData() { | ||
return registrationData; | ||
} | ||
|
||
public void setRegistrationData(RegistrationData registrationData) { | ||
this.registrationData = registrationData; | ||
} | ||
|
||
public Encounter getRegistrationEncounter() { | ||
return registrationEncounter; | ||
} | ||
|
||
public void setRegistrationEncounter(Encounter registrationEncounter) { | ||
this.registrationEncounter = registrationEncounter; | ||
} | ||
|
||
public List<Obs> getRegistrationObs() { | ||
if (registrationObs == null) { | ||
registrationObs = new ArrayList<Obs>(); | ||
} | ||
return registrationObs; | ||
} | ||
|
||
public void setRegistrationObs(List<Obs> registrationObs) { | ||
this.registrationObs = registrationObs; | ||
} | ||
|
||
public List<AfterPatientCreatedAction> getAfterPatientCreatedActions() { | ||
if (afterPatientCreatedActions == null) { | ||
afterPatientCreatedActions = new ArrayList<AfterPatientCreatedAction>(); | ||
} | ||
return afterPatientCreatedActions; | ||
} | ||
|
||
public void setAfterPatientCreatedActions(List<AfterPatientCreatedAction> afterPatientCreatedActions) { | ||
this.afterPatientCreatedActions = afterPatientCreatedActions; | ||
} | ||
|
||
public Map<String, String[]> getParameters() { | ||
if (parameters == null) { | ||
parameters = new HashMap<String, String[]>(); | ||
} | ||
return parameters; | ||
} | ||
|
||
public void setParameters(Map<String, String[]> parameters) { | ||
this.parameters = parameters; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
api/src/main/java/org/openmrs/module/registrationapp/api/RegistrationAppService.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,28 @@ | ||
/** | ||
* The contents of this file are subject to the OpenMRS Public License | ||
* Version 1.0 (the "License"); you may not use this file except in | ||
* compliance with the License. You may obtain a copy of the License at | ||
* http://license.openmrs.org | ||
* | ||
* Software distributed under the License is distributed on an "AS IS" | ||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing rights and limitations | ||
* under the License. | ||
* | ||
* Copyright (C) OpenMRS, LLC. All Rights Reserved. | ||
*/ | ||
package org.openmrs.module.registrationapp.api; | ||
|
||
import org.openmrs.Patient; | ||
import org.openmrs.api.OpenmrsService; | ||
|
||
/** | ||
* This service provides transactional services for the registration app module | ||
*/ | ||
public interface RegistrationAppService extends OpenmrsService { | ||
|
||
/** | ||
* Registers patient, along with associated registration data | ||
*/ | ||
Patient registerPatient(RegistrationAppData registrationData); | ||
} |
85 changes: 85 additions & 0 deletions
85
api/src/main/java/org/openmrs/module/registrationapp/api/RegistrationAppServiceImpl.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,85 @@ | ||
/** | ||
* The contents of this file are subject to the OpenMRS Public License | ||
* Version 1.0 (the "License"); you may not use this file except in | ||
* compliance with the License. You may obtain a copy of the License at | ||
* http://license.openmrs.org | ||
* | ||
* Software distributed under the License is distributed on an "AS IS" | ||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing rights and limitations | ||
* under the License. | ||
* | ||
* Copyright (C) OpenMRS, LLC. All Rights Reserved. | ||
*/ | ||
package org.openmrs.module.registrationapp.api; | ||
|
||
import org.openmrs.Encounter; | ||
import org.openmrs.Obs; | ||
import org.openmrs.Patient; | ||
import org.openmrs.api.EncounterService; | ||
import org.openmrs.api.ObsService; | ||
import org.openmrs.api.impl.BaseOpenmrsService; | ||
import org.openmrs.module.registrationapp.action.AfterPatientCreatedAction; | ||
import org.openmrs.module.registrationcore.api.RegistrationCoreService; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.Date; | ||
|
||
/** | ||
* This service provides transactional services for the registration app module | ||
*/ | ||
@Transactional | ||
public class RegistrationAppServiceImpl extends BaseOpenmrsService implements RegistrationAppService { | ||
|
||
private RegistrationCoreService registrationCoreService; | ||
private EncounterService encounterService; | ||
private ObsService obsService; | ||
|
||
@Override | ||
public Patient registerPatient(RegistrationAppData registrationAppData) { | ||
Patient patient = registrationCoreService.registerPatient(registrationAppData.getRegistrationData()); | ||
|
||
Encounter registrationEncounter = registrationAppData.getRegistrationEncounter(); | ||
for (Obs o : registrationAppData.getRegistrationObs()) { | ||
if (registrationEncounter != null) { | ||
registrationEncounter.addObs(o); | ||
} | ||
else { | ||
if (o.getPerson() == null) { | ||
o.setPerson(patient); | ||
} | ||
if (o.getLocation() == null) { | ||
o.setLocation(registrationAppData.getRegistrationLocation()); | ||
} | ||
if (o.getObsDatetime() == null) { | ||
o.setObsDatetime(registrationAppData.getRegistrationDate()); | ||
if (o.getObsDatetime() == null) { | ||
o.setObsDatetime(new Date()); | ||
} | ||
} | ||
obsService.saveObs(o, null); | ||
} | ||
} | ||
if (registrationEncounter != null) { | ||
encounterService.saveEncounter(registrationEncounter); | ||
} | ||
|
||
for (AfterPatientCreatedAction action : registrationAppData.getAfterPatientCreatedActions()) { | ||
action.afterPatientCreated(patient, registrationAppData.getParameters()); | ||
} | ||
|
||
return patient; | ||
} | ||
|
||
public void setRegistrationCoreService(RegistrationCoreService registrationCoreService) { | ||
this.registrationCoreService = registrationCoreService; | ||
} | ||
|
||
public void setEncounterService(EncounterService encounterService) { | ||
this.encounterService = encounterService; | ||
} | ||
|
||
public void setObsService(ObsService obsService) { | ||
this.obsService = obsService; | ||
} | ||
} |
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
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
Oops, something went wrong.