Skip to content

Commit

Permalink
Merge pull request #192 from nr23730/regexId
Browse files Browse the repository at this point in the history
Regex
  • Loading branch information
nr23730 committed Dec 17, 2021
2 parents 78c1058 + d522b9a commit 94e60bf
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 11 deletions.
37 changes: 29 additions & 8 deletions src/main/java/fhirspark/JsonFhirMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public class JsonFhirMapper {
private static String patientUri;
private static String therapyRecommendationUri;
private static String mtbUri;
private static List<Regex> regex;

private FhirContext ctx = FhirContext.forR4();
private IGenericClient client;
Expand All @@ -113,6 +114,7 @@ public JsonFhirMapper(Settings settings) {
patientUri = settings.getPatientSystem();
mtbUri = settings.getDiagnosticReportSystem();
therapyRecommendationUri = settings.getObservationSystem();
regex = settings.getRegex();
}

/**
Expand Down Expand Up @@ -171,7 +173,8 @@ public String toJson(String patientId) throws JsonProcessingException {
// REBIOPSY HERE
mtb.getSamples().clear();
for (Reference specimen : diagnosticReport.getSpecimen()) {
mtb.getSamples().add(((Specimen) specimen.getResource()).getIdentifierFirstRep().getValue());
mtb.getSamples().add(
applyRegexToCbioportal(((Specimen) specimen.getResource()).getIdentifierFirstRep().getValue()));
}

for (Reference reference : diagnosticReport.getResult()) {
Expand Down Expand Up @@ -204,7 +207,7 @@ public String toJson(String patientId) throws JsonProcessingException {
ClinicalDatum cd = new ClinicalDatum().withAttributeName(attr[0]).withValue(attr[1]);
if (obs.getSpecimen().getResource() != null) {
Specimen specimen = (Specimen) obs.getSpecimen().getResource();
cd.setSampleId(specimen.getIdentifierFirstRep().getValue());
cd.setSampleId(applyRegexToCbioportal(specimen.getIdentifierFirstRep().getValue()));
}
therapyRecommendation.getReasoning().getClinicalData()
.add(cd);
Expand Down Expand Up @@ -417,10 +420,11 @@ public void addOrEditMtb(String patientId, List<Mtb> mtbs) throws DataFormatExce
}

mtb.getSamples().forEach(sample -> {
Specimen s = specimenAdapter.process(fhirPatient, sample);
String sampleId = applyRegexFromCbioportal(sample);
Specimen s = specimenAdapter.process(fhirPatient, sampleId);
bundle.addEntry().setFullUrl(s.getIdElement().getValue()).setResource(s)
.getRequest().setUrl("Specimen?identifier=https://cbioportal.org/specimen/|" + sample)
.setIfNoneExist("identifier=identifier=https://cbioportal.org/specimen/|" + sample)
.getRequest().setUrl("Specimen?identifier=https://cbioportal.org/specimen/|" + sampleId)
.setIfNoneExist("identifier=identifier=https://cbioportal.org/specimen/|" + sampleId)
.setMethod(Bundle.HTTPVerb.PUT);
diagnosticReport.addSpecimen(new Reference(s));
});
Expand Down Expand Up @@ -461,12 +465,13 @@ public void addOrEditMtb(String patientId, List<Mtb> mtbs) throws DataFormatExce
therapyRecommendation.getReasoning().getClinicalData().forEach(clinical -> {
Specimen s = null;
if (clinical.getSampleId() != null && clinical.getSampleId().length() > 0) {
s = specimenAdapter.process(fhirPatient, clinical.getSampleId());
String sampleId = applyRegexFromCbioportal(clinical.getSampleId());
s = specimenAdapter.process(fhirPatient, sampleId);
bundle.addEntry().setFullUrl(s.getIdElement().getValue()).setResource(s)
.getRequest().setUrl("Specimen?identifier=https://cbioportal.org/specimen/|"
+ clinical.getSampleId())
+ sampleId)
.setIfNoneExist("identifier=identifier=https://cbioportal.org/specimen/|"
+ clinical.getSampleId()).setMethod(Bundle.HTTPVerb.PUT);
+ sampleId).setMethod(Bundle.HTTPVerb.PUT);
}
try {
Method m = Class.forName("fhirspark.adapter.clinicaldata." + clinical.getAttributeId())
Expand Down Expand Up @@ -643,6 +648,22 @@ private String harmonizeId(IAnyResource resource) {
}
}

private String applyRegexToCbioportal(String input) {
String output = input;
for (Regex r : regex) {
output = output.replaceAll(r.getHis(), r.getCbio());
}
return output;
}

private String applyRegexFromCbioportal(String input) {
String output = input;
for (Regex r : regex) {
output = output.replaceAll(r.getCbio(), r.getHis());
}
return output;
}

/**
* Fetched Pubmed IDs that have been previously associated with the same alteration.
*
Expand Down
27 changes: 27 additions & 0 deletions src/main/java/fhirspark/Regex.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package fhirspark;

/**
* Regular expressions to convert cBioPortal IDs to HIS IDs.
*/
public class Regex {

private String cbio;
private String his;

public String getCbio() {
return cbio;
}

public void setCbio(String cbio) {
this.cbio = cbio;
}

public String getHis() {
return his;
}

public void setHis(String his) {
this.his = his;
}

}
15 changes: 14 additions & 1 deletion src/main/java/fhirspark/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"portalUrl",
"loginRequired",
"oncokbPath",
"hl7v2config"
"hl7v2config",
"regex"
})
public final class Settings {

Expand All @@ -47,6 +48,8 @@ public final class Settings {
private String oncokbPath;
@JsonProperty("hl7v2config")
private List<Hl7v2config> hl7v2config;
@JsonProperty("regex")
private List<Regex> regex;

@JsonProperty("port")
public Integer getPort() {
Expand Down Expand Up @@ -158,4 +161,14 @@ public void setHl7v2config(List<Hl7v2config> hl7v2config) {
this.hl7v2config = hl7v2config;
}

@JsonProperty("regex")
public List<Regex> getRegex() {
return regex;
}

@JsonProperty("regex")
public void setRegex(List<Regex> newRegex) {
regex = newRegex;
}

}
8 changes: 6 additions & 2 deletions src/main/resources/settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@ specimenSystem: ${FHIRSPARK_SPECIMENSYSTEM:-https://cbioportal.org/specimen/}
diagnosticReportSystem: ${FHIRSPARK_DIAGNOSTICREPORTSYSTEM:-https://cbioportal.org/mtb/}
observationSystem: ${FHIRSPARK_OBSERVATIONSYSTEM:-https://cbioportal.org/therapyrecommendation/}
patientSystem: ${FHIRSPARK_PATIENTSYSTEM:-https://cbioportal.org/patient/}
portalUrl: ${FHIRSPARK_PORTALURL:-http://cbioportal/}
loginRequired: ${FHIRSPARK_LOGINREQUIRED:-true}
portalUrl: ${FHIRSPARK_PORTALURL:-http://localhost:8080/}
loginRequired: ${FHIRSPARK_LOGINREQUIRED:-false}
hgncPath: ${FHIRSPARK_HGNCPATH:-hgnc.csv}
oncokbPath: ${FHIRSPARK_ONCOKBPATH:-drugs.json}
hl7v2config:
- sendv2: ${FHIRSPARK_SENDHL7V2:-false}
server: ${FHIRSPARK_HL7V2SERVER:-localhost}
port: ${FHIRSPARK_HL7V2PORT:-1011}
regex:
-
cbio: ${FHIRSPARK_REGEX_CBIO:-/}
his: ${FHIRSPARK_REGEX_HIS:-/}

0 comments on commit 94e60bf

Please sign in to comment.