-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Old address will be voided and not overriden when address is edited f…
…rom web form
- Loading branch information
1 parent
0d2f245
commit ea53c46
Showing
5 changed files
with
133 additions
and
12 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
motech-server-core/src/main/java/org/motechproject/server/model/PatientAddress.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,46 @@ | ||
package org.motechproject.server.model; | ||
|
||
import org.motechproject.server.model.ghana.Community; | ||
import org.motechproject.server.model.ghana.Facility; | ||
import org.openmrs.Location; | ||
import org.openmrs.PersonAddress; | ||
|
||
public class PatientAddress { | ||
private Location location; | ||
private Community community; | ||
private String addressLine1; | ||
|
||
public PatientAddress near(Facility facility) { | ||
this.location = facility.getLocation(); | ||
return this; | ||
} | ||
|
||
public PatientAddress in(Location location) { | ||
this.location = location; | ||
return this; | ||
} | ||
|
||
public PatientAddress in(Community community) { | ||
this.community = community; | ||
return this; | ||
} | ||
|
||
public PatientAddress at(String addressLine1) { | ||
this.addressLine1 = addressLine1; | ||
return this; | ||
} | ||
|
||
public PersonAddress build() { | ||
PersonAddress address = new PersonAddress(); | ||
address.setAddress1(addressLine1); | ||
if (community != null) { | ||
address.setAddress2(community.getName()); | ||
} | ||
address.setRegion(location.getRegion()); | ||
address.setCountyDistrict(location.getCountyDistrict()); | ||
address.setStateProvince(location.getStateProvince()); | ||
address.setNeighborhoodCell(location.getName()); | ||
return address; | ||
} | ||
|
||
} |
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
65 changes: 65 additions & 0 deletions
65
...server-omod/src/test/java/org/motechproject/server/svc/impl/PatientAddressEditorTest.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 @@ | ||
package org.motechproject.server.svc.impl; | ||
|
||
import org.junit.Test; | ||
import org.motechproject.server.model.PatientEditor; | ||
import org.openmrs.Patient; | ||
import org.openmrs.PersonAddress; | ||
|
||
import static org.junit.Assert.assertTrue; | ||
|
||
public class PatientAddressEditorTest { | ||
|
||
@Test | ||
public void shouldAddNewAddressIfNoneExists() { | ||
Patient patient = new Patient(); | ||
PatientEditor editor = new PatientEditor(patient); | ||
PersonAddress address = new PersonAddress(); | ||
address.setAddress1("1st Cross"); | ||
address.setRegion("Upper East"); | ||
address.setCountyDistrict("Kassenna Nankana West"); | ||
address.setStateProvince("Navio"); | ||
address.setNeighborhoodCell("Navio CHPS"); | ||
|
||
editor.editAddress(address).done(); | ||
|
||
assertTrue(patient.getAddresses().size() == 1); | ||
for (PersonAddress personAddress : patient.getAddresses()) { | ||
assertTrue(personAddress.equalsContent(address)); | ||
} | ||
} | ||
|
||
@Test | ||
public void shouldVoidExistingAddressAndAddNewOne() { | ||
Patient patient = new Patient(); | ||
PatientEditor editor = new PatientEditor(patient); | ||
|
||
PersonAddress oldAddress = new PersonAddress(); | ||
oldAddress.setAddress1("1st Cross"); | ||
oldAddress.setRegion("Upper East"); | ||
oldAddress.setCountyDistrict("Kassenna Nankana West"); | ||
oldAddress.setStateProvince("Navio"); | ||
oldAddress.setNeighborhoodCell("Navio CHPS"); | ||
|
||
patient.addAddress(oldAddress); | ||
|
||
PersonAddress newAddress = new PersonAddress(); | ||
newAddress.setAddress1("2nd Cross"); | ||
newAddress.setRegion("Upper East"); | ||
newAddress.setCountyDistrict("Kassenna Nankana West"); | ||
newAddress.setStateProvince("Navio"); | ||
newAddress.setNeighborhoodCell("Navio CHPS"); | ||
|
||
editor.editAddress(newAddress).done(); | ||
|
||
assertTrue(patient.getAddresses().size() == 2); | ||
for (PersonAddress personAddress : patient.getAddresses()) { | ||
if(personAddress.isVoided()){ | ||
assertTrue(personAddress.equalsContent(oldAddress)); | ||
}else{ | ||
assertTrue(personAddress.equalsContent(newAddress)); | ||
} | ||
} | ||
} | ||
|
||
|
||
} |
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