Skip to content

Commit

Permalink
Quick fix for adding new patient aliases to a Patient node (#593)
Browse files Browse the repository at this point in the history
Signed-off-by: Angelica Ochoa <[email protected]>
  • Loading branch information
ao508 authored Feb 8, 2022
1 parent e8259b3 commit bbdb78e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
25 changes: 25 additions & 0 deletions model/src/main/java/org/mskcc/cmo/metadb/model/MetadbPatient.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,14 @@ public void addMetaDbSample(MetadbSample metaDbSample) {
metaDbSampleList.add(metaDbSample);
}

/**
* Returns patient aliases list.
* @return List
*/
public List<PatientAlias> getPatientAliases() {
if (patientAliases == null) {
patientAliases = new ArrayList<>();
}
return patientAliases;
}

Expand All @@ -92,6 +99,24 @@ public void addPatientAlias(PatientAlias patientAlias) {
patientAliases.add(patientAlias);
}

/**
* Determines whether Patient has a patient alias matching the namespace provided.
* @param patientAlias
* @return Boolean
*/
public Boolean hasPatientAlias(PatientAlias patientAlias) {
if (patientAliases == null) {
patientAliases = new ArrayList<>();
return Boolean.FALSE;
}
for (PatientAlias alias : patientAliases) {
if (alias.getNamespace().equalsIgnoreCase(patientAlias.getNamespace())) {
return Boolean.TRUE;
}
}
return Boolean.FALSE;
}

@Override
public String toString() {
return ToStringBuilder.reflectionToString(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.mskcc.cmo.common.MetadbJsonComparator;
import org.mskcc.cmo.metadb.model.MetadbPatient;
import org.mskcc.cmo.metadb.model.MetadbRequest;
import org.mskcc.cmo.metadb.model.MetadbSample;
import org.mskcc.cmo.metadb.model.PatientAlias;
import org.mskcc.cmo.metadb.model.SampleMetadata;
import org.mskcc.cmo.metadb.model.web.PublishedMetadbSample;
import org.mskcc.cmo.metadb.persistence.neo4j.MetadbSampleRepository;
Expand Down Expand Up @@ -66,9 +69,20 @@ public MetadbSample fetchAndLoadSampleDetails(MetadbSample sample) throws Except
patientService.savePatientMetadata(patient);
sample.setPatient(patient);
} else {
// go through the new patient aliases and indicator for whether a
// new patient alias was added to the existing patient
Boolean patientUpdated = Boolean.FALSE;
for (PatientAlias pa : patient.getPatientAliases()) {
if (!existingPatient.hasPatientAlias(pa)) {
existingPatient.addPatientAlias(pa);
patientUpdated = Boolean.TRUE;
}
}
if (patientUpdated) {
patientService.savePatientMetadata(existingPatient);
}
sample.setPatient(existingPatient);
}

return sample;
}

Expand Down

0 comments on commit bbdb78e

Please sign in to comment.