Skip to content

Commit

Permalink
fix: handle Primaertumor_ICD_Version being unset or not matching regex
Browse files Browse the repository at this point in the history
  • Loading branch information
chgl committed Apr 25, 2024
1 parent 7398750 commit 37db65e
Showing 1 changed file with 24 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
import org.hl7.fhir.r4.model.*;
import org.miracum.streams.ume.obdstofhir.FhirProperties;
import org.miracum.streams.ume.obdstofhir.lookup.*;
Expand All @@ -12,12 +13,16 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.StringUtils;

@Configuration
public class ObdsConditionMapper extends ObdsToFhirMapper {

private static final Logger LOG = LoggerFactory.getLogger(ObdsConditionMapper.class);

private static final Pattern icdVersionPattern =
Pattern.compile("^(10 (?<versionYear>20\\d{2}) ((GM)|(WHO))|Sonstige)$");

@Value("${app.version}")
private String appVersion;

Expand Down Expand Up @@ -94,18 +99,26 @@ public Bundle mapOnkoResourcesToCondition(
.getMeta()
.setProfile(List.of(new CanonicalType(fhirProperties.getProfiles().getCondition())));

var coding = new Coding();
var icd10Version = primDia.getPrimaertumor_ICD_Version();
// Aufbau: "10 2021 GM"
String[] icdVersionArray = icd10Version.split(" ");
var coding =
new Coding()
.setCode(primDia.getPrimaertumor_ICD_Code())
.setSystem(fhirProperties.getSystems().getIcd10gm());

if (icdVersionArray.length == 3 && icdVersionArray[1].matches("^20\\d{2}$")) {
coding.setVersion(icdVersionArray[1]);
} // FIXME: else throw exception?

coding
.setCode(primDia.getPrimaertumor_ICD_Code())
.setSystem(fhirProperties.getSystems().getIcd10gm());
// Aufbau: "10 2021 GM"
var icd10Version = primDia.getPrimaertumor_ICD_Version();
if (StringUtils.hasLength(icd10Version)) {
var matcher = icdVersionPattern.matcher(icd10Version);
if (matcher.matches()) {
coding.setVersion(matcher.group("versionYear"));
} else {
LOG.warn(
"Primaertumor_ICD_Version doesn't match expected format. Expected: '{}', actual: '{}'",
icdVersionPattern.pattern(),
icd10Version);
}
} else {
LOG.warn("Primaertumor_ICD_Version is unset or contains only whitespaces");
}

var conditionCode = new CodeableConcept().addCoding(coding);
onkoCondition.setCode(conditionCode);
Expand Down

0 comments on commit 37db65e

Please sign in to comment.