mirror of
https://github.com/pcvolkmer/mv64e-onkostar-data.git
synced 2025-07-03 19:12:55 +00:00
refactor: common implementation for all data catalogues
This commit is contained in:
@ -0,0 +1,46 @@
|
|||||||
|
package dev.pcvolkmer.onco.datamapper.datacatalogues;
|
||||||
|
|
||||||
|
import dev.pcvolkmer.onco.datamapper.exceptions.DataAccessException;
|
||||||
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
|
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Common implementations for all data catalogues
|
||||||
|
*
|
||||||
|
* @author Paul-Christian Volkmer
|
||||||
|
* @since 0.1
|
||||||
|
*/
|
||||||
|
public abstract class AbstractDataCatalogue implements DataCatalogue {
|
||||||
|
|
||||||
|
protected final JdbcTemplate jdbcTemplate;
|
||||||
|
|
||||||
|
protected AbstractDataCatalogue(JdbcTemplate jdbcTemplate) {
|
||||||
|
this.jdbcTemplate = jdbcTemplate;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract String getTableName();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get procedure result set by procedure id
|
||||||
|
*
|
||||||
|
* @param id The procedure id
|
||||||
|
* @return The procedure id
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public ResultSet getById(int id) {
|
||||||
|
var result = this.jdbcTemplate.query(
|
||||||
|
String.format("SELECT * FROM %s JOIN prozedur ON (prozedur.id = dk_dnpm_kpa.id) WHERE id = ?", getTableName()),
|
||||||
|
(resultSet, i) -> resultSet,
|
||||||
|
id);
|
||||||
|
|
||||||
|
if (result.isEmpty()) {
|
||||||
|
throw new DataAccessException("No record found for id: " + id);
|
||||||
|
} else if (result.size() > 1) {
|
||||||
|
throw new DataAccessException("Multiple records found for id: " + id);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result.get(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
package dev.pcvolkmer.onco.datamapper.datacatalogues;
|
||||||
|
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Common interface for all data catalogues
|
||||||
|
*
|
||||||
|
* @author Paul-Christian Volkmer
|
||||||
|
* @since 0.1
|
||||||
|
*/
|
||||||
|
public interface DataCatalogue {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a result set by database id
|
||||||
|
* @param id The database id (primary key)
|
||||||
|
* @return The result set
|
||||||
|
*/
|
||||||
|
ResultSet getById(int id);
|
||||||
|
|
||||||
|
}
|
@ -3,48 +3,30 @@ package dev.pcvolkmer.onco.datamapper.datacatalogues;
|
|||||||
import dev.pcvolkmer.onco.datamapper.exceptions.DataAccessException;
|
import dev.pcvolkmer.onco.datamapper.exceptions.DataAccessException;
|
||||||
import org.springframework.jdbc.core.JdbcTemplate;
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load raw result sets from database table 'dk_dnpm_kpa'
|
* Load raw result sets from database table 'dk_dnpm_kpa'
|
||||||
*
|
*
|
||||||
* @author Paul-Christian Volkmer
|
* @author Paul-Christian Volkmer
|
||||||
* @since 0.1
|
* @since 0.1
|
||||||
*/
|
*/
|
||||||
public class KpaCatalogue {
|
public class KpaCatalogue extends AbstractDataCatalogue {
|
||||||
|
|
||||||
private final JdbcTemplate jdbcTemplate;
|
|
||||||
|
|
||||||
private KpaCatalogue(JdbcTemplate jdbcTemplate) {
|
private KpaCatalogue(JdbcTemplate jdbcTemplate) {
|
||||||
this.jdbcTemplate = jdbcTemplate;
|
super(jdbcTemplate);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getTableName() {
|
||||||
|
return "dk_dnpm_kpa";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static KpaCatalogue create(JdbcTemplate jdbcTemplate) {
|
public static KpaCatalogue create(JdbcTemplate jdbcTemplate) {
|
||||||
return new KpaCatalogue(jdbcTemplate);
|
return new KpaCatalogue(jdbcTemplate);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get procedure result set by procedure id
|
|
||||||
* @param id The procedure id
|
|
||||||
* @return The procedure id
|
|
||||||
*/
|
|
||||||
public ResultSet getById(int id) {
|
|
||||||
var result = this.jdbcTemplate.query(
|
|
||||||
"SELECT * FROM dk_dnpm_kpa JOIN prozedur ON (prozedur.id = dk_dnpm_kpa.id) WHERE id = ?",
|
|
||||||
(resultSet, i) -> resultSet,
|
|
||||||
id);
|
|
||||||
|
|
||||||
if (result.isEmpty()) {
|
|
||||||
throw new DataAccessException("No record found for id: " + id);
|
|
||||||
} else if (result.size() > 1) {
|
|
||||||
throw new DataAccessException("Multiple records found for id: " + id);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result.get(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get procedure database id by case id
|
* Get procedure database id by case id
|
||||||
|
*
|
||||||
* @param caseId The case id
|
* @param caseId The case id
|
||||||
* @return The procedure id
|
* @return The procedure id
|
||||||
*/
|
*/
|
||||||
@ -65,6 +47,7 @@ public class KpaCatalogue {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get patient database id by case id
|
* Get patient database id by case id
|
||||||
|
*
|
||||||
* @param caseId The case id
|
* @param caseId The case id
|
||||||
* @return The patients database id
|
* @return The patients database id
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user