package org.pdxfinder.repositories;

import org.pdxfinder.dao.Patient;
import org.pdxfinder.dao.PatientSnapshot;
import org.springframework.data.neo4j.annotation.Query;
import org.springframework.data.neo4j.repository.Neo4jRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.Set;

@Repository
public interface PatientSnapshotRepository extends Neo4jRepository<PatientSnapshot, Long> {

    Set<Patient> findByAge(String sex);

    Set<Patient> findByPatientSex(String sex);

    Patient findByPatientExternalId(String externalId);

    @Query("MATCH (ps:PatientSnapshot)--(p:Patient) WHERE p.externalId = {patientId} RETURN ps")
    Set<PatientSnapshot> findByPatient(@Param("patientId") String patientId);

    @Query("MATCH (mod:ModelCreation)-[ii:IMPLANTED_IN]-(s:Sample)-[sf:SAMPLED_FROM]-(ps:PatientSnapshot)-[pr:PATIENT]-(p:Patient)" +
            "WHERE mod.sourcePdxId = {modelId} " +
            "RETURN mod,ii,s,sf,ps, p, pr")
    PatientSnapshot findByModelId(@Param("modelId") String modelId);

}

@@ -915,16 +915,19 @@
 Patient)
+ %5Cn
 %22 +%0A    
@@ -968,17 +968,220 @@
 modelId%7D
- 
+%5Cn%22 +%0A            %22WITH mod, ii, s, sf, ps, pr, p%5Cn%22 +%0A            %22OPTIONAL MATCH (s)-%5Bot:ORIGIN_TISSUE%5D-(t1:Tissue)%5Cn%22 +%0A            %22OPTIONAL MATCH (s)-%5Bss:SAMPLE_SITE%5D-(t2:Tissue)%5Cn%22 +%0A            %22%5Cn
 %22 +%0A    
@@ -1217,16 +1217,32 @@
 s, p, pr
+, t1, t2, ot, ss
 %22)%0A    P

Update query with additional nodes