bzkf / obds-to-fhir

This project contains a Kafka Stream processor that creates FHIR resources from oBDS-XML data and writes them to a FHIR Topic.
GNU General Public License v3.0
3 stars 1 forks source link

refactor: use static lookup methods #69

Closed pcvolkmer closed 4 weeks ago

pcvolkmer commented 1 month ago

Since all lookup classes use immutable data, this replaces creating new objects at runtime with the use of static methods.

pcvolkmer commented 1 month 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 ...
}
chgl commented 1 month ago

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

miracum-bot commented 1 week ago

:tada: This PR is included in version 2.2.0 :tada:

The release is available on GitHub release

Your semantic-release bot :package::rocket: