Commit efe06cff authored by Youn Cadoret's avatar Youn Cadoret
Browse files

[PATREG-129] implement model + TU

parent f3ee781c
Pipeline #159443 failed
......@@ -3,12 +3,18 @@ package net.ihe.gazelle.app.patientregistryapi.application;
import net.ihe.gazelle.app.patientregistryapi.business.PatientAliases;
import net.ihe.gazelle.lib.searchmodelapi.business.exception.SearchException;
import java.util.List;
/**
* Patient Cross Reference Search Service API
*/
public interface PatientCrossReferenceSearch {
List<PatientAliases> search(String key) throws SearchException;
/**
* retrieve the patient alias corresponding to the requested
*
* @param key the search key
* @return the list of patient aliases matching
* @throws SearchException if an error happens during the search processing.
*/
PatientAliases search(String key) throws SearchException;
}
package net.ihe.gazelle.app.patientregistryapi.business;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
......@@ -19,9 +20,10 @@ public class PatientAliases {
/**
* Constructor for the class
* @param uuid
* @param lastModifier
* @param lastModifierDateTime
*
* @param uuid the identifier of the patient aliases
* @param lastModifier the name of the last modifier
* @param lastModifierDateTime the date time of the last update
*/
public PatientAliases(String uuid, String lastModifier, Date lastModifierDateTime) {
this.uuid = uuid;
......@@ -29,51 +31,78 @@ public class PatientAliases {
this.lastModifierDateTime = lastModifierDateTime;
}
/**
* get uuid gazelle patientAliases
*
* @return string uuid
*/
public String getUuid() {
return uuid;
}
/**
* set patientAliases gazelle identifier
*
* @param uuid the value to set to the uuid property
*/
public void setUuid(String uuid) {
this.uuid = uuid;
}
/**
* get the last modifier of the PatientAliases
*
* @return the name as String
*/
public String getLastModifier() {
return lastModifier;
}
/**
* set the last modifier of the PatientAliases
*
* @param lastModifier the name of the last modifier
*/
public void setLastModifier(String lastModifier) {
this.lastModifier = lastModifier;
}
/**
* get the Date Time of the last modifier
*
* @return the date time of the last modifier
*/
public Date getLastModifierDateTime() {
return lastModifierDateTime;
}
public void setLastModifierDateTime(Date lastModifierDateTime) {
this.lastModifierDateTime = lastModifierDateTime;
/**
* set the Date Time of the last modifier
*
*/
public void setLastModifierDateTime() {
this.lastModifierDateTime = new Timestamp(new Date().getTime());
}
/**
* get the list of the patients
*
* @return the list of the patients
*/
public List<Patient> getMembers() {
return members;
}
/**
* add a patient to a members
*
* @param member the patient to add
*/
public void addMember(Patient member) {
setLastModifierDateTime();
this.members.add(member);
}
/**
* add a patient to a members
*
......@@ -81,16 +110,17 @@ public class PatientAliases {
* @param index the index to insert the patient
*/
public void addMember(Patient member, int index) {
setLastModifierDateTime();
this.members.add(index, member);
}
/**
* remove a member to a list of members
*
* @param member the patient to remove
*/
public void removeMember(Patient member) {
setLastModifierDateTime();
this.members.remove(member);
}
......
package net.ihe.gazelle.app.patientregistryapi.business;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import static org.junit.jupiter.api.Assertions.*;
......@@ -29,7 +26,7 @@ class PatientAliasesTest {
*/
@Test
public void patientAliasesCompleteConstructorTest() {
String uuid = "uuid";
String uuid = "3b19b902-cfe8-11ea-87d0-0242ac130003";
Date lastModifierDateTime = new Date();
String lastModifier = "toto";
......@@ -58,14 +55,14 @@ class PatientAliasesTest {
* test members list remove member
*/
@Test
public void removeNameToIndexTest() {
public void removeMemberToIndexTest() {
PatientAliases patientAliases = new PatientAliases();
for(int i=0; i<5; i++) {
for (int i = 0; i < 5; i++) {
patientAliases.addMember(new Patient());
}
int index = 3;
Patient patientToAddAndRemove = new Patient();
patientToAddAndRemove.setUuid("uuid");
patientToAddAndRemove.setUuid("75a59e02-cdb2-11ea-87d0-0242ac130003");
patientAliases.addMember(patientToAddAndRemove, index);
patientAliases.removeMember(patientToAddAndRemove);
......@@ -88,16 +85,16 @@ class PatientAliasesTest {
* test member list add patient to index
*/
@Test
public void addMembersToIndexTest() {
public void addMemberToIndexTest() {
PatientAliases patientAliases = new PatientAliases();
for(int i=0; i<5; i++) {
for (int i = 0; i < 5; i++) {
patientAliases.addMember(new Patient());
}
int index = 3;
Patient patient = new Patient();
patientAliases.addMember(patient, index);
assertEquals(patient,patientAliases.getMembers().get(index));
assertEquals(patient, patientAliases.getMembers().get(index));
}
/**
......@@ -106,14 +103,14 @@ class PatientAliasesTest {
@Test
public void removePatientToIndexTest() {
PatientAliases patientAliases = new PatientAliases();
for(int i=0; i<5; i++) {
for (int i = 0; i < 5; i++) {
patientAliases.addMember(new Patient());
}
int index = 3;
Patient patientUUIDToAddAndRemove = new Patient();
patientUUIDToAddAndRemove.setUuid("75a59e02-cdb2-11ea-87d0-0242ac130003");
patientUUIDToAddAndRemove.setUuid("44380a84-cfe8-11ea-87d0-0242ac130003");
patientAliases.addMember(patientUUIDToAddAndRemove,index);
patientAliases.addMember(patientUUIDToAddAndRemove, index);
patientAliases.removeMember(patientUUIDToAddAndRemove);
assertFalse(patientAliases.getMembers().contains(patientUUIDToAddAndRemove));
......@@ -121,48 +118,63 @@ class PatientAliasesTest {
/**
* Test patientAliases on member and Null
* Test check date time last modifier
*/
@Test
public void equals_patientAliases_null(){
public void checkPatientAliasesDateTime() {
PatientAliases patientAliases = new PatientAliases();
assertFalse(patientAliases.equals(null),"PatientAliases shall not be equal to null!");
}
Patient patient = new Patient();
patientAliases.addMember(patient);
String date1 = patientAliases.getLastModifierDateTime().toString();
patientAliases.addMember(patient);
String lastDateTime1 = patientAliases.getLastModifierDateTime().toString();
assertFalse(lastDateTime1.contains(date1));
}
/**
* Test check last modifier
*/
@Test
public void checkPatientAliasesLastModifier() {
PatientAliases patientAliases = new PatientAliases();
Patient patient = new Patient();
patient.setUuid("4e7fc004-cfe8-11ea-87d0-0242ac130003");
patientAliases.addMember(patient);
patientAliases.setLastModifier("toto");
assertTrue(patientAliases.getLastModifier().contains("toto"));
}
/**
* Test equals on same patientAliases
* Test patientAliases on member and Null
*/
@Test
public void equals_patientAliases_same(){
public void equals_patientAliases_null() {
PatientAliases patientAliases = new PatientAliases();
assertTrue(patientAliases.equals(patientAliases),"Patientes shall be equal!");
assertFalse(patientAliases.equals(null), "PatientAliases shall not be equal to null!");
}
/**
* Test equals on Patient and another class
* Test equals on same patientAliases
*/
@Test
public void equals_patientAliases_other_class(){
public void equals_patientAliases_same() {
PatientAliases patientAliases = new PatientAliases();
assertFalse(patientAliases.equals("Malade"),"Patient shall not be equal to string !");
assertTrue(patientAliases.equals(patientAliases), "PatientAliases shall be equal!");
}
/**
* Test equals on patientAliases uuid equals
* Test equals on Patient and another class
*/
@Test
public void equals_patientAliases_uuid_true(){
String uuid= "uuid1";
public void equals_patientAliases_other_class() {
PatientAliases patientAliases = new PatientAliases();
patientAliases.setUuid(uuid);
PatientAliases patientAliases1 = new PatientAliases();
patientAliases1.setUuid(uuid);
assertTrue(patientAliases1.equals(patientAliases1),"Patient shall be equal !");
assertFalse(patientAliases.equals("TEST"), "PatientAliases shall not be equal to string !");
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment