/
ConceptRepository.java
40 lines (33 loc) · 1.68 KB
/
ConceptRepository.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package org.openconceptlab.fhir.repository;
import org.openconceptlab.fhir.model.Concept;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import java.util.List;
/**
* The ConceptRepository.
* @author harpatel1
*/
@Repository
public interface ConceptRepository extends BaseOclRepository<Concept>{
List<Concept> findByMnemonic(String mnemonic);
@Query(nativeQuery = true, value = "select * from concepts c2 where c2.id in (" +
"select concept_id from (\n" +
"select max(cs.concept_id) as concept_id , c1.mnemonic from concepts_sources cs \n" +
"inner join concepts c1 on c1.id = cs.concept_id \n" +
"where cs.source_id = :sourceId\n" +
"group by c1.mnemonic) as val \n" +
") order by c2.mnemonic asc")
Page<Concept> findConcepts(@Param("sourceId") Long sourceId, Pageable pageable);
@Query(nativeQuery = true, value = "select count(*) from (select max(cs.concept_id) as concept_id , c1.mnemonic from concepts_sources cs \n" +
"inner join concepts c1 on c1.id = cs.concept_id \n" +
"where cs.source_id = :sourceId\n" +
"group by c1.mnemonic) as val")
int findConceptCountInSource(@Param("sourceId") Long sourceId);
@Modifying(flushAutomatically = true, clearAutomatically = true)
@Query(value = "update concepts set version = :id where id = :id", nativeQuery = true)
void updateVersion(@Param("id") Long id);
}