Skip to content

Commit

Permalink
Refactor transform into simpler methods
Browse files Browse the repository at this point in the history
  • Loading branch information
jbiskie authored and jorg3lopez committed Sep 27, 2024
1 parent 6b15821 commit 6eb52dd
Showing 1 changed file with 31 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,36 +43,13 @@ public void transform(FhirResource<?> resource, Map<String, String> args) {
}

var coding = codingList.get(0);

if (!HapiHelper.hasCodingExtensionWithUrl(coding, HapiHelper.EXTENSION_CWE_CODING)) {
continue;
}
var cwe =
HapiHelper.getCodingExtensionByUrl(coding, HapiHelper.EXTENSION_CWE_CODING)
.getValue()
.toString();

if (!HapiHelper.hasCodingSystem(coding)) {
continue;
}
var codingSystem = HapiHelper.getCodingSystem(coding);

if (!Objects.equals(cwe, "alt-coding")
|| !HapiHelper.LOCAL_CODE_URL.equals(codingSystem)) {
if (!hasLocalCodeInAlternateCoding(coding)) {
continue;
}

var identifier = codingMap.get(coding.getCode());

if (identifier == null) {
var msh41Identifier = HapiHelper.getMSH4_1Identifier(bundle);
var msh41Value = msh41Identifier != null ? msh41Identifier.getValue() : null;

LOGGER.logWarning(
"Unmapped local code detected: '{}', from sender: '{}', message Id: '{}'",
coding.getCode(),
msh41Value,
HapiHelper.getMessageControlId(bundle));
logUnmappedLocalCode(bundle, coding);
continue;
}

Expand All @@ -81,6 +58,35 @@ public void transform(FhirResource<?> resource, Map<String, String> args) {
}
}

private Boolean hasLocalCodeInAlternateCoding(Coding coding) {
if (!HapiHelper.hasCodingExtensionWithUrl(coding, HapiHelper.EXTENSION_CWE_CODING)) {
return false;
}

if (!HapiHelper.hasCodingSystem(coding)) {
return false;
}

var cwe =
HapiHelper.getCodingExtensionByUrl(coding, HapiHelper.EXTENSION_CWE_CODING)
.getValue()
.toString();
var codingSystem = HapiHelper.getCodingSystem(coding);

return Objects.equals(cwe, "alt-coding") && HapiHelper.LOCAL_CODE_URL.equals(codingSystem);
}

private void logUnmappedLocalCode(Bundle bundle, Coding coding) {
var msh41Identifier = HapiHelper.getMSH4_1Identifier(bundle);
var msh41Value = msh41Identifier != null ? msh41Identifier.getValue() : null;

LOGGER.logWarning(
"Unmapped local code detected: '{}', from sender: '{}', message Id: '{}'",
coding.getCode(),
msh41Value,
HapiHelper.getMessageControlId(bundle));
}

private String urlForCodeType(String code) {
return switch (code) {
case HapiHelper.LOINC_CODE -> HapiHelper.LOINC_URL;
Expand Down

0 comments on commit 6eb52dd

Please sign in to comment.