Skip to content

Commit

Permalink
refactor: some minor code cleanup
Browse files Browse the repository at this point in the history
* use .getFirst() instead of .get(0)
* use of ifPresent(..)
* simplify if conditions
  • Loading branch information
pcvolkmer committed Aug 16, 2024
1 parent 76e18ec commit 1d0d1e3
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public Bundle mapOnkoResourcesToCondition(
}

// get first element of meldungExportList
var meldungExport = meldungExportList.get(0);
var meldungExport = meldungExportList.getFirst();

LOG.debug(
"Mapping Meldung {} to {}", getReportingIdFromAdt(meldungExport), ResourceType.Condition);
Expand Down Expand Up @@ -173,10 +173,9 @@ public Bundle mapOnkoResourcesToCondition(
fhirProperties.getSystems().getIdentifierType(), "MR", null)))
.setValue(pid)));

var conditionDateString = primDia.getDiagnosedatum();
if (conditionDateString.isPresent()) {
onkoCondition.setOnset(convertObdsDateToDateTimeType(conditionDateString.get()));
}
primDia
.getDiagnosedatum()
.ifPresent(value -> onkoCondition.setOnset(convertObdsDateToDateTimeType(value)));

var stageBackBoneComponentList = new ArrayList<Condition.ConditionStageComponent>();
var evidenceBackBoneComponentList = new ArrayList<Condition.ConditionEvidenceComponent>();
Expand All @@ -199,7 +198,7 @@ public Bundle mapOnkoResourcesToCondition(
stageBackBoneComponentList.add(conditionStageComponent);
}
} else {
var profile = obsEntry.getResource().getMeta().getProfile().get(0).getValue();
var profile = obsEntry.getResource().getMeta().getProfile().getFirst().getValue();
if (profile.equals(fhirProperties.getProfiles().getHistologie())) {
// || profile.equals(fhirProperties.getProfiles().getGenVariante())) { Genetische
// Variante
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public Bundle mapOnkoResourcesToMedicationStatement(List<MeldungExport> meldungE
var bundle = new Bundle();

// get first element of meldungExportList
var meldungExport = meldungExportList.get(0);
var meldungExport = meldungExportList.getFirst();

LOG.debug(
"Mapping Meldung {} to {}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public Bundle mapOnkoResourcesToPatient(List<MeldungExport> meldungExportList) {
}

// address
var patAddess = patData.getMenge_Adresse().getAdresse().get(0);
var patAddess = patData.getMenge_Adresse().getAdresse().getFirst();
if (StringUtils.hasLength(patAddess.getPatienten_PLZ())) {
var address = new Address();
address.setPostalCode(patAddess.getPatienten_PLZ()).setType(Address.AddressType.BOTH);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ public Procedure createOpProcedure(
// Complication
if (op.getMenge_Komplikation() != null
&& op.getMenge_Komplikation().getOP_Komplikation() != null
&& op.getMenge_Komplikation().getOP_Komplikation().size() > 0) {
&& !op.getMenge_Komplikation().getOP_Komplikation().isEmpty()) {
var complicationConcept = new CodeableConcept();
for (var complication : op.getMenge_Komplikation().getOP_Komplikation()) {
complicationConcept.addCoding(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,11 @@ public ValueMapper<Pair<MeldungExportList, Bundle>, Bundle> getOnkoToConditionBu
private static String patientBundleKeySelector(Bundle bundle) {
var patients = BundleUtil.toListOfResourcesOfType(ctx, bundle, Patient.class);

if (patients.isEmpty() || patients.size() > 1) {
if (patients.size() != 1) {
throw new RuntimeException(
String.format("A patient bundle contains %d resources instead of 1", patients.size()));
}
var patient = patients.get(0);
var patient = patients.getFirst();
return String.format("%s/%s", patient.getResourceType(), patient.getId());
}
}

0 comments on commit 1d0d1e3

Please sign in to comment.