mirror of
https://github.com/pcvolkmer/mv64e-onkostar-data.git
synced 2025-07-02 02:22:54 +00:00
refactor: create mapper with catalogue
This commit is contained in:
@ -3,7 +3,6 @@ package dev.pcvolkmer.onco.datamapper;
|
||||
import dev.pcvolkmer.mv64e.mtb.Coding;
|
||||
import dev.pcvolkmer.mv64e.mtb.MtbDiagnosis;
|
||||
import dev.pcvolkmer.onco.datamapper.datacatalogues.KpaCatalogue;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
|
||||
import static dev.pcvolkmer.onco.datamapper.TypeMapper.asString;
|
||||
|
||||
@ -15,20 +14,10 @@ import static dev.pcvolkmer.onco.datamapper.TypeMapper.asString;
|
||||
*/
|
||||
public class KpaDiagnosisDataMapper implements DataMapper<MtbDiagnosis> {
|
||||
|
||||
private final JdbcTemplate jdbcTemplate;
|
||||
private final KpaCatalogue kpaCatalogue;
|
||||
|
||||
private KpaDiagnosisDataMapper(final JdbcTemplate jdbcTemplate) {
|
||||
this.jdbcTemplate = jdbcTemplate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create instance of the mapper class
|
||||
*
|
||||
* @param jdbcTemplate The Spring JdbcTemplate to be used
|
||||
* @return The initialized mapper
|
||||
*/
|
||||
public static KpaDiagnosisDataMapper create(final JdbcTemplate jdbcTemplate) {
|
||||
return new KpaDiagnosisDataMapper(jdbcTemplate);
|
||||
public KpaDiagnosisDataMapper(final KpaCatalogue kpaCatalogue) {
|
||||
this.kpaCatalogue = kpaCatalogue;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -39,8 +28,7 @@ public class KpaDiagnosisDataMapper implements DataMapper<MtbDiagnosis> {
|
||||
*/
|
||||
@Override
|
||||
public MtbDiagnosis getById(int id) {
|
||||
var kpa = KpaCatalogue.create(this.jdbcTemplate);
|
||||
var data = kpa.getById(id);
|
||||
var data = kpaCatalogue.getById(id);
|
||||
|
||||
var builder = MtbDiagnosis.builder();
|
||||
builder
|
||||
|
@ -2,7 +2,6 @@ package dev.pcvolkmer.onco.datamapper;
|
||||
|
||||
import dev.pcvolkmer.mv64e.mtb.*;
|
||||
import dev.pcvolkmer.onco.datamapper.datacatalogues.KpaCatalogue;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@ -17,20 +16,10 @@ import static dev.pcvolkmer.onco.datamapper.TypeMapper.asString;
|
||||
*/
|
||||
public class KpaPatientDataMapper implements DataMapper<Patient> {
|
||||
|
||||
private final JdbcTemplate jdbcTemplate;
|
||||
private final KpaCatalogue kpaCatalogue;
|
||||
|
||||
private KpaPatientDataMapper(final JdbcTemplate jdbcTemplate) {
|
||||
this.jdbcTemplate = jdbcTemplate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create instance of the mapper class
|
||||
*
|
||||
* @param jdbcTemplate The Spring JdbcTemplate to be used
|
||||
* @return The initialized mapper
|
||||
*/
|
||||
public static KpaPatientDataMapper create(final JdbcTemplate jdbcTemplate) {
|
||||
return new KpaPatientDataMapper(jdbcTemplate);
|
||||
public KpaPatientDataMapper(final KpaCatalogue kpaCatalogue) {
|
||||
this.kpaCatalogue = kpaCatalogue;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -41,7 +30,6 @@ public class KpaPatientDataMapper implements DataMapper<Patient> {
|
||||
*/
|
||||
@Override
|
||||
public Patient getById(int id) {
|
||||
var kpaCatalogue = KpaCatalogue.create(this.jdbcTemplate);
|
||||
var kpaData = kpaCatalogue.getById(id);
|
||||
|
||||
var builder = Patient.builder();
|
||||
|
@ -2,6 +2,7 @@ package dev.pcvolkmer.onco.datamapper;
|
||||
|
||||
import dev.pcvolkmer.mv64e.mtb.Mtb;
|
||||
import dev.pcvolkmer.onco.datamapper.datacatalogues.KpaCatalogue;
|
||||
import dev.pcvolkmer.onco.datamapper.datacatalogues.PatientCatalogue;
|
||||
import dev.pcvolkmer.onco.datamapper.exceptions.DataAccessException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@ -54,9 +55,10 @@ public class MtbDataMapper implements DataMapper<Mtb> {
|
||||
*/
|
||||
@Override
|
||||
public Mtb getById(int kpaId) {
|
||||
var patientDataMapper = PatientDataMapper.create(jdbcTemplate);
|
||||
var kpaPatientDataMapper = KpaPatientDataMapper.create(jdbcTemplate);
|
||||
var diagnosisDataMapper = KpaDiagnosisDataMapper.create(jdbcTemplate);
|
||||
var kpaCatalogue = KpaCatalogue.create(jdbcTemplate);
|
||||
var patientDataMapper = new PatientDataMapper(new PatientCatalogue(jdbcTemplate));
|
||||
var kpaPatientDataMapper = new KpaPatientDataMapper(kpaCatalogue);
|
||||
var diagnosisDataMapper = new KpaDiagnosisDataMapper(kpaCatalogue);
|
||||
|
||||
var resultBuilder = Mtb.builder();
|
||||
|
||||
|
@ -6,7 +6,6 @@ import dev.pcvolkmer.mv64e.mtb.GenderCodingCode;
|
||||
import dev.pcvolkmer.mv64e.mtb.Patient;
|
||||
import dev.pcvolkmer.onco.datamapper.datacatalogues.PatientCatalogue;
|
||||
import dev.pcvolkmer.onco.datamapper.exceptions.DataAccessException;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@ -21,20 +20,10 @@ import static dev.pcvolkmer.onco.datamapper.TypeMapper.asString;
|
||||
*/
|
||||
public class PatientDataMapper implements DataMapper<Patient> {
|
||||
|
||||
private final JdbcTemplate jdbcTemplate;
|
||||
private final PatientCatalogue patientCatalogue;
|
||||
|
||||
private PatientDataMapper(final JdbcTemplate jdbcTemplate) {
|
||||
this.jdbcTemplate = jdbcTemplate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create instance of the mapper class
|
||||
*
|
||||
* @param jdbcTemplate The Spring JdbcTemplate to be used
|
||||
* @return The initialized mapper
|
||||
*/
|
||||
public static PatientDataMapper create(final JdbcTemplate jdbcTemplate) {
|
||||
return new PatientDataMapper(jdbcTemplate);
|
||||
public PatientDataMapper(final PatientCatalogue patientCatalogue) {
|
||||
this.patientCatalogue = patientCatalogue;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -45,7 +34,6 @@ public class PatientDataMapper implements DataMapper<Patient> {
|
||||
*/
|
||||
@Override
|
||||
public Patient getById(int id) {
|
||||
var patientCatalogue = PatientCatalogue.create(this.jdbcTemplate);
|
||||
var patientData = patientCatalogue.getById(id);
|
||||
|
||||
var builder = Patient.builder();
|
||||
|
@ -15,7 +15,7 @@ public class PatientCatalogue implements DataCatalogue {
|
||||
|
||||
private final JdbcTemplate jdbcTemplate;
|
||||
|
||||
private PatientCatalogue(JdbcTemplate jdbcTemplate) {
|
||||
public PatientCatalogue(JdbcTemplate jdbcTemplate) {
|
||||
this.jdbcTemplate = jdbcTemplate;
|
||||
}
|
||||
|
||||
|
@ -1,12 +1,12 @@
|
||||
package dev.pcvolkmer.onco.datamapper;
|
||||
|
||||
import dev.pcvolkmer.mv64e.mtb.MtbDiagnosis;
|
||||
import dev.pcvolkmer.onco.datamapper.datacatalogues.KpaCatalogue;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.util.List;
|
||||
@ -20,14 +20,14 @@ import static org.mockito.Mockito.doAnswer;
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class KpaDiagnosisDataMapperTest {
|
||||
|
||||
JdbcTemplate jdbcTemplate;
|
||||
KpaCatalogue kpaCatalogue;
|
||||
|
||||
KpaDiagnosisDataMapper dataMapper;
|
||||
|
||||
@BeforeEach
|
||||
void setUp(@Mock JdbcTemplate jdbcTemplate) {
|
||||
this.jdbcTemplate = jdbcTemplate;
|
||||
this.dataMapper = KpaDiagnosisDataMapper.create(jdbcTemplate);
|
||||
void setUp(@Mock KpaCatalogue kpaCatalogue) {
|
||||
this.kpaCatalogue = kpaCatalogue;
|
||||
this.dataMapper = new KpaDiagnosisDataMapper(kpaCatalogue);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -42,9 +42,9 @@ class KpaDiagnosisDataMapperTest {
|
||||
return testData().get(columnName);
|
||||
}).when(resultSet).get(anyString());
|
||||
|
||||
doAnswer(invocationOnMock -> List.of(resultSet))
|
||||
.when(jdbcTemplate)
|
||||
.queryForList(anyString(), anyInt());
|
||||
doAnswer(invocationOnMock -> resultSet)
|
||||
.when(kpaCatalogue)
|
||||
.getById(anyInt());
|
||||
|
||||
var actual = this.dataMapper.getById(1);
|
||||
assertThat(actual).isInstanceOf(MtbDiagnosis.class);
|
||||
|
@ -1,17 +1,16 @@
|
||||
package dev.pcvolkmer.onco.datamapper;
|
||||
|
||||
import dev.pcvolkmer.mv64e.mtb.*;
|
||||
import dev.pcvolkmer.onco.datamapper.datacatalogues.KpaCatalogue;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.time.Instant;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@ -22,14 +21,14 @@ import static org.mockito.Mockito.doAnswer;
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class KpaPatientDataMapperTest {
|
||||
|
||||
JdbcTemplate jdbcTemplate;
|
||||
KpaCatalogue kpaCatalogue;
|
||||
|
||||
KpaPatientDataMapper dataMapper;
|
||||
|
||||
@BeforeEach
|
||||
void setUp(@Mock JdbcTemplate jdbcTemplate) {
|
||||
this.jdbcTemplate = jdbcTemplate;
|
||||
this.dataMapper = KpaPatientDataMapper.create(jdbcTemplate);
|
||||
void setUp(@Mock KpaCatalogue kpaCatalogue) {
|
||||
this.kpaCatalogue = kpaCatalogue;
|
||||
this.dataMapper = new KpaPatientDataMapper(kpaCatalogue);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -52,9 +51,9 @@ class KpaPatientDataMapperTest {
|
||||
return testData.get(columnName);
|
||||
}).when(resultSet).get(anyString());
|
||||
|
||||
doAnswer(invocationOnMock -> List.of(resultSet))
|
||||
.when(jdbcTemplate)
|
||||
.queryForList(anyString(), anyInt());
|
||||
doAnswer(invocationOnMock -> resultSet)
|
||||
.when(kpaCatalogue)
|
||||
.getById(anyInt());
|
||||
|
||||
var actual = this.dataMapper.getById(1);
|
||||
assertThat(actual).isInstanceOf(Patient.class);
|
||||
@ -81,9 +80,9 @@ class KpaPatientDataMapperTest {
|
||||
return testData.get(columnName);
|
||||
}).when(resultSet).get(anyString());
|
||||
|
||||
doAnswer(invocationOnMock -> List.of(resultSet))
|
||||
.when(jdbcTemplate)
|
||||
.queryForList(anyString(), anyInt());
|
||||
doAnswer(invocationOnMock -> resultSet)
|
||||
.when(kpaCatalogue)
|
||||
.getById(anyInt());
|
||||
|
||||
var actual = this.dataMapper.getById(1);
|
||||
assertThat(actual).isInstanceOf(Patient.class);
|
||||
|
@ -3,15 +3,14 @@ package dev.pcvolkmer.onco.datamapper;
|
||||
import dev.pcvolkmer.mv64e.mtb.Address;
|
||||
import dev.pcvolkmer.mv64e.mtb.GenderCodingCode;
|
||||
import dev.pcvolkmer.mv64e.mtb.Patient;
|
||||
import dev.pcvolkmer.onco.datamapper.datacatalogues.PatientCatalogue;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.sql.SQLException;
|
||||
import java.time.Instant;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
@ -25,14 +24,14 @@ import static org.mockito.Mockito.doAnswer;
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class PatientDataMapperTest {
|
||||
|
||||
JdbcTemplate jdbcTemplate;
|
||||
PatientCatalogue patientCatalogue;
|
||||
|
||||
PatientDataMapper dataMapper;
|
||||
|
||||
@BeforeEach
|
||||
void setUp(@Mock JdbcTemplate jdbcTemplate) {
|
||||
this.jdbcTemplate = jdbcTemplate;
|
||||
this.dataMapper = PatientDataMapper.create(jdbcTemplate);
|
||||
void setUp(@Mock PatientCatalogue patientCatalogue) {
|
||||
this.patientCatalogue = patientCatalogue;
|
||||
this.dataMapper = new PatientDataMapper(patientCatalogue);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -55,9 +54,9 @@ class PatientDataMapperTest {
|
||||
return testData.get(columnName);
|
||||
}).when(resultSet).get(anyString());
|
||||
|
||||
doAnswer(invocationOnMock -> List.of(resultSet))
|
||||
.when(jdbcTemplate)
|
||||
.queryForList(anyString(), anyInt());
|
||||
doAnswer(invocationOnMock -> resultSet)
|
||||
.when(patientCatalogue)
|
||||
.getById(anyInt());
|
||||
|
||||
var actual = this.dataMapper.getById(1);
|
||||
assertThat(actual).isInstanceOf(Patient.class);
|
||||
@ -82,9 +81,9 @@ class PatientDataMapperTest {
|
||||
return testData.get(columnName);
|
||||
}).when(resultSet).get(anyString());
|
||||
|
||||
doAnswer(invocationOnMock -> List.of(resultSet))
|
||||
.when(jdbcTemplate)
|
||||
.queryForList(anyString(), anyInt());
|
||||
doAnswer(invocationOnMock -> resultSet)
|
||||
.when(patientCatalogue)
|
||||
.getById(anyInt());
|
||||
|
||||
var actual = this.dataMapper.getById(1);
|
||||
assertThat(actual).isInstanceOf(Patient.class);
|
||||
|
Reference in New Issue
Block a user