Skip to content

Commit

Permalink
Merge branch 'release/0.9.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
dermatologist committed Apr 21, 2021
2 parents f4024d5 + bef471c commit c8a577b
Show file tree
Hide file tree
Showing 60 changed files with 2,671 additions and 411 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,4 @@ README.html
application/.factorypath
library/.factorypath
qtakes/.factorypath
graph/.factorypath
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@
"java.configuration.updateBuildConfiguration": "automatic",
"cSpell.words": [
"ESEARCH"
]
],
"licenser.license": "MPLv2",
"licenser.author": "Bell Eapen",
"licenser.projectName": "CKBLIB"
}
20 changes: 19 additions & 1 deletion application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</parent>
<groupId>com.canehealth.ckblib</groupId>
<artifactId>ckblib-application</artifactId>
<version>0.2.0</version>
<version>0.9.0</version>
<name>ckblib-application</name>
<description>Demo project for Spring Boot</description>
<properties>
Expand All @@ -27,12 +27,30 @@
<artifactId>library</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.canehealth.ckblib</groupId>
<artifactId>qtakes</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.canehealth.ckblib</groupId>
<artifactId>graph</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
<scope>provided</scope>
</dependency>

<!-- https://stackoverflow.com/questions/62006284/noclassdeffounderror-org-w3c-dom-ls-documentls-issue-occurring-only-on-deploy -->
<dependency>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
<version>2.12.0</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,83 @@
package com.canehealth.ckblib.application;

import com.canehealth.ckblib.library.service.MyService;
import com.canehealth.ckblib.library.util.CkblibConstants;

import java.util.List;
import java.util.Random;
import java.util.concurrent.TimeUnit;

import com.canehealth.ckblib.graph.*;
import com.canehealth.ckblib.graph.model.*;
import com.canehealth.ckblib.library.model.BaseQuery;
import com.canehealth.ckblib.library.model.EsearchResultRoot;
import com.canehealth.ckblib.library.service.CkbEfetch;
import com.canehealth.ckblib.library.service.CkbEsearch;
import com.canehealth.ckblib.qtakes.service.QtakesService;
import com.canehealth.ckblib.qtakes.model.ConceptMention;
import com.canehealth.ckblib.qtakes.model.QtakesRoot;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.neo4j.repository.config.EnableReactiveNeo4jRepositories;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@SpringBootApplication(scanBasePackages = "com.canehealth.ckblib")
@EnableReactiveNeo4jRepositories(basePackages = "com.canehealth.ckblib.graph")
public class DemoApplication implements CommandLineRunner {

private final MyService myService;
private static Logger LOG = LoggerFactory.getLogger(DemoApplication.class);
@Autowired
private BaseQuery baseQuery;

@Autowired
private CkbEsearch ckbEsearch;

@Autowired
private CkbEfetch ckbEfetch;

@Autowired
private QtakesService qtakesService;

@Autowired
JournalArticleService journalArticleService;

@Autowired
private JournalArticle journalArticle;

@Autowired
DiseaseDisorderService diseaseDisorderService;

@Autowired
private DiseaseDisorderMention diseaseDisorderMention;

@Autowired
SignSymptomService signSymptomService;

@Autowired
private SignSymptomMention signSymptomMention;

@Autowired
AnatomicalSiteService anatomicalSiteService;

@Autowired
private AnatomicalSiteMention anatomicalSiteMention;

@Autowired
MedicationService medicationService;

@Autowired
private MedicationMention medicationMention;

@Autowired
ProcedureService procedureService;

@Autowired
private ProcedureMention procedureMention;

public DemoApplication (MyService myService) {
this.myService = myService;
Expand All @@ -24,40 +88,215 @@ public static void main(String[] args) {
}

@Override
public void run(String... args) {
public void run(String... args) throws InterruptedException {
LOG.info("EXECUTING : " + myService.message());

String _function = "";
String _source = "";
String _destination = "";
String _term = "";
String mainCui = "";

try {
if (args[0].toLowerCase().equals("help")) {
System.out.println(CkblibConstants.HELP_STRING);
LOG.info(myService.message());
} else {
for (int i = 0; i < args.length; ++i) {
LOG.debug("args[{}]: {}", i, args[i]);
_function = args[0];
_source = args[1];
_destination = args[2];
_term = args[0];
}
}
baseQuery.setTerm(_term);
baseQuery.setRetmax(3);

// Check and adjust for total count of articles
ckbEsearch.setBaseQuery(baseQuery);
ckbEsearch.get();
TimeUnit.SECONDS.sleep(1);
EsearchResultRoot esearchResultRoot = ckbEsearch.getResults().get(0);
LOG.info("Count: " + esearchResultRoot.esearchresult.count);
int ct = Integer.parseInt(esearchResultRoot.esearchresult.count);
Random random = new Random();
if(ct>3){
baseQuery.setRetstart(random.nextInt(ct));
}


ckbEfetch.setBaseQuery(baseQuery);
TimeUnit.SECONDS.sleep(3);
ckbEfetch.get();
TimeUnit.SECONDS.sleep(5);

// Fails if disease not known, Try again after adding concepts
try {
mainCui = diseaseDisorderService.getDiseasesByName(_term).block().getCui();
} catch (Exception e) {
}

LOG.info("MainCUI: " + mainCui + "\n");

List<String> abstracts = ckbEfetch.getPath("//Abstract");
List<String> pmids = ckbEfetch.getPath("//PMID");
List<String> titles = ckbEfetch.getPath("//ArticleTitle");

qtakesService.setQtakesUrl("http://127.0.0.1:8093");

for (int i = 0; i < abstracts.size(); i++) {
LOG.info(pmids.get(i) + " : " + titles.get(i));
String pmid = pmids.get(i);

if (_function.equals("tofhirbundle")) {
// Chech if pmid processed
try{
JournalArticle processed = journalArticleService.getSymptomByPmid(pmid).block();
if(processed.getPmid().equals(pmid)){
LOG.info(pmid + " known.");
break;
}
}catch (Exception e) {
LOG.info("Processing: " + pmid);
}

journalArticle.setPmid(pmid);
journalArticle.setName(titles.get(i));
qtakesService.post(abstracts.get(i));
try {
// Should fail if already created
journalArticleService.saveArticle(journalArticle).block();

} catch (Exception e) {
System.out.println(CkblibConstants.HELP_STRING);

}
} else if (_function.equals("tofhirserver")) {
System.out.println("To FHIR SERVER not implemented yet");
} else if (_function.equals("toomop")) {
TimeUnit.SECONDS.sleep(3);
QtakesRoot r = qtakesService.getQtakesResults();

} else if (_function.toLowerCase().equals("help")) {
System.out.println(CkblibConstants.HELP_STRING);
// Diseases
List<ConceptMention>concepts = r.getDiseaseDisorderMention();
for(ConceptMention concept : concepts){
String name = concept.getText();
int polarity = 1;
if(concept.getPolarity()<0) polarity = concept.getPolarity();
String cui = concept.getConceptAttributes().get(0).cui;
diseaseDisorderMention.setCui(cui);
diseaseDisorderMention.setName(name);
try {
diseaseDisorderService.saveDisease(diseaseDisorderMention).block();
} catch (Exception e) {
LOG.info(name + " known.");
}
journalArticleService.addEvidence(cui, pmid).block();

if (!"".equals(mainCui) && !mainCui.equals(cui)) {
LOG.info("Adding DDs");
diseaseDisorderService.addDifferential(mainCui, cui, polarity, 0, 0);
}
}
// Disease should exist now
if("".equals(mainCui)){
try {
mainCui = diseaseDisorderService.getDiseasesByName(_term).block().getCui();
} catch (Exception e) {
LOG.error(mainCui + " unknown.");
}
}

// Signs and symptoms
concepts = r.getSignSymptomMention();
for (ConceptMention concept : concepts) {
String name = concept.getText();
int polarity = 1;
if (concept.getPolarity() < 0)
polarity = concept.getPolarity();
String cui = concept.getConceptAttributes().get(0).cui;
signSymptomMention.setCui(cui);
signSymptomMention.setName(name);
try {
signSymptomService.saveSymptom(signSymptomMention).block();
} catch (Exception e) {
LOG.info(name + " known.");
}
LOG.info("Disease: " + mainCui + " Contept: " + cui + "\n");
signSymptomService.addRelation(mainCui, cui, polarity, 0, 0).block();
journalArticleService.addEvidence(cui, pmid).block();
}

// Anatomy
concepts = r.getAnatomicalSiteMention();
for (ConceptMention concept : concepts) {
String name = concept.getText();
int polarity = 1;
if (concept.getPolarity() < 0)
polarity = concept.getPolarity();
String cui = concept.getConceptAttributes().get(0).cui;
anatomicalSiteMention.setCui(cui);
anatomicalSiteMention.setName(name);
try {
anatomicalSiteService.saveSymptom(anatomicalSiteMention).block();
} catch (Exception e) {
LOG.info(name + " known.");
}
LOG.info("Disease: " + mainCui + " Contept: " + cui + "\n");
anatomicalSiteService.addRelation(mainCui, cui, polarity, 0, 0).block();
journalArticleService.addEvidence(cui, pmid).block();
}

// Medication
concepts = r.getMedicationMention();
for (ConceptMention concept : concepts) {
String name = concept.getText();
int polarity = 1;
if (concept.getPolarity() < 0)
polarity = concept.getPolarity();
String cui = concept.getConceptAttributes().get(0).cui;
medicationMention.setCui(cui);
medicationMention.setName(name);
try {
medicationService.saveSymptom(medicationMention).block();
} catch (Exception e) {
LOG.info(name + " known.");
}
LOG.info("Disease: " + mainCui + " Contept: " + cui + "\n");
medicationService.addRelation(mainCui, cui, polarity, 0, 0).block();
journalArticleService.addEvidence(cui, pmid).block();
}

// Procedure
concepts = r.getProcedureMention();
for (ConceptMention concept : concepts) {
String name = concept.getText();
int polarity = 1;
if (concept.getPolarity() < 0)
polarity = concept.getPolarity();
String cui = concept.getConceptAttributes().get(0).cui;
procedureMention.setCui(cui);
procedureMention.setName(name);
try {
procedureService.saveSymptom(procedureMention).block();
} catch (Exception e) {
LOG.info(name + " known.");
}
LOG.info("Disease: " + mainCui + " Contept: " + cui + "\n");
procedureService.addRelation(mainCui, cui, polarity, 0, 0).block();
journalArticleService.addEvidence(cui, pmid).block();
}
//System.out.println(r);
}

} catch (Exception e) {
System.out.println(CkblibConstants.HELP_STRING);
LOG.error(e.getLocalizedMessage());
}
// String myPublications = ckbEfetch.getPath("//Abstract").get(0);
// String myPMID = ckbEfetch.getPath("//PMID").get(0);
// System.out.print(myPublications);
// System.out.print(myPMID);

// qtakesService.setQtakesUrl("http://127.0.0.1:8093");
// qtakesService.post(myPublications);
// TimeUnit.SECONDS.sleep(3);
// QtakesRoot r = qtakesService.getQtakesResults();
// System.out.print(r.toString());
// String s = ckbEfetch.getChain(baseQuery).block();
// List<String> abstracts = ckbEfetch.getPathFromString("//Abstract", s);
// for (String abs : abstracts){
// System.out.println(abs);
// }

}

}
Loading

0 comments on commit c8a577b

Please sign in to comment.