Spring Data Commons implementation for HAPI FHIR (Part 4)
<p>Now we are ready to implement more advance functionality. In our Repository Factory<strong> </strong>we override the query lookup strategy using our own implementation for FHIR queries (see the next section)</p>
<p><strong>Strategy:</strong></p>
<pre>
public class FHIRQueryLookupStrategy implements QueryLookupStrategy {
private final IGenericClient fhirClient;
public FHIRQueryLookupStrategy(IGenericClient fhirClient) {
this.fhirClient = fhirClient;
}
@Override
public RepositoryQuery resolveQuery(Method method, RepositoryMetadata metadata, ProjectionFactory factory, NamedQueries namedQueries) {
return new FHIRQuery(method, metadata, factory, fhirClient);
}
}</pre>
<p><strong>Repository Factory:</strong></p>
<pre>
public class FhirRepositoryFactory extends RepositoryFactorySupport {
private final IGenericClient fhirClient;
...
@Override
protected Optional<QueryLookupStrategy> getQueryLookupStrategy(QueryLookupStrategy.Key key,
QueryMethodEvaluationContextProvider evaluationContextProvider) {
return Optional.of(new FHIRQueryLookupStrategy(fhirClient));
}
}</pre>
<h1>Query methods support</h1>
<p><img alt="" src="https://miro.medium.com/v2/resize:fit:667/1*ApmMIMF4wscOw72AL5vTvw.png" style="height:468px; width:667px" /></p>
<p>No we are implementing <strong>RepositoryQuery</strong> interface which has two methods:<br />
<strong>execute() </strong>— executes the target method.<br />
<strong>getQueryMethod() </strong>— returns a method metadata.</p>
<p>Inside the constructor we take general methods metadata and also parse parameter names (based on method name).</p>
<p><a href="https://medium.com/@svosh2/spring-data-commons-implementation-for-hapi-fhir-part-4-c6c27bcf67d1"><strong>Click Here</strong></a></p>