Closed pcvolkmer closed 4 weeks ago
Notice: If you plan to use a "term server" as mentioned in https://github.com/bzkf/obds-to-fhir/pull/65#issuecomment-2284607324, this PR should not be merged.
A testable lookup class will eventually make use some kind of REST client and therefore needs a dependency of a REST client, witch has to be provided at runtime using DI, e.g.:
public class BeurteilungResidualstatusVsLookup {
private RestTemplate restTemplate;
public BeurteilungResidualstatusVsLookup(RestTemplate restTemplate) {
this.restTemplate = restTemplate;
}
public final String lookupDisplay(String code) {
this.restTemplate.getForEntity( ... )
// .. handle response ...
}
}
Test classes could provide TestRestTemplate
to simulate a HTTP response.
If using static lookup methods, the injection and use of a RestTemplate
is not possible any more on object creation at runtime, but lookup classes can be used as Spring Beans instead, using @Component
annotation, witch will also result in some kind of singleton/prototyped objects.
As an alternative, you could use a second argument holding a reference to the RestTemplate
, but his looks some kind of wierd:
public static String lookupDisplay(String code, RestTemplate restTemplate) {
restTemplate.getForEntity( ... )
// .. handle response ...
}
I think its fine to merge this as well, a nice refactoring. But more effort should definitely depend on if we move forward with #70
:tada: This PR is included in version 2.2.0 :tada:
The release is available on GitHub release
Your semantic-release bot :package::rocket:
Since all lookup classes use immutable data, this replaces creating new objects at runtime with the use of static methods.