Skip to content

Commit

Permalink
Merge pull request #9 from SevKohler/fix_missing_day
Browse files Browse the repository at this point in the history
added exclusion for partial date and updated test
  • Loading branch information
SevKohler authored Sep 6, 2024
2 parents 87bdfdc + cb76cd5 commit c8b1c38
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public ResponseEntity<Object> addCompositionJson(@RequestBody String json, @Path
if (ehrToPerson.isPresent()) {
Composition composition = new CanonicalJson().
unmarshal(json, com.nedap.archie.rm.composition.Composition.class);
System.out.println(composition);
return runConversion(composition, ehrToPerson.get().getPerson());
} else {
return new ResponseEntity<>("{ \"message\" : \"EHR id has no person, create either one or enter a correct ehr id\" }", HttpStatus.CONFLICT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.time.LocalDate;
import java.time.OffsetDateTime;
import java.time.ZoneId;
import java.time.temporal.ChronoField;
import java.time.temporal.Temporal;
import java.time.temporal.TemporalAccessor;
import java.time.temporal.TemporalAmount;
Expand Down Expand Up @@ -106,7 +107,8 @@ private Optional<Date> getIntervalEventStart(IntervalEvent intervalEvent) {
}

public Optional<Date> parseDvDateTime(TemporalAccessor dvDateTime) {
if (dvDateTime == null) {
if (dvDateTime == null || !dvDateTime.isSupported(ChronoField.DAY_OF_MONTH)) {
LOG.warn("Date was empty, or partial (e.g. Day missing), therefore Date is returned empty.");
return Optional.empty();
} else {
OffsetDateTime dateTime = OffsetDateTime.parse(dvDateTime.toString());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
package org.bih.eos.converter.cdt.conversion_entities;

import org.bih.eos.converter.cdt.converter.nonconfigurable.VisitOccurrenceConverter;
import org.bih.eos.exceptions.UnprocessableEntityException;
import org.bih.eos.jpabase.entity.Concept;
import org.bih.eos.jpabase.entity.Person;
import org.bih.eos.jpabase.entity.VisitOccurrence;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Date;
import java.util.Optional;

public class VisitOccurrenceEntity extends EntityWithStandardConcept<VisitOccurrence> {
private static final Logger LOG = LoggerFactory.getLogger(VisitOccurrenceEntity.class);


public VisitOccurrenceEntity(VisitOccurrence jpaEntity, Person person, Concept type) {
Expand Down Expand Up @@ -39,11 +43,24 @@ public void setEntitySourceValue(Optional<String> entitySourceValue) {
//ignored field doesnt exist
}

public void setEndDate(Optional<Date> date) {
populateFieldIfPresent(date, dateTimeValue -> {
jpaEntity.setVisitEndDate(dateTimeValue);
jpaEntity.setVisitEndDateTime(dateTimeValue);
});
public void setEndDate(Optional<Date> endDate, Optional<Date> startDate) {
if(endDate.isPresent()){
populateFieldIfPresent(endDate, dateTimeValue -> {
jpaEntity.setVisitEndDate(dateTimeValue);
jpaEntity.setVisitEndDateTime(dateTimeValue);
});
}else if(startDate.isPresent()){ //Set StartDate as EndDate since Enddate is emtpy
LOG.warn("EndDate time was empty provided by the composition, startDate is set instead for Visit_occurrence");
populateFieldIfPresent(startDate, dateTimeValue -> {
jpaEntity.setVisitEndDate(dateTimeValue);
jpaEntity.setVisitEndDateTime(dateTimeValue);
});
}
}

public void setDateStartAndEnd(Optional<Date> startDate, Optional<Date> endDate) {
setDateTime(startDate);
setEndDate(endDate, startDate);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ public VisitOccurrenceConverter(DefaultConverterServices defaultConverterService
public Optional<JPABaseEntity> convert(Composition composition, Person person) {
VisitOccurrenceEntity visitOccurrence = new VisitOccurrenceEntity(new VisitOccurrence(), person, defaultConverterServices.getConceptService().findById(32817L));
convertStandardAndSourceConcept(visitOccurrence);
visitOccurrence.setDateTime(convertStartDate(composition));
visitOccurrence.setEndDate(convertEndDate(composition));
visitOccurrence.setDateStartAndEnd(convertStartDate(composition), convertEndDate(composition));
visitOccurrence.setAdmittedFromConcept(defaultConverterServices.getConceptService().findById(0L));
visitOccurrence.setDischargeToConcept(defaultConverterServices.getConceptService().findById(0L));
return visitOccurrence.toJpaEntity();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.springframework.lang.NonNull;

import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;

public class CompositionToMDConverter extends CompositionToEntityConverter<CDTConverter, ConvertableComposition> {
HashMap<String, Integer> archetypeList = new HashMap<String, Integer>();
Expand All @@ -44,7 +45,7 @@ private List<JPABaseEntity> runCDTConverters(List<ConversionTrack> conversionTra
Optional<VisitOccurrence> visitOccurrence = convertVisitOccurrence(convertableComposition.getComposition(), convertableComposition.getPerson());
CdtExecutionParameterMedData cdtExecutionParameters = new CdtExecutionParameterMedData(convertableComposition.getPerson(), visitOccurrence);
cdtConverterResults = iterateContent(convertableComposition.getComposition().getContent(), cdtExecutionParameters, conversionTracker, cdtConverterResults);
LOG.info("Mapped amount of archetypes: " + archetypeList.values().stream().mapToInt(i -> i.intValue()).sum() + ", including following archetypes: " + archetypeList);
LOG.info("Mapped amount of all transformed archetypes: " + archetypeList.values().stream().mapToInt(i -> i.intValue()).sum() + ", including following archetypes: " + archetypeList);
return cdtConverterResults;
}

Expand All @@ -71,7 +72,7 @@ private void increaseArchetypeCounter(String archetypeNodeId) {
if (archetypeList.containsKey(archetypeNodeId)) {
archetypeList.put(archetypeNodeId, archetypeList.get(archetypeNodeId) + 1);
} else {
archetypeList.put(archetypeNodeId, 0);
archetypeList.put(archetypeNodeId, 1);
}
}

Expand Down
14 changes: 14 additions & 0 deletions src/main/java/org/bih/eos/services/ConverterService.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package org.bih.eos.services;

import com.nedap.archie.rm.composition.Composition;
import org.bih.eos.converter.cdt.conversion_entities.VisitOccurrenceEntity;
import org.bih.eos.services.dao.ConvertableComposition;
import org.bih.eos.jpabase.entity.JPABaseEntity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.convert.ConversionService;
import org.springframework.core.convert.TypeDescriptor;
import org.springframework.stereotype.Service;
Expand All @@ -14,21 +17,31 @@ public class ConverterService {
private final ConversionService conversionService;
private final PersistenceService persistenceService;

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

public ConverterService(ConversionService conversionService, PersistenceService persistenceService) {
this.conversionService = conversionService;
this.persistenceService = persistenceService;
}

@SuppressWarnings({"Unchecked", "ConstantConditions"})
public List<JPABaseEntity> convert(ConvertableComposition convertableComposition) {
logComposition(convertableComposition.getComposition());
persistenceService.clearPersistedEntities();
TypeDescriptor sourceType = TypeDescriptor.valueOf(ConvertableComposition.class);
TypeDescriptor targetType = TypeDescriptor.collection(List.class, TypeDescriptor.valueOf(JPABaseEntity.class));
persistenceService.create((List<JPABaseEntity>) conversionService.convert(convertableComposition, sourceType, targetType));
return persistenceService.getPersistedEntities();
}

private void logComposition(Composition composition) {
if(composition.getUid() != null){
LOG.info("Converting Composition with id: " + composition.getUid().getValue());
}
}

public List<JPABaseEntity> convertBatch(ConvertableComposition convertableComposition) {
logComposition(convertableComposition.getComposition());
persistenceService.clearPersistedEntities();
TypeDescriptor sourceType = TypeDescriptor.valueOf(ConvertableComposition.class);
TypeDescriptor targetType = TypeDescriptor.collection(List.class, TypeDescriptor.valueOf(JPABaseEntity.class));
Expand All @@ -42,6 +55,7 @@ public List<JPABaseEntity> convertLastBatch() {
return persistenceService.getPersistedEntities();
}
public List<JPABaseEntity> convert(Composition composition) {
logComposition(composition);
persistenceService.clearPersistedEntities();
TypeDescriptor sourceType = TypeDescriptor.valueOf(Composition.class);
TypeDescriptor targetType = TypeDescriptor.collection(List.class, TypeDescriptor.valueOf(JPABaseEntity.class));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"person": "##ignore",
"measurementConcept": {
"id": "##ignore",
"conceptName": "SARS-CoV-2 (COVID-19) Ag [Presence] in Respiratory specimen by Rapid immunoassay",
"conceptName": "SARS-CoV-2 (COVID-19) Ag [Presence] in Respiratory system specimen by Rapid immunoassay",
"domainId": "Measurement",
"vocabularyId": "LOINC",
"conceptClassId": "Lab Test",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"person": "##ignore",
"measurementConcept": {
"id": "##ignore",
"conceptName": "SARS-CoV-2 (COVID-19) Ag [Presence] in Respiratory specimen by Rapid immunoassay",
"conceptName": "SARS-CoV-2 (COVID-19) Ag [Presence] in Respiratory system specimen by Rapid immunoassay",
"domainId": "Measurement",
"vocabularyId": "LOINC",
"conceptClassId": "Lab Test",
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/karate-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ function fn() {

var config = {
baseUrl: 'http://localhost:8081',
ehrId: '266ee149-95f7-4b0d-8cbe-9790f91c40f6',
ehrId: 'bddb4332-090e-40ea-88d1-6e69f69d17eb',
action_composition_path: 'classpath:json/compositions/medical_data/action/',
evaluation_composition_path: 'classpath:json/compositions/medical_data/evaluation/',
instruction_composition_path: 'classpath:json/compositions/medical_data/instruction/',
Expand Down

0 comments on commit c8b1c38

Please sign in to comment.