-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add initial SystemischeTherapieMedicationStatementMapper #170
Merged
Merged
Changes from 3 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
fa4760c
feat: add initial SystemischeTherapieMedicationStatementMapper
pcvolkmer bf2fae3
add medication and bundle type
pcvolkmer 1648552
add missing subject, status and effective
pcvolkmer 71b87df
change property "mii-pr-medication-statement"
pcvolkmer 11205d5
set "partOf"
pcvolkmer 914ba6e
extract and change substance id generation from plain name
pcvolkmer 4760193
Revert "change property "mii-pr-medication-statement""
pcvolkmer 6f8625e
use custom system for medical statement id
pcvolkmer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
106 changes: 106 additions & 0 deletions
106
...racum/streams/ume/obdstofhir/mapper/mii/SystemischeTherapieMedicationStatementMapper.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,106 @@ | ||
package org.miracum.streams.ume.obdstofhir.mapper.mii; | ||
|
||
import de.basisdatensatz.obds.v3.SYSTTyp; | ||
import de.basisdatensatz.obds.v3.SYSTTyp.Meldeanlass; | ||
import java.util.Objects; | ||
import org.apache.commons.lang3.Validate; | ||
import org.hl7.fhir.r4.model.Bundle; | ||
import org.hl7.fhir.r4.model.CodeableConcept; | ||
import org.hl7.fhir.r4.model.Coding; | ||
import org.hl7.fhir.r4.model.Enumerations.ResourceType; | ||
import org.hl7.fhir.r4.model.Identifier; | ||
import org.hl7.fhir.r4.model.MedicationStatement; | ||
import org.hl7.fhir.r4.model.Period; | ||
import org.hl7.fhir.r4.model.Reference; | ||
import org.miracum.streams.ume.obdstofhir.FhirProperties; | ||
import org.miracum.streams.ume.obdstofhir.mapper.ObdsToFhirMapper; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.util.StringUtils; | ||
|
||
@Service | ||
public class SystemischeTherapieMedicationStatementMapper extends ObdsToFhirMapper { | ||
|
||
private static final Logger LOG = | ||
LoggerFactory.getLogger(SystemischeTherapieProcedureMapper.class); | ||
|
||
public SystemischeTherapieMedicationStatementMapper(FhirProperties fhirProperties) { | ||
super(fhirProperties); | ||
} | ||
|
||
public Bundle map(SYSTTyp syst, Reference patient, Reference procedure) { | ||
Objects.requireNonNull(syst, "Systemtherapie must not be null"); | ||
Objects.requireNonNull(patient, "Reference to Patient must not be null"); | ||
Objects.requireNonNull(procedure, "Reference to Procedure must not be null"); | ||
|
||
Validate.notBlank(syst.getSYSTID(), "Required SYST_ID is unset"); | ||
Validate.isTrue( | ||
Objects.equals( | ||
patient.getReferenceElement().getResourceType(), ResourceType.PATIENT.toCode()), | ||
"The subject reference should point to a Patient resource"); | ||
Validate.isTrue( | ||
Objects.equals( | ||
procedure.getReferenceElement().getResourceType(), ResourceType.PROCEDURE.toCode()), | ||
"The subject reference should point to a Procedure resource"); | ||
|
||
var bundle = new Bundle(); | ||
bundle.setType(Bundle.BundleType.TRANSACTION); | ||
|
||
for (var substanz : syst.getMengeSubstanz().getSubstanz()) { | ||
var systMedicationStatement = new MedicationStatement(); | ||
pcvolkmer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
systMedicationStatement | ||
.getMeta() | ||
.addProfile(fhirProperties.getProfiles().getMiiPrMedicationStatement()); | ||
|
||
if ((null != substanz.getATC() && StringUtils.hasText(substanz.getATC().getCode())) | ||
|| StringUtils.hasText(substanz.getBezeichnung())) { | ||
var substanzId = ""; | ||
if (null != substanz.getATC() && StringUtils.hasText(substanz.getATC().getCode())) { | ||
substanzId = substanz.getATC().getCode(); | ||
var atcCoding = | ||
new Coding( | ||
fhirProperties.getSystems().getAtcBfarm(), substanz.getATC().getCode(), ""); | ||
systMedicationStatement.setMedication(new CodeableConcept(atcCoding)); | ||
} else { | ||
substanzId = substanz.getBezeichnung().replaceAll("[^A-Za-z0-9]", ""); | ||
pcvolkmer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
systMedicationStatement.setMedication( | ||
new CodeableConcept().setText(substanz.getBezeichnung())); | ||
} | ||
|
||
// TODO: can we be sure that this SYST-ID is globally unqiue across all SYSTs? | ||
// if not we may instead need to construct the ID from the patient-id + others. | ||
var identifier = | ||
new Identifier() | ||
.setSystem(fhirProperties.getSystems().getSystemischeTherapieProcedureId()) | ||
pcvolkmer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
.setValue(String.format("%s_%s", syst.getSYSTID(), substanzId)); | ||
systMedicationStatement.addIdentifier(identifier); | ||
systMedicationStatement.setId(computeResourceIdFromIdentifier(identifier)); | ||
|
||
// Status / Effective | ||
var meldeanlass = syst.getMeldeanlass(); | ||
var period = new Period(); | ||
if (meldeanlass == Meldeanlass.BEHANDLUNGSENDE) { | ||
systMedicationStatement.setStatus( | ||
MedicationStatement.MedicationStatementStatus.COMPLETED); | ||
convertObdsDatumToDateTimeType(syst.getBeginn()) | ||
.ifPresent(start -> period.setStart(start.getValue(), start.getPrecision())); | ||
convertObdsDatumToDateTimeType(syst.getEnde()) | ||
.ifPresent(end -> period.setEnd(end.getValue(), end.getPrecision())); | ||
} else { | ||
systMedicationStatement.setStatus(MedicationStatement.MedicationStatementStatus.ACTIVE); | ||
convertObdsDatumToDateTimeType(syst.getBeginn()) | ||
.ifPresent(start -> period.setStart(start.getValue(), start.getPrecision())); | ||
} | ||
systMedicationStatement.setEffective(period); | ||
|
||
// Subject | ||
systMedicationStatement.setSubject(patient); | ||
|
||
bundle = addResourceAsEntryInBundle(bundle, systMedicationStatement); | ||
} | ||
} | ||
|
||
return bundle; | ||
} | ||
} |
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
66 changes: 66 additions & 0 deletions
66
...m/streams/ume/obdstofhir/mapper/mii/SystemischeTherapieMedicationStatementMapperTest.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,66 @@ | ||
package org.miracum.streams.ume.obdstofhir.mapper.mii; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import ca.uhn.fhir.context.FhirContext; | ||
import com.fasterxml.jackson.databind.DeserializationFeature; | ||
import com.fasterxml.jackson.dataformat.xml.XmlMapper; | ||
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; | ||
import com.fasterxml.jackson.module.jakarta.xmlbind.JakartaXmlBindAnnotationModule; | ||
import de.basisdatensatz.obds.v3.OBDS; | ||
import java.io.IOException; | ||
import org.approvaltests.Approvals; | ||
import org.hl7.fhir.r4.model.Reference; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.CsvSource; | ||
import org.miracum.streams.ume.obdstofhir.FhirProperties; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.context.properties.EnableConfigurationProperties; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
|
||
@SpringBootTest(classes = {FhirProperties.class}) | ||
@EnableConfigurationProperties | ||
class SystemischeTherapieMedicationStatementMapperTest { | ||
private static SystemischeTherapieMedicationStatementMapper sut; | ||
|
||
@BeforeAll | ||
static void beforeAll(@Autowired FhirProperties fhirProps) { | ||
sut = new SystemischeTherapieMedicationStatementMapper(fhirProps); | ||
} | ||
|
||
@ParameterizedTest | ||
@CsvSource({"Testpatient_1.xml", "Testpatient_2.xml", "Testpatient_3.xml"}) | ||
void map_withGivenObds_shouldCreateValidMedicationStatement(String sourceFile) | ||
throws IOException { | ||
final var resource = this.getClass().getClassLoader().getResource("obds3/" + sourceFile); | ||
assertThat(resource).isNotNull(); | ||
|
||
final var xmlMapper = | ||
XmlMapper.builder() | ||
.defaultUseWrapper(false) | ||
.addModule(new JakartaXmlBindAnnotationModule()) | ||
.addModule(new Jdk8Module()) | ||
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) | ||
.build(); | ||
|
||
final var obds = xmlMapper.readValue(resource.openStream(), OBDS.class); | ||
|
||
var obdsPatient = obds.getMengePatient().getPatient().getFirst(); | ||
|
||
var patient = new Reference("Patient/any"); | ||
var procedure = new Reference("Procedure/any"); | ||
var systMeldung = | ||
obdsPatient.getMengeMeldung().getMeldung().stream() | ||
.filter(m -> m.getSYST() != null) | ||
.findFirst() | ||
.get(); | ||
var bundle = sut.map(systMeldung.getSYST(), patient, procedure); | ||
|
||
var fhirParser = FhirContext.forR4().newJsonParser().setPrettyPrint(true); | ||
var fhirJson = fhirParser.encodeResourceToString(bundle); | ||
|
||
Approvals.verify( | ||
fhirJson, Approvals.NAMES.withParameters(sourceFile).forFile().withExtension(".fhir.json")); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...p_withGivenObds_shouldCreateValidMedicationStatement.Testpatient_1.xml.approved.fhir.json
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,36 @@ | ||
{ | ||
"resourceType": "Bundle", | ||
"type": "transaction", | ||
"entry": [ { | ||
"fullUrl": "MedicationStatement/99635bf8744dadda1f8b293046f2bfb3d021938263616e6228523113af2695c1", | ||
"resource": { | ||
"resourceType": "MedicationStatement", | ||
"id": "99635bf8744dadda1f8b293046f2bfb3d021938263616e6228523113af2695c1", | ||
"meta": { | ||
"profile": [ "https://www.medizininformatik-initiative.de/fhir/core/modul-medikation/StructureDefinition/MedicationStatement" ] | ||
}, | ||
"identifier": [ { | ||
"system": "https://bzkf.github.io/obds-to-fhir/identifiers/systemische-therapie-procedure-id", | ||
"value": "101_IN-1_L01FF05" | ||
} ], | ||
"status": "completed", | ||
"medicationCodeableConcept": { | ||
"coding": [ { | ||
"system": "http://fhir.de/CodeSystem/bfarm/atc", | ||
"code": "L01FF05" | ||
} ] | ||
}, | ||
"subject": { | ||
"reference": "Patient/any" | ||
}, | ||
"effectivePeriod": { | ||
"start": "2020-05", | ||
"end": "2020-10-15" | ||
} | ||
}, | ||
"request": { | ||
"method": "PUT", | ||
"url": "MedicationStatement/99635bf8744dadda1f8b293046f2bfb3d021938263616e6228523113af2695c1" | ||
} | ||
} ] | ||
} |
32 changes: 32 additions & 0 deletions
32
...p_withGivenObds_shouldCreateValidMedicationStatement.Testpatient_2.xml.approved.fhir.json
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,32 @@ | ||
{ | ||
"resourceType": "Bundle", | ||
"type": "transaction", | ||
"entry": [ { | ||
"fullUrl": "MedicationStatement/d5925147316a1e8c6e69c3f663fad0301c1666ca5bf1b14f4c75cdda22ffce3b", | ||
"resource": { | ||
"resourceType": "MedicationStatement", | ||
"id": "d5925147316a1e8c6e69c3f663fad0301c1666ca5bf1b14f4c75cdda22ffce3b", | ||
"meta": { | ||
"profile": [ "https://www.medizininformatik-initiative.de/fhir/core/modul-medikation/StructureDefinition/MedicationStatement" ] | ||
}, | ||
"identifier": [ { | ||
"system": "https://bzkf.github.io/obds-to-fhir/identifiers/systemische-therapie-procedure-id", | ||
"value": "11_1_Innere.1_Bicalutamid" | ||
} ], | ||
"status": "active", | ||
"medicationCodeableConcept": { | ||
"text": "Bicalutamid" | ||
}, | ||
"subject": { | ||
"reference": "Patient/any" | ||
}, | ||
"effectivePeriod": { | ||
"start": "2021-11-08" | ||
} | ||
}, | ||
"request": { | ||
"method": "PUT", | ||
"url": "MedicationStatement/d5925147316a1e8c6e69c3f663fad0301c1666ca5bf1b14f4c75cdda22ffce3b" | ||
} | ||
} ] | ||
} |
32 changes: 32 additions & 0 deletions
32
...p_withGivenObds_shouldCreateValidMedicationStatement.Testpatient_3.xml.approved.fhir.json
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,32 @@ | ||
{ | ||
"resourceType": "Bundle", | ||
"type": "transaction", | ||
"entry": [ { | ||
"fullUrl": "MedicationStatement/9d5246fd9512f352552a8ea37cbb65991f06e7497c6bf0575f81a49e1b9bfa35", | ||
"resource": { | ||
"resourceType": "MedicationStatement", | ||
"id": "9d5246fd9512f352552a8ea37cbb65991f06e7497c6bf0575f81a49e1b9bfa35", | ||
"meta": { | ||
"profile": [ "https://www.medizininformatik-initiative.de/fhir/core/modul-medikation/StructureDefinition/MedicationStatement" ] | ||
}, | ||
"identifier": [ { | ||
"system": "https://bzkf.github.io/obds-to-fhir/identifiers/systemische-therapie-procedure-id", | ||
"value": "12_1_Innere.1_Paclitaxel" | ||
} ], | ||
"status": "active", | ||
"medicationCodeableConcept": { | ||
"text": "Paclitaxel" | ||
}, | ||
"subject": { | ||
"reference": "Patient/any" | ||
}, | ||
"effectivePeriod": { | ||
"start": "2018-03-17" | ||
} | ||
}, | ||
"request": { | ||
"method": "PUT", | ||
"url": "MedicationStatement/9d5246fd9512f352552a8ea37cbb65991f06e7497c6bf0575f81a49e1b9bfa35" | ||
} | ||
} ] | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Da wollte ich am Mittwoch nochmal drüber diskutieren ob Bundle als Rückgabewert oder List<> nützlicher ist - in #159 haben wir das auch. Aber soll jetzt nicht blocken