Commit a6f68e11 authored by Franck Desaize's avatar Franck Desaize
Browse files

Merge branch 'PATREG-124' into 'develop'

Patreg 124

See merge request !8
parents bb4a3b61 9724dd57
Pipeline #258058 failed with stages
in 52 seconds
......@@ -32,7 +32,7 @@ services:
code:
stage: build
extends:
- .codeForJavaWithWildflyAndPostgresql
- .buildCodeForJavaWithWildflyAndPostgresql
services:
- postgres:9.6.17-alpine
variables:
......@@ -41,7 +41,7 @@ code:
quality:
stage: tests
extends:
- .qualityForJavaWithSonarqubeAndPostgresql
- .testQualityForJavaWithSonarqubeAndPostgresql
variables:
P_MAVEN_IMAGE_TAG: "wildfly-3.6.3-18.0.1.Final"
P_CODE_BINARIES: "target/classes/"
......
package net.ihe.gazelle.app.patientregistryapi.application;
import net.ihe.gazelle.app.patientregistryapi.business.PatientAliases;
import net.ihe.gazelle.lib.searchmodelapi.business.exception.SearchException;
/**
* Patient Cross Reference Search Service API
*/
public interface PatientCrossReferenceSearch {
/**
* 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;
public class PatientAliases {
private String uuid;
private String lastModifier;
private Date lastModifierDateTime;
private List<Patient> members = new ArrayList<>();
/**
* default constructor
*/
public PatientAliases() {
}
/**
* Constructor for the class
*
* @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;
this.lastModifier = lastModifier;
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;
}
/**
* 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
*
* @param member the patient to add
* @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);
}
/**
* {@inheritDoc}
*/
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
if (!super.equals(o)) {
return false;
}
PatientAliases patientAliases = (PatientAliases) o;
if (uuid != null ? !uuid.equals(patientAliases.uuid) : patientAliases.uuid != null) {
return false;
}
if (lastModifier != null ? !lastModifier.equals(patientAliases.lastModifier) : patientAliases.lastModifier != null) {
return false;
}
if (lastModifierDateTime != null ? !lastModifierDateTime.equals(patientAliases.lastModifierDateTime) : patientAliases.lastModifierDateTime != null) {
return false;
}
return members.equals(patientAliases.members);
}
/**
* {@inheritDoc}
*/
@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + (uuid != null ? uuid.hashCode() : 0);
result = 31 * result + (lastModifier != null ? lastModifier.hashCode() : 0);
result = 31 * result + (lastModifierDateTime != null ? lastModifierDateTime.hashCode() : 0);
result = 31 * result + members.hashCode();
return result;
}
}
package net.ihe.gazelle.app.patientregistryapi.business;
import org.junit.jupiter.api.Test;
import java.util.Date;
import static org.junit.jupiter.api.Assertions.*;
/**
* tests for Patient class
*/
class PatientAliasesTest {
/**
* test default constructor
*/
@Test
public void patientAliasesDefaultConstructorTest() {
PatientAliases patientAliases = new PatientAliases();
assertTrue(patientAliases.getMembers().isEmpty());
}
/**
* test complete constructor
*/
@Test
public void patientAliasesCompleteConstructorTest() {
String uuid = "3b19b902-cfe8-11ea-87d0-0242ac130003";
Date lastModifierDateTime = new Date();
String lastModifier = "toto";
PatientAliases patientAliases = new PatientAliases(uuid, lastModifier, lastModifierDateTime);
assertTrue(patientAliases.getMembers().isEmpty());
assertEquals(uuid, patientAliases.getUuid());
assertEquals(lastModifier, patientAliases.getLastModifier());
assertEquals(lastModifierDateTime, patientAliases.getLastModifierDateTime());
}
/**
* test member list add patient
*/
@Test
public void addMembersTest() {
PatientAliases patientAliases = new PatientAliases();
patientAliases.addMember(new Patient());
assertFalse(patientAliases.getMembers().isEmpty());
}
/**
* test members list remove member
*/
@Test
public void removeMemberToIndexTest() {
PatientAliases patientAliases = new PatientAliases();
for (int i = 0; i < 5; i++) {
patientAliases.addMember(new Patient());
}
int index = 3;
Patient patientToAddAndRemove = new Patient();
patientToAddAndRemove.setUuid("75a59e02-cdb2-11ea-87d0-0242ac130003");
patientAliases.addMember(patientToAddAndRemove, index);
patientAliases.removeMember(patientToAddAndRemove);
assertFalse(patientAliases.getMembers().contains(patientToAddAndRemove));
}
/**
* test Members list add member
*/
@Test
public void addMemberTest() {
PatientAliases patientAliases = new PatientAliases();
patientAliases.addMember(new Patient());
assertFalse(patientAliases.getMembers().isEmpty());
}
/**
* test member list add patient to index
*/
@Test
public void addMemberToIndexTest() {
PatientAliases patientAliases = new PatientAliases();
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));
}
/**
* test member list remove patient
*/
@Test
public void removePatientToIndexTest() {
PatientAliases patientAliases = new PatientAliases();
for (int i = 0; i < 5; i++) {
patientAliases.addMember(new Patient());
}
int index = 3;
Patient patientUUIDToAddAndRemove = new Patient();
patientUUIDToAddAndRemove.setUuid("44380a84-cfe8-11ea-87d0-0242ac130003");
patientAliases.addMember(patientUUIDToAddAndRemove, index);
patientAliases.removeMember(patientUUIDToAddAndRemove);
assertFalse(patientAliases.getMembers().contains(patientUUIDToAddAndRemove));
}
/**
* Test check date time last modifier
*/
@Test
public void checkPatientAliasesDateTime() {
PatientAliases patientAliases = new PatientAliases();
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 patientAliases on member and Null
*/
@Test
public void equals_patientAliases_null() {
PatientAliases patientAliases = new PatientAliases();
assertFalse(patientAliases.equals(null), "PatientAliases shall not be equal to null!");
}
/**
* Test equals on same patientAliases
*/
@Test
public void equals_patientAliases_same() {
PatientAliases patientAliases = new PatientAliases();
assertTrue(patientAliases.equals(patientAliases), "PatientAliases shall be equal!");
}
/**
* Test equals on Patient and another class
*/
@Test
public void equals_patientAliases_other_class() {
PatientAliases patientAliases = new PatientAliases();
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