add medication conversion from dstu2 to r4 (#430)

* add medication conversion from dstu2 to r4

* fixed test

* add description to the release notes
This commit is contained in:
ItayGoren 2021-02-01 16:43:51 +02:00 committed by GitHub
parent 82546c5764
commit 42d148a80e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 177 additions and 1 deletions

View File

@ -0,0 +1 @@
add medication conversion from dstu2 to r4

View File

@ -2923,6 +2923,8 @@ public class VersionConvertor_10_40 {
return TestScript10_40.convertTestScript((org.hl7.fhir.dstu2.model.TestScript) src); return TestScript10_40.convertTestScript((org.hl7.fhir.dstu2.model.TestScript) src);
if (src instanceof org.hl7.fhir.dstu2.model.ValueSet) if (src instanceof org.hl7.fhir.dstu2.model.ValueSet)
return ValueSet10_40.convertValueSet((org.hl7.fhir.dstu2.model.ValueSet) src, advisor); return ValueSet10_40.convertValueSet((org.hl7.fhir.dstu2.model.ValueSet) src, advisor);
if (src instanceof org.hl7.fhir.dstu2.model.Medication)
return Medication10_40.convertMedication((org.hl7.fhir.dstu2.model.Medication) src);
throw new FHIRException("Unknown resource " + src.fhirType()); throw new FHIRException("Unknown resource " + src.fhirType());
} }

View File

@ -0,0 +1,92 @@
package org.hl7.fhir.convertors.conv10_40;
import org.hl7.fhir.convertors.VersionConvertor_10_40;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.r4.model.Extension;
import org.hl7.fhir.r4.model.Medication;
import org.hl7.fhir.r4.model.Type;
import java.util.List;
public class Medication10_40 {
public static org.hl7.fhir.r4.model.Medication convertMedication(org.hl7.fhir.dstu2.model.Medication src) throws FHIRException {
if (src == null || src.isEmpty())
return null;
org.hl7.fhir.r4.model.Medication tgt = new org.hl7.fhir.r4.model.Medication();
VersionConvertor_10_40.copyDomainResource(src, tgt);
if (src.hasCode())
tgt.setCode(VersionConvertor_10_40.convertCodeableConcept(src.getCode()));
if (src.hasIsBrandElement())
tgt.addExtension(
"http://hl7.org/fhir/3.0/StructureDefinition/extension-Medication.isBrand",
VersionConvertor_10_40.convertBoolean(src.getIsBrandElement())
);
if (src.hasManufacturer())
tgt.setManufacturer(VersionConvertor_10_40.convertReference(src.getManufacturer()));
if (src.hasProduct()) {
if (src.getProduct().hasForm())
tgt.setForm(VersionConvertor_10_40.convertCodeableConcept(src.getProduct().getForm()));
for (org.hl7.fhir.dstu2.model.Medication.MedicationProductIngredientComponent ingridient : src.getProduct().getIngredient())
tgt.addIngredient(convertMedicationIngridient(ingridient));
if (src.getProduct().hasBatch())
tgt.setBatch(batch(src.getProduct().getBatch().get(0)));
}
if (src.hasPackage()) {
org.hl7.fhir.dstu2.model.Medication.MedicationPackageComponent package_ = src.getPackage();
if (package_.hasContainer())
tgt.addExtension(
"http://hl7.org/fhir/3.0/StructureDefinition/extension-Medication.package.container",
VersionConvertor_10_40.convertCodeableConcept(package_.getContainer())
);
for (org.hl7.fhir.dstu2.model.Medication.MedicationPackageContentComponent c : package_.getContent())
tgt.addExtension(
"http://hl7.org/fhir/3.0/StructureDefinition/extension-Medication.package.content",
content(c)
);
}
return tgt;
}
private static org.hl7.fhir.r4.model.Medication.MedicationBatchComponent batch(org.hl7.fhir.dstu2.model.Medication.MedicationProductBatchComponent src) {
if (src == null || src.isEmpty())
return null;
org.hl7.fhir.r4.model.Medication.MedicationBatchComponent tgt = new org.hl7.fhir.r4.model.Medication.MedicationBatchComponent();
VersionConvertor_10_40.copyElement(src, tgt);
if (src.hasLotNumber())
tgt.setLotNumber(src.getLotNumber());
if (src.hasExpirationDate())
tgt.setExpirationDate(src.getExpirationDate());
return tgt;
}
private static org.hl7.fhir.r4.model.Extension content(org.hl7.fhir.dstu2.model.Medication.MedicationPackageContentComponent src) {
if (src == null || src.isEmpty())
return null;
org.hl7.fhir.r4.model.Extension tgt = new org.hl7.fhir.r4.model.Extension();
VersionConvertor_10_40.copyElement(src, tgt);
if (src.hasItem())
tgt.addExtension(
"http://hl7.org/fhir/3.0/StructureDefinition/extension-Medication.package.content",
VersionConvertor_10_40.convertReference(src.getItem())
);
if (src.hasAmount())
tgt.addExtension(
"http://hl7.org/fhir/3.0/StructureDefinition/extension-Medication.package.content.amount",
VersionConvertor_10_40.convertSimpleQuantity(src.getAmount())
);
return tgt;
}
private static org.hl7.fhir.r4.model.Medication.MedicationIngredientComponent convertMedicationIngridient(org.hl7.fhir.dstu2.model.Medication.MedicationProductIngredientComponent src) {
if (src == null || src.isEmpty())
return null;
org.hl7.fhir.r4.model.Medication.MedicationIngredientComponent tgt = new org.hl7.fhir.r4.model.Medication.MedicationIngredientComponent();
VersionConvertor_10_40.copyElement(src, tgt);
if (src.hasItem())
tgt.setItem(VersionConvertor_10_40.convertReference(src.getItem()));
if (src.hasAmount())
tgt.setStrength(VersionConvertor_10_40.convertRatio(src.getAmount()));
return tgt;
}
}

View File

@ -0,0 +1,31 @@
package org.hl7.fhir.convertors.conv10_40;
import org.hl7.fhir.convertors.VersionConvertorAdvisor40;
import org.hl7.fhir.convertors.VersionConvertor_10_40;
import org.hl7.fhir.convertors.misc.IGR2ConvertorAdvisor;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.io.InputStream;
public class Medication10_40Test {
@Test
@DisplayName("Test 10_40 Medication conversion")
public void testMedicationConversion() throws IOException {
InputStream dstu2_input = this.getClass().getResourceAsStream("/0_medication_10.json");
InputStream r4_exepected_input = this.getClass().getResourceAsStream("/0_medication_40.json");
org.hl7.fhir.dstu2.model.Medication dstu2 = (org.hl7.fhir.dstu2.model.Medication) new org.hl7.fhir.dstu2.formats.JsonParser().parse(dstu2_input);
VersionConvertorAdvisor40 advisor = new IGR2ConvertorAdvisor();
org.hl7.fhir.r4.model.Resource r4_actual = VersionConvertor_10_40.convertResource(dstu2, advisor);
org.hl7.fhir.r4.formats.JsonParser r4_parser = new org.hl7.fhir.r4.formats.JsonParser();
org.hl7.fhir.r4.model.Resource r4_expected = r4_parser.parse(r4_exepected_input);
Assertions.assertTrue(r4_expected.equalsDeep(r4_actual),
"Failed comparing\n" + r4_parser.composeString(r4_actual) + "\nand\n" + r4_parser.composeString(r4_expected));
}
}

View File

@ -0,0 +1,24 @@
{
"resourceType": "Medication",
"id": "FOBAfoba",
"code": {
"coding": [
{
"system": "http://www.nlm.nih.gov/research/umls/rxnorm",
"code": "309309",
"display": "CIPROFLOXACIN 500 MG TABLET"
}
],
"text": "CIPROFLOXACIN 500 MG TABLET"
},
"form": {
"coding": [
{
"system": "urn:oid:1.2.840.114350.1.13.331.2.7.4.698288.310",
"code": "81",
"display": "Tablet"
}
],
"text": "Tablet"
}
}

View File

@ -0,0 +1,26 @@
{
"resourceType": "Medication",
"id": "FOBAfoba",
"code": {
"coding": [
{
"system": "http://www.nlm.nih.gov/research/umls/rxnorm",
"code": "309309",
"display": "CIPROFLOXACIN 500 MG TABLET"
}
],
"text": "CIPROFLOXACIN 500 MG TABLET"
},
"product": {
"form": {
"coding": [
{
"system": "urn:oid:1.2.840.114350.1.13.331.2.7.4.698288.310",
"code": "81",
"display": "Tablet"
}
],
"text": "Tablet"
}
}
}