Allow specimen to be converted from STU3 -> STU2

This commit is contained in:
Graham, Gary 2019-01-24 16:06:08 -08:00
parent a2d0168671
commit 237a508d83
3 changed files with 149 additions and 9 deletions

View File

@ -24,33 +24,26 @@ import java.util.ArrayList;
import java.util.List;
import org.apache.commons.codec.binary.Base64;
import org.hl7.fhir.dstu3.model.*;
import org.hl7.fhir.instance.model.CodeableConcept;
import org.hl7.fhir.instance.model.Reference;
import org.hl7.fhir.instance.model.Resource;
import org.hl7.fhir.instance.utils.ToolingExtensions;
import org.hl7.fhir.dstu3.conformance.ProfileUtilities;
import org.hl7.fhir.dstu3.model.Annotation;
import org.hl7.fhir.dstu3.model.CapabilityStatement.SystemRestfulInteraction;
import org.hl7.fhir.dstu3.model.CodeSystem;
import org.hl7.fhir.dstu3.model.Coding;
import org.hl7.fhir.dstu3.model.CodeSystem.CodeSystemContentMode;
import org.hl7.fhir.dstu3.model.CodeSystem.ConceptDefinitionComponent;
import org.hl7.fhir.dstu3.model.CodeSystem.ConceptDefinitionDesignationComponent;
import org.hl7.fhir.dstu3.model.CommunicationRequest.CommunicationPriority;
import org.hl7.fhir.dstu3.model.ConceptMap;
import org.hl7.fhir.dstu3.model.ContactDetail;
import org.hl7.fhir.dstu3.model.ConceptMap.ConceptMapGroupComponent;
import org.hl7.fhir.dstu3.model.ConceptMap.SourceElementComponent;
import org.hl7.fhir.dstu3.model.DocumentReference.ReferredDocumentStatus;
import org.hl7.fhir.dstu3.model.Dosage;
import org.hl7.fhir.dstu3.model.ElementDefinition;
import org.hl7.fhir.dstu3.model.ElementDefinition.ElementDefinitionSlicingDiscriminatorComponent;
import org.hl7.fhir.dstu3.model.Enumeration;
import org.hl7.fhir.dstu3.model.Immunization.ImmunizationPractitionerComponent;
import org.hl7.fhir.dstu3.model.ReferralRequest.ReferralPriority;
import org.hl7.fhir.dstu3.model.StructureDefinition.StructureDefinitionKind;
import org.hl7.fhir.dstu3.model.StructureDefinition.TypeDerivationRule;
import org.hl7.fhir.dstu3.model.Timing.EventTiming;
import org.hl7.fhir.dstu3.model.UriType;
import org.hl7.fhir.dstu3.terminologies.CodeSystemUtilities;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.utilities.Utilities;
@ -13102,6 +13095,8 @@ public org.hl7.fhir.instance.model.ValueSet.ConceptDefinitionDesignationComponen
return convertSearchParameter((org.hl7.fhir.dstu3.model.SearchParameter) src);
if (src instanceof org.hl7.fhir.dstu3.model.Slot)
return convertSlot((org.hl7.fhir.dstu3.model.Slot) src);
if (src instanceof org.hl7.fhir.dstu3.model.Specimen)
return convertSpecimen((org.hl7.fhir.dstu3.model.Specimen) src);
if (src instanceof org.hl7.fhir.dstu3.model.StructureDefinition)
return convertStructureDefinition((org.hl7.fhir.dstu3.model.StructureDefinition) src);
if (src instanceof org.hl7.fhir.dstu3.model.Subscription)
@ -13119,4 +13114,99 @@ public org.hl7.fhir.instance.model.ValueSet.ConceptDefinitionDesignationComponen
throw new Error("Unknown resource "+src.fhirType());
}
private org.hl7.fhir.instance.model.Specimen.SpecimenStatus convertSpecimenStatus(Specimen.SpecimenStatus status) {
if (status == null) {
return null;
}
switch(status) {
case AVAILABLE: return org.hl7.fhir.instance.model.Specimen.SpecimenStatus.AVAILABLE;
case UNAVAILABLE: return org.hl7.fhir.instance.model.Specimen.SpecimenStatus.UNAVAILABLE;
case ENTEREDINERROR: return org.hl7.fhir.instance.model.Specimen.SpecimenStatus.ENTEREDINERROR;
case UNSATISFACTORY: return org.hl7.fhir.instance.model.Specimen.SpecimenStatus.UNSATISFACTORY;
case NULL: return org.hl7.fhir.instance.model.Specimen.SpecimenStatus.NULL;
default: return org.hl7.fhir.instance.model.Specimen.SpecimenStatus.NULL;
}
}
public org.hl7.fhir.instance.model.Specimen.SpecimenTreatmentComponent convertSpecimenProcessingComponent(org.hl7.fhir.dstu3.model.Specimen.SpecimenProcessingComponent src) throws FHIRException {
if (src == null)
return null;
org.hl7.fhir.instance.model.Specimen.SpecimenTreatmentComponent tgt = new org.hl7.fhir.instance.model.Specimen.SpecimenTreatmentComponent();
copyElement(src, tgt);
if (src.hasDescription())
tgt.setDescription(src.getDescription());
if (src.hasProcedure())
tgt.setProcedure(convertCodeableConcept(src.getProcedure()));
for (org.hl7.fhir.dstu3.model.Reference t : src.getAdditive())
tgt.addAdditive(convertReference(t));
return tgt;
}
public org.hl7.fhir.instance.model.Specimen.SpecimenContainerComponent convertSpecimenContainerComponent(org.hl7.fhir.dstu3.model.Specimen.SpecimenContainerComponent src) throws FHIRException {
if (src == null)
return null;
org.hl7.fhir.instance.model.Specimen.SpecimenContainerComponent tgt = new org.hl7.fhir.instance.model.Specimen.SpecimenContainerComponent();
copyElement(src, tgt);
for (org.hl7.fhir.dstu3.model.Identifier t : src.getIdentifier())
tgt.addIdentifier(convertIdentifier(t));
if (src.hasDescription())
tgt.setDescription(src.getDescription());
if (src.hasType())
tgt.setType(convertCodeableConcept(src.getType()));
if (src.hasCapacity())
tgt.setCapacity(convertSimpleQuantity(src.getCapacity()));
if (src.hasSpecimenQuantity())
tgt.setSpecimenQuantity(convertSimpleQuantity(src.getSpecimenQuantity()));
if (src.hasAdditive())
tgt.setAdditive(convertType(src.getAdditive()));
return tgt;
}
public org.hl7.fhir.instance.model.Specimen.SpecimenCollectionComponent convertSpecimenCollectionComponent(org.hl7.fhir.dstu3.model.Specimen.SpecimenCollectionComponent src) throws FHIRException {
if (src == null)
return null;
org.hl7.fhir.instance.model.Specimen.SpecimenCollectionComponent tgt = new org.hl7.fhir.instance.model.Specimen.SpecimenCollectionComponent();
copyElement(src, tgt);
if (src.hasCollector())
tgt.setCollector(convertReference(src.getCollector()));
if (src.hasCollected())
tgt.setCollected(convertType(src.getCollected()));
if (src.hasQuantity())
tgt.setQuantity(convertSimpleQuantity(src.getQuantity()));
if (src.hasMethod())
tgt.setMethod(convertCodeableConcept(src.getMethod()));
if (src.hasBodySite())
tgt.setBodySite(convertCodeableConcept(src.getBodySite()));
return tgt;
}
private org.hl7.fhir.instance.model.Specimen convertSpecimen(Specimen src) {
if (src == null) {
return null;
}
org.hl7.fhir.instance.model.Specimen tgt = new org.hl7.fhir.instance.model.Specimen();
copyDomainResource(src, tgt);
for (org.hl7.fhir.dstu3.model.Identifier t : src.getIdentifier())
tgt.addIdentifier(convertIdentifier(t));
if (src.hasAccessionIdentifier())
tgt.setAccessionIdentifier(convertIdentifier(src.getAccessionIdentifier()));
if (src.hasStatus())
tgt.setStatus(convertSpecimenStatus(src.getStatus()));
if (src.hasType())
tgt.setType(convertCodeableConcept(src.getType()));
if (src.hasSubject())
tgt.setSubject(convertReference(src.getSubject()));
if (src.hasReceivedTime())
tgt.setReceivedTime(src.getReceivedTime());
for (org.hl7.fhir.dstu3.model.Reference t : src.getParent())
tgt.addParent(convertReference(t));
if (src.hasCollection())
tgt.setCollection(convertSpecimenCollectionComponent(src.getCollection()));
for (org.hl7.fhir.dstu3.model.Specimen.SpecimenProcessingComponent t : src.getProcessing())
tgt.addTreatment(convertSpecimenProcessingComponent(t));
for (org.hl7.fhir.dstu3.model.Specimen.SpecimenContainerComponent t : src.getContainer())
tgt.addContainer(convertSpecimenContainerComponent(t));
return tgt;
}
}

View File

@ -64,6 +64,17 @@ public class VersionedApiConverterInterceptorR4Test {
}
}
@Test
public void testSearchConvertSpecimenToR2() throws Exception {
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Specimen");
httpGet.addHeader("Accept", "application/fhir+json; fhirVersion=1.0.2");
try (CloseableHttpResponse status = ourClient.execute(httpGet)) {
String responseContent = IOUtils.toString(status.getEntity().getContent(), StandardCharsets.UTF_8);
ourLog.info(responseContent);
assertThat(responseContent, containsString("\"family\": ["));
}
}
@Test
public void testSearchConvertToR2ByFormatParam() throws Exception {
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?_format=" + UrlUtil.escapeUrlParam("application/fhir+json; fhirVersion=1.0"));

View File

@ -2,9 +2,14 @@ package org.hl7.fhir.convertors;
import static org.junit.Assert.assertEquals;
import org.hl7.fhir.dstu3.model.*;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.instance.model.Resource;
import org.junit.Test;
import java.util.Collections;
import java.util.Date;
public class VersionConvertor_10_30Test {
@Test
@ -21,5 +26,39 @@ public class VersionConvertor_10_30Test {
assertEquals("Encounter/123", context);
}
@Test
public void testConvertSpecimen() throws FHIRException {
NullVersionConverterAdvisor30 advisor = new NullVersionConverterAdvisor30();
VersionConvertor_10_30 converter = new VersionConvertor_10_30(advisor);
Specimen spec = new Specimen();
CodeableConcept cc = new CodeableConcept();
Coding coding = new Coding();
coding.setSystem("test_system");
coding.setCode("test_code");
coding.setDisplay("test_display");
cc.addCoding(coding);
spec.setType(cc);
spec.setId("76c1143a-974a-4dfe-8f1a-4292b02d323d");
spec.setReceivedTime(new Date());
spec.addExtension().setUrl("testurl!").setValue(new StringType("Yup its an extension"));
spec.setSubject(new Reference("Patient/123"));
spec.getRequest().add(new Reference("Practitioner/321"));
Specimen.SpecimenCollectionComponent specimenCollectionComponent = new Specimen.SpecimenCollectionComponent();
specimenCollectionComponent.setCollected(new DateTimeType(new Date()));
SimpleQuantity simpleQuantity = new SimpleQuantity();
simpleQuantity.setUnit("buckets");
simpleQuantity.setValue(1000L);
specimenCollectionComponent.setQuantity(simpleQuantity);
spec.setCollection(specimenCollectionComponent);
Specimen.SpecimenContainerComponent specimenContainerComponent = new Specimen.SpecimenContainerComponent();
specimenContainerComponent.getExtension().add(new Extension().setUrl("some_url").setValue(new StringType("some_value")));
spec.setContainer(Collections.singletonList(specimenContainerComponent));
Resource resource = converter.convertResource(spec);
}
}