Skip to content

Commit

Permalink
Changes to fix issues of missing extensions and others (#1050)
Browse files Browse the repository at this point in the history
* Changes to fix issues of missing extensions and others

* Resolving parquet-tools memory error

* Addressing review comments

* Addressing review comments

* Increasing the sleep time during e2e tests before triggering incremental runs
  • Loading branch information
chandrashekar-s authored May 16, 2024
1 parent 498d7c1 commit 5dd428c
Show file tree
Hide file tree
Showing 21 changed files with 7,135 additions and 245 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public Schema getDataType() {
// FHIR (Double and BigDecimal are not assignable to each other hence explicit conversions).
// Note with this approach we are loosing some precision!
private static final HapiConverter<Schema> DOUBLE_CONVERTER =
new PrimitiveConverter<Schema>("Double") {
new PrimitiveConverter<Schema>("Decimal") {
@Override
public void toHapi(Object input, IPrimitiveType primitive) {
Preconditions.checkArgument((input instanceof BigDecimal) || (input instanceof Double));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.hl7.fhir.r4.model.Patient;
import org.hl7.fhir.r4.model.Provenance;
import org.hl7.fhir.r4.model.Quantity;
import org.hl7.fhir.r4.model.QuestionnaireResponse;
import org.hl7.fhir.r4.model.Task;
import org.junit.Assert;
import org.junit.BeforeClass;
Expand Down Expand Up @@ -101,6 +102,13 @@ public class R4AvroConverterUsCoreTest {

private static Encounter testEncounterDecoded;

private static QuestionnaireResponse testQuestionnaireResponse =
TestData.newQuestionnaireResponse();

private static Record avroQuestionnaireResponse;

private static QuestionnaireResponse testQuestionnaireResponseDecoded;

private static FhirContext fhirContext;

/** Initialize test data. */
Expand Down Expand Up @@ -175,6 +183,15 @@ public static void convertTestData() throws ProfileException {
AvroConverter.forResources(fhirContext, R4UsCoreProfileData.US_CORE_ENCOUNTER_PROFILES, 1);
avroEncounter = (Record) encounterConverter.resourceToAvro(testEncounter);
testEncounterDecoded = (Encounter) encounterConverter.avroToResource(avroEncounter);

AvroConverter questionnaireResponseConverter =
AvroConverter.forResources(
fhirContext, R4UsCoreProfileData.US_CORE_QUESTIONNAIRE_RESPONSE_PROFILES, 1);
avroQuestionnaireResponse =
(Record) questionnaireResponseConverter.resourceToAvro(testQuestionnaireResponse);
testQuestionnaireResponseDecoded =
(QuestionnaireResponse)
questionnaireResponseConverter.avroToResource(avroQuestionnaireResponse);
}

@Test
Expand Down Expand Up @@ -588,4 +605,9 @@ public void testEncounterConversions() {
Assert.assertEquals(
testEncounter.getParticipant().size(), testEncounterDecoded.getParticipant().size());
}

@Test
public void setTestQuestionnaireResponseConversions() {
Assert.assertTrue(testQuestionnaireResponse.equalsDeep(testQuestionnaireResponseDecoded));
}
}

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
import javax.annotation.Nonnull;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.r4.model.CanonicalType;
import org.hl7.fhir.r4.model.ElementDefinition;
import org.hl7.fhir.r4.model.StructureDefinition;
Expand Down Expand Up @@ -37,9 +39,16 @@ public FhirConversionSupport conversionSupport() {
}

@Override
protected IStructureDefinition getStructureDefinition(String resourceUrl) {
return new StructureDefinitionWrapper(
(StructureDefinition) context.getValidationSupport().fetchStructureDefinition(resourceUrl));
@Nonnull
protected IStructureDefinition getStructureDefinition(String resourceUrl)
throws IllegalArgumentException {
IBaseResource baseResource =
context.getValidationSupport().fetchStructureDefinition(resourceUrl);
if (baseResource == null) {
throw new IllegalArgumentException(
String.format("Unable to find definition for %s", resourceUrl));
}
return new StructureDefinitionWrapper((StructureDefinition) baseResource);
}

// FHIR version specific interface implementations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
import org.hl7.fhir.r4.model.Period;
import org.hl7.fhir.r4.model.Provenance;
import org.hl7.fhir.r4.model.Quantity;
import org.hl7.fhir.r4.model.QuestionnaireResponse;
import org.hl7.fhir.r4.model.QuestionnaireResponse.QuestionnaireResponseItemAnswerComponent;
import org.hl7.fhir.r4.model.QuestionnaireResponse.QuestionnaireResponseItemComponent;
import org.hl7.fhir.r4.model.QuestionnaireResponse.QuestionnaireResponseStatus;
import org.hl7.fhir.r4.model.Reference;
import org.hl7.fhir.r4.model.StringType;
import org.hl7.fhir.r4.model.Task;
Expand Down Expand Up @@ -438,6 +442,26 @@ public static Provenance newProvenance() {
return provenance;
}

/**
* Returns a new QuestionnaireResponse for testing.
*
* @return a FHIR QuestionnaireResponse for testing.
*/
public static QuestionnaireResponse newQuestionnaireResponse() {
QuestionnaireResponse response = new QuestionnaireResponse();
response.setId("test-questionnaire-response-id");
response.setStatus(QuestionnaireResponseStatus.COMPLETED);
response.setSubject(new Reference("Patient/12345").setDisplay("Here is a display for you."));
QuestionnaireResponseItemComponent component = new QuestionnaireResponseItemComponent();
component.setText("What is your Gender?");
QuestionnaireResponseItemAnswerComponent answerComponent =
new QuestionnaireResponseItemAnswerComponent();
answerComponent.setValue(new StringType("Male"));
component.addAnswer(answerComponent);
response.addItem(component);
return response;
}

/**
* Returns a new Patient from Bunsen Test profile for testing.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
import com.cerner.bunsen.definitions.StructureDefinitions;
import java.util.List;
import java.util.stream.Collectors;
import javax.annotation.Nonnull;
import org.hl7.fhir.dstu3.model.ElementDefinition;
import org.hl7.fhir.dstu3.model.StructureDefinition;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -31,9 +33,16 @@ public FhirConversionSupport conversionSupport() {
}

@Override
protected IStructureDefinition getStructureDefinition(String resourceUrl) {
return new StructureDefinitionWrapper(
(StructureDefinition) context.getValidationSupport().fetchStructureDefinition(resourceUrl));
@Nonnull
protected IStructureDefinition getStructureDefinition(String resourceUrl)
throws IllegalArgumentException {
IBaseResource baseResource =
context.getValidationSupport().fetchStructureDefinition(resourceUrl);
if (baseResource == null) {
throw new IllegalArgumentException(
String.format("Unable to find definition for %s", resourceUrl));
}
return new StructureDefinitionWrapper((StructureDefinition) baseResource);
}

// FHIR version specific interface implementations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public String extensionUrl() {

/**
* The FHIR type of the element to be converted, or null if there is no FHIR type, such as within
* a FHIR backbone element.
* a FHIR backbone element. The return value should be a valid FHIR type.
*
* @return FHIR type of the element to be converted.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;

/** Abstract base class to visit FHIR structure definitions. */
Expand Down Expand Up @@ -494,24 +495,9 @@ public <T> T transform(

IStructureDefinition definition = getStructureDefinition(resourceTypeUrl);

if (definition == null) {
throw new IllegalArgumentException("Unable to find definition for " + resourceTypeUrl);
}

List<IStructureDefinition> containedDefinitions =
containedResourceTypeUrls.stream()
.map(
containedResourceTypeUrl -> {
IStructureDefinition containedDefinition =
getStructureDefinition(containedResourceTypeUrl);

if (containedDefinition == null) {
throw new IllegalArgumentException(
"Unable to find definition for " + containedResourceTypeUrl);
}

return containedDefinition;
})
.map(containedResourceTypeUrl -> getStructureDefinition(containedResourceTypeUrl))
.collect(Collectors.toList());

return transformRoot(visitor, definition, containedDefinitions);
Expand Down Expand Up @@ -550,7 +536,11 @@ private <T> T transform(
// Retrieve only the unique reference types
.distinct()
.collect(Collectors.toList());
return visitor.visitReference(parentElement.toString(), referenceTypes, childElements);

String elementName = DefinitionVisitorsUtil.elementName(parentElement.getPath());
String elementFullPath = DefinitionVisitorsUtil.pathFromStack(elementName, stack);
return visitor.visitReference(
DefinitionVisitorsUtil.recordNameFor(elementFullPath), referenceTypes, childElements);
} else {
String rootName = DefinitionVisitorsUtil.elementName(root.getPath());

Expand Down Expand Up @@ -600,12 +590,16 @@ private <T> T transformRoot(
}

/**
* Returns the structure definition interface corresponding to the given URL.
* Returns the structure definition interface corresponding to the given resourceUrl.
*
* @param resourceUrl it can be a resource type like `Patient` or a profile URL.
* @return the {@link IStructureDefinition} corresponding to the `resourceUrl`.
* @return the {@link IStructureDefinition} corresponding to the `resourceUrl`
* @throws IllegalArgumentException if the structure definition cannot be found for the given
* resourceUrl.
*/
protected abstract IStructureDefinition getStructureDefinition(String resourceUrl);
@Nonnull
protected abstract IStructureDefinition getStructureDefinition(String resourceUrl)
throws IllegalArgumentException;

/**
* Returns the structure definition interface corresponding to the given element.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,9 @@ public class R4UsCoreProfileData {
Arrays.asList(
"http://hl7.org/fhir/StructureDefinition/Medication",
"http://hl7.org/fhir/us/core/StructureDefinition/us-core-medication");

public static final List<String> US_CORE_QUESTIONNAIRE_RESPONSE_PROFILES =
Arrays.asList(
"http://hl7.org/fhir/StructureDefinition/QuestionnaireResponse",
"http://hl7.org/fhir/us/core/StructureDefinition/us-core-questionnaireresponse");
}
Loading

0 comments on commit 5dd428c

Please sign in to comment.