Commit a8c37fa1 authored by Cossin Sebastien's avatar Cossin Sebastien
Browse files

WIP OMOP loading

parent 3e6832f0
......@@ -41,8 +41,6 @@ public class FrDrugLoader extends PojoLoader<FrDrugPOJO> implements Iterator<Lis
}
}
public static String getSqlQuery(String cip13) {
return("SELECT * FROM v_ansm_marketed_drug_ucd13 where CIP13 = " + cip13);
}
......
package fr.erias.frenchdrugs.entities;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name="omop_cd_hash")
public class OMOP_CD_HASH {
@Id
@Column(name = "cd_id")
private String cd_id;
@Column(name = "hash")
private String hash;
public OMOP_CD_HASH(String cd_id, String hash) {
this.cd_id = cd_id;
this.hash = hash;
}
}
package fr.erias.frenchdrugs.entities;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
@Entity
public class OMOP_CD_POJO {
public static String sqlQuery = "SELECT * FROM V_OMOP_CDC_CD "
+ "ORDER BY cd_id";
@Id
@Column(name = "id")
protected String id;
@Column(name = "substance_id")
protected String substance_id;
@Column(name = "amount")
protected float amount;
@Column(name = "unit_strength_id")
protected String unit_strength_id;
@Column(name = "amount_ref")
protected int amount_ref;
@Column(name = "unit_ref_id")
protected String unit_ref_id;
@Column(name = "cdc_id")
protected String cdc_id;
@Column(name = "cd_name")
protected String cd_name;
@Column(name = "cd_id")
protected String cd_id;
@Column(name = "dosageform_id")
protected String dosageform_id;
@Column(name = "route_id")
protected String route_id;
public String getId() {
return id;
}
public String getSubstanceId() {
return substance_id;
}
public float getAmount() {
return amount;
}
public String getUnit_strength_id() {
return unit_strength_id;
}
public int getAmount_ref() {
return amount_ref;
}
public String getUnit_ref_id() {
return unit_ref_id;
}
public String getCdc_id() {
return cdc_id;
}
public String getCd_name() {
return cd_name;
}
public String getCd_id() {
return cd_id;
}
public String getDosageform_id() {
return dosageform_id;
}
public String getRoute_id() {
return route_id;
}
}
......@@ -5,72 +5,104 @@ import javax.persistence.Entity;
import javax.persistence.Id;
@Entity
public class OMOP_PACK_POJO extends OMOP_CD_POJO {
public static String sqlQuery = "SELECT \n" +
"--ROW_NUMBER() OVER (PARTITION BY true) as id, \n" +
"V_OMOP_CDC_CD.*,\n" +
"omop_pack.*\n" +
"FROM omop_pack\n" +
"inner join V_OMOP_CDC_CD on omop_pack.cd_id = V_OMOP_CDC_CD.cd_id\n" +
"where pack_id is not null\n" +
"order by pack_id;";
public class OMOP_PACK_POJO {
@Id
@Column(name = "id")
private String id;
@Column(name = "cd_id")
private String cd_id;
@Column(name = "substance_id")
private String substance_id;
@Column(name = "quantcd_id")
private String quantcd_id;
@Column(name = "cdc_id")
private String cdc_id;
@Column(name = "amount")
private Double amount;
@Column(name = "quantcd_name")
private String quantcd_name;
@Column(name = "strength_unit_id")
private String strength_unit_id;
@Column(name = "quantcd_amount")
private double quantcd_amount;
@Column(name = "amount_ref")
private Double amount_ref;
@Column(name = "pack_name")
private String pack_name;
@Column(name = "pack_amount")
private int pack_amount;
@Column(name = "ref_unit_id")
private String ref_unit_id;
@Column(name = "pack_id")
private String pack_id;
@Column(name = "amount_pack")
private Integer amount_pack;
@Column(name = "quant_cd_id")
private String quant_cd_id;
@Column(name = "cd_id")
private String cd_id;
@Column(name = "quantity_factor")
private Double quantity_factor;
@Column(name = "df_id")
private String df_id;
@Column(name = "concept_id")
private String concept_id;
public String getConceptId() {
return concept_id;
}
public String getId() {
return id;
}
public String getCd_id() {
public String getCD_id() {
return cd_id;
}
public String getSubstance_id() {
return substance_id;
}
public String getQuantcd_id() {
return quantcd_id;
public String getCdc_id() {
return cdc_id;
}
public String getQuantcd_name() {
return quantcd_name;
public Double getAmount() {
return amount;
}
public double getQuantcd_amount() {
return quantcd_amount;
public String getStrength_unit_id() {
return strength_unit_id;
}
public String getPack_name() {
return pack_name;
public Double getAmount_ref() {
return amount_ref;
}
public int getPack_amount() {
return pack_amount;
public String getRef_unit_id() {
return ref_unit_id;
}
public String getPack_id() {
return pack_id;
}
public Integer getAmount_pack() {
return amount_pack;
}
public String getQuant_cd_id() {
return quant_cd_id;
}
public Double getQuantity_factor() {
return quantity_factor;
}
public String getDf_id() {
return df_id;
}
}
package fr.erias.frenchdrugs.omop;
import fr.erias.frenchdrugs.entities.OMOP_CD_POJO;
import fr.erias.frenchdrugs.entities.PojoLoader;
public class LoadOMOPcd extends PojoLoader<OMOP_CD_POJO> {
public LoadOMOPcd(String sql, Class<OMOP_CD_POJO> resultClass) {
super(sql, resultClass);
}
}
package fr.erias.frenchdrugs.omop;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import fr.erias.frenchdrugs.entities.OMOP_PACK_POJO;
import fr.erias.frenchdrugs.entities.PojoLoader;
public class LoadOMOPpack extends PojoLoader<OMOP_PACK_POJO> {
// TODO : refactor with FrDrug
// these 2 classes need a common interface to implement group_by id (cip13 / concept_id) columns
public class LoadOMOPpack extends PojoLoader<OMOP_PACK_POJO> implements Iterator<List<OMOP_PACK_POJO>> {
protected Iterator<OMOP_PACK_POJO> iterator;
private List<OMOP_PACK_POJO> currentRows = new ArrayList<OMOP_PACK_POJO>();
private List<OMOP_PACK_POJO> nextRows = new ArrayList<OMOP_PACK_POJO>();
public LoadOMOPpack(String sql, Class<OMOP_PACK_POJO> resultClass) {
super(sql, resultClass);
this.iterator = entities.iterator();
setNextRows();
}
public void setNextRows() {
currentRows = new ArrayList<OMOP_PACK_POJO>();
if (!this.iterator.hasNext()) {
return;
}
currentRows.addAll(nextRows);
nextRows = new ArrayList<OMOP_PACK_POJO>();
if (currentRows.size() == 0) {
OMOP_PACK_POJO first = this.iterator.next();
currentRows.add(first);
}
String conceptId = currentRows.get(0).getConceptId();
OMOP_PACK_POJO row = null;
try {
while (this.iterator.hasNext() && (row = iterator.next()).getConceptId().equals(conceptId)) {
currentRows.add(row);
}
nextRows.add(row);
} catch (NullPointerException e) {
System.out.println(e.getMessage());
}
}
@Override
public boolean hasNext() {
return currentRows.size() != 0;
}
@Override
public List<OMOP_PACK_POJO> next() {
List<OMOP_PACK_POJO> toSend = currentRows;
setNextRows();
return toSend;
}
public static String getSqlQuery(String concept_id) {
return("SELECT * FROM V_OMOP_PACK where concept_id = '" + concept_id + "'");
}
public static void main(String[] args) {
String sqlQuery = LoadOMOPpack.getSqlQuery(OMOP_TEST.pack_doliprane_8_cp);
LoadOMOPpack loader = new LoadOMOPpack(sqlQuery, OMOP_PACK_POJO.class);
while(loader.hasNext()) {
List<OMOP_PACK_POJO> rows = loader.next();
System.out.println(rows.get(0).getConceptId());
break;
}
}
}
package fr.erias.frenchdrugs.omop;
public class OMOP_TEST {
public static final String pack_doliprane_8_cp = "36880199";
}
package fr.erias.frenchdrugs.omop;
import java.util.ArrayList;
import java.util.List;
import org.hibernate.Session;
import org.hibernate.Transaction;
import fr.erias.frenchdrugs.entities.OMOP_CD_HASH;
import fr.erias.frenchdrugs.postgresql.HibernateUtil;
public class OMOPcdHashWrite {
private List<OMOP_CD_HASH> hashes = new ArrayList<OMOP_CD_HASH>();
public OMOPcdHashWrite() {
}
public void add(String cd_id, String hash) {
OMOP_CD_HASH cd = new OMOP_CD_HASH(cd_id, hash);
hashes.add(cd);
}
public void write() {
System.out.println("writing hashes...");
final Session session = HibernateUtil.getHibernateSession();
Transaction t = session.beginTransaction();
for (OMOP_CD_HASH hash : hashes) {
session.saveOrUpdate(hash);
}
t.commit();
session.close();
}
public static void main(String[] args) {
OMOPcdHashWrite w = new OMOPcdHashWrite();
w.add("1", "2");
w.write();
}
}
......@@ -4,103 +4,94 @@ import java.util.ArrayList;
import java.util.List;
import fr.erias.frenchdrugs.atomsexceptions.InvalidUnitException;
import fr.erias.frenchdrugs.entities.OMOP_CD_POJO;
import fr.erias.frenchdrugs.entities.OMOP_PACK_POJO;
import fr.erias.frenchdrugs.labels.ELang;
import fr.erias.frenchdrugs.loaders.DBloaders;
import fr.erias.frenchdrugs.loaders.IProvideAllAtomicsEl;
import fr.erias.romedi.atoms.DoseForm;
import fr.erias.romedi.atoms.Route;
import fr.erias.romedi.atoms.Substance;
import fr.erias.romedi.atoms.Unit;
import fr.erias.romedi.cd.CDroute;
import fr.erias.romedi.cd.CD;
import fr.erias.romedi.cdc.CDC;
import fr.erias.romedi.pack.Pack;
import fr.erias.romedi.quandCD.QuantCD;
import fr.erias.romedi.strength.Concentration;
import fr.erias.romedi.strength.Strength;
public class TransformCD {
public class OMOPinstance {
private IProvideAllAtomicsEl atomsProvider;
private final IProvideAllAtomicsEl atomsProvider;
private final List<OMOP_PACK_POJO> rows;
public TransformCD(IProvideAllAtomicsEl atomsProvider) throws InvalidUnitException {
public OMOPinstance(IProvideAllAtomicsEl atomsProvider, List<OMOP_PACK_POJO> rows) throws InvalidUnitException {
this.atomsProvider = atomsProvider;
this.rows = rows;
}
public Pack getPack(List<OMOP_PACK_POJO> rows, CDroute cd) {
QuantCD quantCD = new QuantCD(cd, rows.get(0).getQuantcd_amount());
private OMOP_PACK_POJO getFirstRow() {
return(rows.get(0));
}
public boolean hasPackId() {
return(getFirstRow().getPack_id() != null);
}
public String getPackId() {
String packId = rows.get(0).getPack_id();
return(packId);
}
public boolean hasQuantCDid() {
return(getFirstRow().getQuant_cd_id() != null);
}
public String getQuantCDid() {
String quantCDid = rows.get(0).getQuant_cd_id();
return(quantCDid);
}
public boolean hasCDid() {
return(getFirstRow().getCD_id() != null);
}
public String getCDid() {
String cdId = rows.get(0).getCD_id();
return(cdId);
}
public Pack getPack() {
QuantCD quantCD = getQuantCD();
Pack pack = new Pack();
pack.addQuantCD(quantCD);
pack.setQuantity(rows.get(0).getPack_amount());
pack.setQuantity(rows.get(0).getAmount_pack());
return(pack);
}
public QuantCD getQuantCD(List<OMOP_PACK_POJO> rows, CDroute cd) {
QuantCD quantCD = new QuantCD(cd, rows.get(0).getQuantcd_amount());
public QuantCD getQuantCD() {
CD cd = getCD();
double quantityFactor = rows.get(0).getQuantity_factor();
QuantCD quantCD = new QuantCD(cd, quantityFactor);
return(quantCD);
}
public CDroute getCD(List<OMOP_PACK_POJO> rows) {
Route route = new Route(rows.get(0).getRoute_id());
DoseForm df = new DoseForm(rows.get(0).getDosageform_id());
public CD getCD() {
DoseForm df = new DoseForm(rows.get(0).getDf_id());
List<CDC> cdcs = new ArrayList<CDC>();
for (OMOP_PACK_POJO row : rows) {
CDC cdc = extractCDC(row);
cdcs.add(cdc);
}
CDroute cd = new CDroute(cdcs, df, route);
CD cd = new CD(cdcs, df);
return(cd);
}
public CDC extractCDC(OMOP_PACK_POJO res) {
Substance substance = new Substance(res.getSubstanceId());
Unit unit = atomsProvider.getUnitEl(ELang.FR, res.getUnit_strength_id());
private CDC extractCDC(OMOP_PACK_POJO res) {
Substance substance = new Substance(res.getSubstance_id());
Unit unit = atomsProvider.getUnitEl(ELang.FR, res.getStrength_unit_id());
Strength strengthSubstance = new Strength(res.getAmount(), unit);
Unit unitRef = atomsProvider.getUnitEl(ELang.FR, res.getUnit_ref_id());
Unit unitRef = atomsProvider.getUnitEl(ELang.FR, res.getRef_unit_id());
Strength refStrength = new Strength(res.getAmount_ref(), unitRef);
Concentration concentration = new Concentration(strengthSubstance, refStrength);
CDC cdc = new CDC(substance, concentration);
return(cdc);
}
public String getCDName(List<OMOP_PACK_POJO> rows) {
String cdName = rows.get(0).getCd_name();
return(cdName);
}
public String getPackName(List<OMOP_PACK_POJO> rows) {
String packName = rows.get(0).getPack_name();
return(packName);
}
public String getPackId(List<OMOP_PACK_POJO> rows) {
String packId = rows.get(0).getPack_id();
return(packId);
}
public String getQuantName(List<OMOP_PACK_POJO> rows) {
String quantName = rows.get(0).getQuantcd_name();
return(quantName);
}
public String getQuantId(List<OMOP_PACK_POJO> rows) {
String quantId = rows.get(0).getQuantcd_id();
return(quantId);
}
public String getCDid(List<OMOP_PACK_POJO> rows) {
String cdId = rows.get(0).getCd_id();
return(cdId);
}
public static void main(String[] args) throws InvalidUnitException {
TransformCD transFormCD = new TransformCD(DBloaders.getAtomsProvider());
LoadOMOPcd loadOMOP = new LoadOMOPcd(OMOP_CD_POJO.sqlQuery, OMOP_CD_POJO.class);
for (OMOP_CD_POJO pojo : loadOMOP.getEntities()) {
System.out.println(pojo.getCd_id());
break;
}
}
}
......@@ -6,6 +6,8 @@ import java.util.List;
import org.eclipse.rdf4j.model.IRI;
import org.eclipse.rdf4j.model.Model;
import org.eclipse.rdf4j.model.util.ModelBuilder;
import org.eclipse.rdf4j.model.vocabulary.DC;
import org.eclipse.rdf4j.model.vocabulary.OWL;
import org.eclipse.rdf4j.model.vocabulary.RDF;
import org.eclipse.rdf4j.model.vocabulary.RDFS;
......@@ -13,6 +15,7 @@ import org.eclipse.rdf4j.model.vocabulary.RDFS;
import fr.erias.frenchdrugs.atomsexceptions.InvalidUnitException;
import fr.erias.frenchdrugs.entities.DoseFormPOJO;
import fr.erias.frenchdrugs.entities.OMOP_PACK_POJO;
import fr.erias.frenchdrugs.labels.AtomsProvider;
import fr.erias.frenchdrugs.labels.IProvideRDFLabel;
import fr.erias.frenchdrugs.loaders.DBloaders;
import fr.erias.frenchdrugs.loaders.DoseFormLoader;
......@@ -20,6 +23,7 @@ import fr.erias.frenchdrugs.loaders.INormAtomicEl;
import fr.erias.frenchdrugs.loaders.IProvideAllAtomicsEl;