Skip to content

Commit e4ba269

Browse files
authored
Refactored ID mapping to use databricks jdbc template instead (#1571) (#1576)
* Refactored ID mapping to use databricks jdbc template instead (#1571) Signed-off-by: Angelica Ochoa <15623749+ao508@users.noreply.github.com> * Remove references to user 'laptop' (#1577) Signed-off-by: Angelica Ochoa <15623749+ao508@users.noreply.github.com> * Updated databricks view name (#1578) Signed-off-by: Angelica Ochoa <15623749+ao508@users.noreply.github.com> * Renamed mat views (#1579) Signed-off-by: Angelica Ochoa <15623749+ao508@users.noreply.github.com> --------- Signed-off-by: Angelica Ochoa <15623749+ao508@users.noreply.github.com>
1 parent 9181d86 commit e4ba269

30 files changed

+407
-382
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ All properties are required with the exception of some NATS connection-specific
1818
### Locally
1919

2020
**Requirements:**
21-
- maven 3.6.1
22-
- java 8
21+
- maven 3.8.8
22+
- java 21
2323

2424
Add `application.properties` to the local application resources: `src/main/resources`
2525

@@ -32,7 +32,7 @@ mvn clean install
3232
Run with
3333

3434
```
35-
java -jar server/target/smile_server.jar
35+
java --add-opens=java.base/java.nio=org.apache.arrow.memory.core,ALL-UNNAMED -jar server/target/smile_server.jar
3636
```
3737

3838
### With Docker
@@ -57,14 +57,14 @@ If the Docker image is built with the properties baked in then simply run with:
5757

5858
```
5959
docker run --name smile-server <repo>/<tag>:<version> \
60-
-jar /smile-server/smile_server.jar
60+
--add-opens=java.base/java.nio=org.apache.arrow.memory.core,ALL-UNNAMED -jar /smile-server/smile_server.jar
6161
```
6262

6363
Otherwise use a bind mount to make the local files available to the Docker image and add `--spring.config.location` to the java arg
6464

6565
```
6666
docker run --mount type=bind,source=<local path to properties files>,target=/smile-server/src/main/resources \
6767
--name smile-server <repo>/<tag>:<version> \
68-
-jar /smile-server/smile_server.jar \
68+
--add-opens=java.base/java.nio=org.apache.arrow.memory.core,ALL-UNNAMED -jar /smile-server/smile_server.jar \
6969
--spring.config.location=/cmo-metadb/src/main/resources/application.properties
7070
```

model/src/main/java/org/mskcc/smile/model/internal/CrdbMappingModel.java

Lines changed: 0 additions & 70 deletions
This file was deleted.
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package org.mskcc.smile.model.internal;
2+
3+
/**
4+
*
5+
* @author ochoaa
6+
*/
7+
public class PatientIdTriplet {
8+
private String mrn;
9+
private String cmoPatientId;
10+
private String dmpPatientId;
11+
12+
public PatientIdTriplet() {}
13+
14+
/**
15+
* PatientIdTriplet constructor.
16+
* @param mrn
17+
* @param cmoPatientId
18+
* @param dmpPatientId
19+
*/
20+
public PatientIdTriplet(String mrn, String cmoPatientId, String dmpPatientId) {
21+
this.mrn = mrn;
22+
this.cmoPatientId = cmoPatientId;
23+
this.dmpPatientId = dmpPatientId;
24+
}
25+
26+
/**
27+
* @return the mrn
28+
*/
29+
public String getMrn() {
30+
return mrn;
31+
}
32+
33+
/**
34+
* @param mrn the mrn to set
35+
*/
36+
public void setMrn(String mrn) {
37+
this.mrn = mrn;
38+
}
39+
40+
/**
41+
* @return the cmoPatientId
42+
*/
43+
public String getCmoPatientId() {
44+
return cmoPatientId;
45+
}
46+
47+
/**
48+
* @param cmoPatientId the cmoPatientId to set
49+
*/
50+
public void setCmoPatientId(String cmoPatientId) {
51+
this.cmoPatientId = cmoPatientId;
52+
}
53+
54+
/**
55+
* @return the dmpPatientId
56+
*/
57+
public String getDmpPatientId() {
58+
return dmpPatientId;
59+
}
60+
61+
/**
62+
* @param dmpPatientId the dmpPatientId to set
63+
*/
64+
public void setDmpPatientId(String dmpPatientId) {
65+
this.dmpPatientId = dmpPatientId;
66+
}
67+
68+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package org.mskcc.smile.model.internal;
2+
3+
import java.sql.ResultSet;
4+
import java.sql.SQLException;
5+
import org.springframework.jdbc.core.RowMapper;
6+
7+
/**
8+
*
9+
* @author ochoaa
10+
*/
11+
public class PatientIdTripletMapper implements RowMapper<PatientIdTriplet> {
12+
13+
@Override
14+
public PatientIdTriplet mapRow(ResultSet rs, int rowNum) throws SQLException {
15+
PatientIdTriplet patient = new PatientIdTriplet();
16+
patient.setMrn(rs.getString("MRN"));
17+
patient.setCmoPatientId(rs.getString("CMO_PATIENT_ID"));
18+
patient.setDmpPatientId(rs.getString("DMP_PATIENT_ID"));
19+
return patient;
20+
}
21+
22+
}

persistence/pom.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
<artifactId>model</artifactId>
1717
<version>${project.version}</version>
1818
</dependency>
19-
<!-- oracle jdbc driver -->
19+
<!-- https://mvnrepository.com/artifact/com.databricks/databricks-jdbc -->
2020
<dependency>
21-
<groupId>com.oracle.database.jdbc</groupId>
22-
<artifactId>ojdbc8</artifactId>
23-
<version>21.1.0.0</version>
21+
<groupId>com.databricks</groupId>
22+
<artifactId>databricks-jdbc</artifactId>
23+
<version>2.7.3</version>
2424
</dependency>
2525
</dependencies>
2626
</project>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package org.mskcc.smile.persistence.jdbc;
2+
3+
import com.databricks.client.jdbc.Driver;
4+
import org.springframework.beans.factory.annotation.Value;
5+
import org.springframework.context.annotation.Bean;
6+
import org.springframework.context.annotation.Configuration;
7+
import org.springframework.jdbc.core.JdbcTemplate;
8+
import org.springframework.jdbc.datasource.SimpleDriverDataSource;
9+
10+
/**
11+
*
12+
* @author ochoaa
13+
*/
14+
@Configuration
15+
public class DatabricksJdbcConfig {
16+
@Value("${databricks.url}")
17+
private String databricksUrl;
18+
19+
/**
20+
* Returns the databricks JdbcTemplate.
21+
* @return JdbcTemplate
22+
*/
23+
@Bean
24+
public JdbcTemplate databricksJdbcTemplate() {
25+
SimpleDriverDataSource dataSource = new SimpleDriverDataSource();
26+
dataSource.setDriver(new Driver());
27+
dataSource.setUrl(databricksUrl);
28+
return new JdbcTemplate(dataSource);
29+
}
30+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package org.mskcc.smile.persistence.jdbc;
2+
3+
import java.sql.PreparedStatement;
4+
import java.sql.SQLException;
5+
import java.util.List;
6+
import org.mskcc.smile.model.internal.PatientIdTriplet;
7+
import org.mskcc.smile.model.internal.PatientIdTripletMapper;
8+
import org.springframework.beans.factory.annotation.Autowired;
9+
import org.springframework.jdbc.core.JdbcTemplate;
10+
import org.springframework.jdbc.core.PreparedStatementSetter;
11+
import org.springframework.stereotype.Repository;
12+
13+
/**
14+
*
15+
* @author ochoaa
16+
*/
17+
@Repository
18+
public class DatabricksRepository {
19+
@Autowired
20+
private JdbcTemplate jdbcTemplate;
21+
22+
/**
23+
* Returns an instance of PatientIdTriplet given an input.
24+
* @param inputId
25+
* @return PatientIdTriplet
26+
*/
27+
public PatientIdTriplet findPatientIdTripletByInputId(String inputId) {
28+
String sqlQuery = "SELECT MRN, CMO_PATIENT_ID, DMP_PATIENT_ID "
29+
+ "FROM cdsi_eng_phi.id_mapping.mrn_cmo_dmp_patient_fullouter "
30+
+ "WHERE ? IN (MRN, CMO_PATIENT_ID, DMP_PATIENT_ID)";
31+
32+
List<PatientIdTriplet> patientIds = jdbcTemplate.query(
33+
sqlQuery,
34+
new PreparedStatementSetter() {
35+
@Override
36+
public void setValues(PreparedStatement ps) throws SQLException {
37+
ps.setString(1, inputId);
38+
}
39+
},
40+
new PatientIdTripletMapper()
41+
);
42+
return patientIds.isEmpty() ? null : patientIds.get(0);
43+
}
44+
45+
}

persistence/src/main/java/org/mskcc/smile/persistence/jpa/CrdbRepository.java

Lines changed: 0 additions & 19 deletions
This file was deleted.

server/src/main/java/org/mskcc/smile/SmileConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
/**
1010
*
11-
* @author laptop
11+
* @author ochoaa
1212
*/
1313
@Configuration
1414
@EnableNeo4jRepositories(basePackages = "org.mskcc.smile.persistence.neo4j")

service/src/main/java/org/mskcc/smile/service/CrdbMappingService.java

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)