-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add default implementation of reference validator
This adds a generic interface for MII mappers containing a default implementation of a reference validator.
- Loading branch information
Showing
9 changed files
with
296 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/main/java/org/miracum/streams/ume/obdstofhir/mapper/mii/Mapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package org.miracum.streams.ume.obdstofhir.mapper.mii; | ||
|
||
import java.util.Objects; | ||
import org.apache.commons.lang3.Validate; | ||
import org.hl7.fhir.r4.model.Enumerations.ResourceType; | ||
import org.hl7.fhir.r4.model.Reference; | ||
|
||
public interface Mapper<S, D> { | ||
|
||
/** | ||
* Default implementation of reference validation. This does not check the existance of the | ||
* referenced resource! | ||
* | ||
* @param reference The reference to be validated | ||
* @param resourceType The required resource type of the reference | ||
* @return Will return `true` if reference is usable | ||
* @throws NullPointerException if reference is null | ||
* @throws IllegalArgumentException if reference is not of required reesource type. | ||
*/ | ||
default boolean verifyReference(Reference reference, ResourceType resourceType) | ||
throws NullPointerException, IllegalArgumentException { | ||
Objects.requireNonNull( | ||
reference, String.format("Reference to %s must not be null", resourceType.toString())); | ||
Validate.isTrue( | ||
Objects.equals(reference.getReferenceElement().getResourceType(), resourceType.toCode()), | ||
String.format("The reference should point to a %s resource", resourceType.toString())); | ||
|
||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.