Skip to content

Commit

Permalink
Adds REST interface tests for FHIR CarePlan.
Browse files Browse the repository at this point in the history
  • Loading branch information
volsch committed Aug 18, 2019
1 parent 80712f4 commit c19cb73
Show file tree
Hide file tree
Showing 11 changed files with 424 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,15 @@ protected void expectProgramStageMetadataRequests() throws Exception
systemDhis2Server.expect( ExpectedCount.between( 0, 1 ), method( HttpMethod.GET ) ).andExpect( header( "Authorization", testConfiguration.getDhis2SystemAuthorization() ) )
.andExpect( requestTo( dhis2BaseUrl + "/api/" + dhis2ApiVersion + "/programs/EPDyQuoRnXk.json?" +
"fields=id,name,code,description,lastUpdated,selectIncidentDatesInFuture,selectEnrollmentDatesInFuture,displayIncidentDate,registration,withoutRegistration,captureCoordinates,trackedEntityType%5Bid%5D,programTrackedEntityAttributes%5Bid," +
"name,valueType," +
"mandatory,allowFutureDate,trackedEntityAttribute%5Bid,name,code,valueType,generated%5D%5D,programStages%5Bid,program%5Bid%5D,lastUpdated,name,description,repeatable,captureCoordinates,generatedByEnrollmentDate,minDaysFromStart," +
"programStageDataElements%5Bid,compulsory," +
"allowProvidedElsewhere,dataElement%5Bid,name,code,formName,valueType,optionSetValue,optionSet%5Bid,name,options%5Bcode,name%5D%5D%5D%5D%5D" ) )
"name,valueType,mandatory,allowFutureDate,trackedEntityAttribute%5Bid,name,code,valueType,generated%5D%5D,programStages%5Bid,program%5Bid%5D,lastUpdated,name,description,repeatable,captureCoordinates,generatedByEnrollmentDate," +
"minDaysFromStart," +
"programStageDataElements%5Bid,compulsory,allowProvidedElsewhere,dataElement%5Bid,name,code,formName,valueType,optionSetValue,optionSet%5Bid,name,options%5Bcode,name%5D%5D%5D%5D%5D" ) )
.andRespond( withSuccess( IOUtils.resourceToString( "/org/dhis2/fhir/adapter/dhis/test/single-program.json", StandardCharsets.UTF_8 ), MediaType.APPLICATION_JSON ) );
systemDhis2Server.expect( ExpectedCount.between( 0, 1 ), method( HttpMethod.GET ) ).andExpect( header( "Authorization", testConfiguration.getDhis2SystemAuthorization() ) )
.andExpect( requestTo( dhis2BaseUrl + "/api/" + dhis2ApiVersion + "/programs.json?paging=false&fields=id,name,code,description,lastUpdated,selectIncidentDatesInFuture,selectEnrollmentDatesInFuture,displayIncidentDate,registration," +
"withoutRegistration,captureCoordinates,trackedEntityType%5Bid%5D,programTrackedEntityAttributes%5Bid,name,valueType,mandatory,allowFutureDate,trackedEntityAttribute%5Bid,name,code,valueType,generated%5D%5D,programStages%5Bid," +
"program%5Bid%5D,lastUpdated,name," +
"description,repeatable,captureCoordinates,generatedByEnrollmentDate,minDaysFromStart,programStageDataElements%5Bid,compulsory,allowProvidedElsewhere,dataElement%5Bid,name,code,formName,valueType,optionSetValue,optionSet%5Bid,name," +
"options%5Bcode,name%5D%5D%5D%5D%5D&filter=name:eq:Child%20Programme" ) )
"program%5Bid%5D,lastUpdated,name,description,repeatable,captureCoordinates,generatedByEnrollmentDate,minDaysFromStart,programStageDataElements%5Bid,compulsory,allowProvidedElsewhere,dataElement%5Bid,name,code,formName,valueType," +
"optionSetValue,optionSet%5Bid,name,options%5Bcode,name%5D%5D%5D%5D%5D&filter=name:eq:Child%20Programme" ) )
.andRespond( withSuccess( IOUtils.resourceToString( "/org/dhis2/fhir/adapter/dhis/test/default-program.json", StandardCharsets.UTF_8 ), MediaType.APPLICATION_JSON ) );
}
}

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion app/src/test/resources/data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2455,7 +2455,7 @@ VALUES ('41d3bd48578847618274f8327f15fcbe', 0, 'Subject TEI Lookup', 'SUBJECT_TE
INSERT INTO fhir_script_variable (script_id, variable) VALUES ('41d3bd48578847618274f8327f15fcbe', 'CONTEXT');
INSERT INTO fhir_script_variable (script_id, variable) VALUES ('41d3bd48578847618274f8327f15fcbe', 'INPUT');
INSERT INTO fhir_script_source (id,version,script_id,source_text,source_type)
VALUES ('67249e7b4ba7466ca770a78923fbf1c3', 0, '41d3bd48578847618274f8327f15fcbe', 'referenceUtils.getResource(input.subject, ''PATIENT'')', 'JAVASCRIPT');
VALUES ('67249e7b4ba7466ca770a78923fbf1c3', 0, '41d3bd48578847618274f8327f15fcbe', 'fhirResourceUtils.getIdentifiedResource(input.subject, ''Patient'')', 'JAVASCRIPT');
INSERT INTO fhir_script_source_version (script_source_id,fhir_version)
VALUES ('67249e7b4ba7466ca770a78923fbf1c3', 'DSTU3');
INSERT INTO fhir_script_source_version (script_source_id,fhir_version)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,6 @@ protected void initSearchFilter( @Nonnull FhirVersion fhirVersion, @Nonnull Rule
searchFilter.addReference( CarePlan.SP_INSTANTIATES_URI, FhirResourceType.PLAN_DEFINITION, DhisResourceType.PROGRAM_METADATA, "program" );
searchFilter.addReference( CarePlan.SP_PATIENT, FhirResourceType.PATIENT, DhisResourceType.TRACKED_ENTITY, "trackedEntityInstance" );
searchFilter.addReference( CarePlan.SP_SUBJECT, null, DhisResourceType.TRACKED_ENTITY, "trackedEntityInstance" );
searchFilter.addReference( LocationExtensionUtils.LOCATION_SEARCH_PARAM, DhisResourceType.ORGANIZATION_UNIT, FhirResourceType.LOCATION, "ou" );
searchFilter.addReference( LocationExtensionUtils.LOCATION_SEARCH_PARAM, FhirResourceType.LOCATION, DhisResourceType.ORGANIZATION_UNIT, "ou" );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,19 @@ protected static void setDateValue( @Nonnull String url, @Nonnull IBaseHasExtens
}
}

@Nullable
protected static IBaseReference getReferenceValue( @Nonnull String url, @Nonnull IBaseHasExtensions resource )
{
final IBaseDatatype value = getValue( url, resource );

if ( value instanceof IBaseReference )
{
return (IBaseReference) value;
}

return null;
}

protected static void setReferenceValue( @Nonnull String url, @Nonnull IBaseHasExtensions resource, @Nullable IBaseReference value )
{
resource.getExtension().removeIf( e -> url.equals( e.getUrl() ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ public static void setValue( @Nonnull IBaseHasExtensions resource, @Nullable IBa
BaseExtensionUtils.setReferenceValue( URL, resource, locationReference );
}

@Nullable
public static IBaseReference getValue( @Nonnull IBaseHasExtensions resource )
{
return BaseExtensionUtils.getReferenceValue( URL, resource );
}

private LocationExtensionUtils()
{
super();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public Collection<RuleInfo<ProgramStageRule>> findAllExp( @Nonnull Collection<Re
.setParameter( "programReferences", programReferences )
.setParameter( "dataReferences", dataReferences ).getResultList() );
}

return rules.stream().map( r -> {
Hibernate.initialize( r.getDhisDataReferences() );
return new RuleInfo<>( r, r.getDhisDataReferences() );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
import org.dhis2.fhir.adapter.fhir.metadata.model.EnrollmentRule;
import org.dhis2.fhir.adapter.fhir.metadata.model.RuleInfo;
import org.dhis2.fhir.adapter.fhir.metadata.repository.FhirClientRepository;
import org.dhis2.fhir.adapter.fhir.metadata.repository.ProgramStageRuleRepository;
import org.dhis2.fhir.adapter.fhir.metadata.repository.RuleRepository;
import org.dhis2.fhir.adapter.fhir.script.ScriptExecutionContext;
import org.dhis2.fhir.adapter.fhir.transform.TransformerDataException;
import org.dhis2.fhir.adapter.fhir.transform.dhis.impl.AbstractDhisToFhirRequestResolver;
Expand All @@ -53,7 +53,6 @@
import org.dhis2.fhir.adapter.fhir.transform.scripted.ImmutableScriptedEnrollment;
import org.dhis2.fhir.adapter.fhir.transform.scripted.ImmutableScriptedTrackedEntityInstance;
import org.dhis2.fhir.adapter.fhir.transform.scripted.ScriptedDhisResource;
import org.dhis2.fhir.adapter.fhir.transform.scripted.ScriptedEvent;
import org.dhis2.fhir.adapter.fhir.transform.scripted.ScriptedTrackedEntityInstance;
import org.dhis2.fhir.adapter.fhir.transform.scripted.WritableScriptedEnrollment;
import org.dhis2.fhir.adapter.fhir.transform.scripted.WritableScriptedTrackedEntityInstance;
Expand All @@ -73,7 +72,7 @@ public class EnrollmentToFhirRequestResolver extends AbstractDhisToFhirRequestRe
{
private final ProgramMetadataService programMetadataService;

private final ProgramStageRuleRepository ruleRepository;
private final RuleRepository ruleRepository;

private final TrackedEntityService trackedEntityService;

Expand All @@ -86,7 +85,7 @@ public class EnrollmentToFhirRequestResolver extends AbstractDhisToFhirRequestRe
public EnrollmentToFhirRequestResolver(
@Nonnull FhirClientRepository fhirClientRepository,
@Nonnull ProgramMetadataService programMetadataService,
@Nonnull ProgramStageRuleRepository ruleRepository,
@Nonnull RuleRepository ruleRepository,
@Nonnull TrackedEntityService trackedEntityService,
@Nonnull TrackedEntityMetadataService trackedEntityMetadataService,
@Nonnull ScriptExecutionContext scriptExecutionContext,
Expand All @@ -113,8 +112,7 @@ public DhisResourceType getDhisResourceType()
@Override
public List<RuleInfo<? extends AbstractRule>> resolveRules( @Nonnull ScriptedDhisResource dhisResource )
{
final ScriptedEvent event = (ScriptedEvent) dhisResource;
return ruleRepository.findAllExp( event.getProgram().getAllReferences(), event.getProgramStage().getAllReferences(), null )
return ruleRepository.findAllExp( DhisResourceType.ENROLLMENT )
.stream().sorted().collect( Collectors.toList() );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ public DhisResourceType getDhisResourceType()
public List<RuleInfo<? extends AbstractRule>> resolveRules( @Nonnull ScriptedDhisResource dhisResource )
{
final ScriptedEvent event = (ScriptedEvent) dhisResource;

return ruleRepository.findAllExp( event.getProgram().getAllReferences(), event.getProgramStage().getAllReferences(), null )
.stream().sorted().collect( Collectors.toList() );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,15 @@ public void setReferenceValue()
Assert.assertEquals( "testUrl", planDefinition.getExtension().get( 0 ).getUrl() );
Assert.assertSame( reference, planDefinition.getExtension().get( 0 ).getValue() );
}

@Test
public void getReferenceValue()
{
TestPlanDefinition planDefinition = new TestPlanDefinition();

final IBaseReference reference = new TestReference();

BaseExtensionUtils.setReferenceValue( "testUrl", planDefinition, reference );
Assert.assertSame( reference, BaseExtensionUtils.getReferenceValue( "testUrl", planDefinition ) );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

import org.hl7.fhir.instance.model.api.IBaseReference;
import org.junit.Assert;
import org.junit.Test;

Expand Down Expand Up @@ -62,4 +63,15 @@ public void setValue()
Assert.assertEquals( LocationExtensionUtils.URL, planDefinition.getExtension().get( 0 ).getUrl() );
Assert.assertEquals( reference, planDefinition.getExtension().get( 0 ).getValue() );
}

@Test
public void getValue()
{
TestPlanDefinition planDefinition = new TestPlanDefinition();

final IBaseReference reference = new TestReference();

LocationExtensionUtils.setValue( planDefinition, reference );
Assert.assertSame( reference, LocationExtensionUtils.getValue( planDefinition ) );
}
}

0 comments on commit c19cb73

Please sign in to comment.