Skip to content

Commit

Permalink
Adds REST interface tests for FHIR QuestionnaireResponse.
Browse files Browse the repository at this point in the history
  • Loading branch information
volsch committed Aug 18, 2019
1 parent c19cb73 commit fcb9625
Show file tree
Hide file tree
Showing 15 changed files with 494 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,10 @@ protected void expectProgramStageMetadataRequests() throws Exception
"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 ) );
systemDhis2Server.expect( ExpectedCount.between( 0, 1 ), method( HttpMethod.GET ) ).andExpect( header( "Authorization", testConfiguration.getDhis2SystemAuthorization() ) )
.andExpect( requestTo( dhis2BaseUrl + "/api/" + dhis2ApiVersion + "/programStages/MsWxkiY6tMS.json?fields=id,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" ) )
.andRespond( withSuccess( IOUtils.resourceToString( "/org/dhis2/fhir/adapter/dhis/test/single-program-stage.json", StandardCharsets.UTF_8 ), MediaType.APPLICATION_JSON ) );

}
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"events": [
{
"event": "deR4kl4mnf7",
"status": "ACTIVE",
"eventDate": "2018-11-10T00:00:00+01:00",
"dueDate": "2018-11-12T00:00:00+01:00",
"coordinate": null,
"dataValues": [
{
"value": "3666",
"providedElsewhere": false,
"dataElement": "BnplxU2jGvX"
},
{
"value": "1",
"providedElsewhere": false,
"dataElement": "ft7iD5ZzPxJ"
}
],
"orgUnit": "ldXIdLNUNEn",
"program": "EPDyQuoRnXk",
"trackedEntityInstance": "JeR2Ul4mZfx",
"programStage": "MsWxkiY6tMS"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"status": "OK",
"response": {
"importSummaries": [
{
"status": "SUCCESS",
"reference": "deR4kl4mnf7"
}
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"status": "OVERDUE",
"eventDate": "2018-11-10T00:00:00+01:00",
"dueDate": "2018-11-14T00:00:00+01:00",
"coordinate": null,
"dataValues": [
{
"value": "3666",
"providedElsewhere": false,
"dataElement": "BnplxU2jGvX"
},
{
"value": "1",
"providedElsewhere": false,
"dataElement": "ft7iD5ZzPxJ"
}
],
"orgUnit": "ldXIdLNUNEn",
"program": "EPDyQuoRnXk",
"trackedEntityInstance": "JeR2Ul4mZfx",
"programStage": "MsWxkiY6tMS"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"event": "deR4kl4mnf7",
"status": "ACTIVE",
"eventDate": "2018-11-10T00:00:00+01:00",
"dueDate": "2018-11-12T00:00:00+01:00",
"coordinate": null,
"dataValues": [
{
"value": "3666",
"providedElsewhere": false,
"dataElement": "BnplxU2jGvX"
},
{
"value": "1",
"providedElsewhere": false,
"dataElement": "ft7iD5ZzPxJ"
}
],
"orgUnit": "ldXIdLNUNEn",
"program": "EPDyQuoRnXk",
"trackedEntityInstance": "JeR2Ul4mZfx",
"programStage": "MsWxkiY6tMS"
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@
query = "SELECT psr FROM ProgramStageRule psr " +
"LEFT JOIN psr.programStage ps ON (ps.enabled=true AND ps.expEnabled=true AND (ps.fhirCreateEnabled=true OR ps.fhirUpdateEnabled=true) AND ps.programStageReference IN (:programStageReferences)) " +
"LEFT JOIN ps.program p ON (p.enabled=true AND p.expEnabled=true AND (p.fhirCreateEnabled=true OR p.fhirUpdateEnabled=true) AND p.programReference IN (:programReferences)) WHERE " +
"psr.enabled=true AND psr.expEnabled=true AND (psr.fhirCreateEnabled=true OR psr.fhirUpdateEnabled=true) AND psr.transformExpScript IS NOT NULL" ),
"psr.enabled=true AND psr.expEnabled=true AND (psr.fhirCreateEnabled=true OR psr.fhirUpdateEnabled=true)" ),
@NamedQuery( name = ProgramStageRule.FIND_ALL_EXP_BY_DATA_REF_NAMED_QUERY,
query = "SELECT psr FROM ProgramStageRule psr " +
"LEFT JOIN psr.programStage ps ON (ps.enabled=true AND ps.expEnabled=true AND (ps.fhirCreateEnabled=true OR ps.fhirUpdateEnabled=true) AND ps.programStageReference IN (:programStageReferences)) " +
"LEFT JOIN ps.program p ON (p.enabled=true AND p.expEnabled=true AND (p.fhirCreateEnabled=true OR p.fhirUpdateEnabled=true) AND p.programReference IN (:programReferences)) WHERE " +
"psr.enabled=true AND psr.expEnabled=true AND (psr.fhirCreateEnabled=true OR psr.fhirUpdateEnabled=true) AND psr.transformExpScript IS NOT NULL AND " +
"psr.enabled=true AND psr.expEnabled=true AND (psr.fhirCreateEnabled=true OR psr.fhirUpdateEnabled=true) AND " +
"EXISTS (SELECT 1 FROM RuleDhisDataReference edr WHERE edr.rule=psr AND edr.dataReference IN (:dataReferences))" )
} )
@Relation( value = "rule", collectionRelation = "rules" )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,4 @@ public interface CustomRuleRepository
@RestResource( exported = false )
@Nonnull
Collection<RuleInfo<? extends AbstractRule>> findAllExp( @Nonnull DhisResourceType dhisResourceType );

}
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,25 @@ public Collection<RuleInfo<? extends AbstractRule>> findAllExp( @Nonnull DhisRes

return rules.stream().map( r -> {
Hibernate.initialize( r.getDhisDataReferences() );

return new RuleInfo<>( r, r.getDhisDataReferences() );
} ).collect( Collectors.toList() );
}

@RestResource( exported = false )
@Nonnull
@Cacheable( key = "{#root.methodName, #a0, #a1}", cacheManager = "metadataCacheManager", cacheNames = "rule" )
@Transactional( readOnly = true )
public Collection<RuleInfo<? extends AbstractRule>> findAllExp( @Nonnull DhisResourceType dhisResourceType, @Nonnull FhirResourceType fhirResourceType )
{
final List<AbstractRule> rules = entityManager.createQuery( "SELECT r FROM " + dhisResourceType.getRuleType() +
" r WHERE r.enabled=true AND r.expEnabled=true AND r.fhirResourceType=:fhirResourceType AND " +
"(r.fhirCreateEnabled=true OR r.fhirUpdateEnabled=true)", AbstractRule.class )
.setParameter( "fhirResourceType", fhirResourceType ).getResultList();

return rules.stream().map( r -> {
Hibernate.initialize( r.getDhisDataReferences() );

return new RuleInfo<>( r, r.getDhisDataReferences() );
} ).collect( Collectors.toList() );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public interface DhisToFhirRequestResolver
List<RuleInfo<? extends AbstractRule>> resolveRules( @Nonnull ScriptedDhisResource dhisResource );

@Nonnull
List<RuleInfo<? extends AbstractRule>> resolveRules( @Nonnull ScriptedDhisResource dhisResource, @Nonnull List<RuleInfo<? extends AbstractRule>> rules );
List<RuleInfo<? extends AbstractRule>> filterRules( @Nonnull ScriptedDhisResource dhisResource, @Nonnull List<RuleInfo<? extends AbstractRule>> rules );

@Nonnull
Optional<FhirClient> resolveFhirClient( @Nonnull ScriptedDhisResource scriptedDhisResource );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,8 @@ public DhisToFhirTransformerRequest createTransformerRequest( @Nonnull FhirClien
{
final DhisToFhirRequestResolver requestResolver = getRequestResolver( dhisRequest.getResourceType() );

return createTransformerRequest( dhisRequest, rr -> rr.convert( resource, dhisRequest ), requestResolver, ( rr, scriptedResource ) -> rr.resolveRules( scriptedResource, rules ),
ri -> true, ( si, rr ) -> fhirClient );
return createTransformerRequest( dhisRequest, rr -> rr.convert( resource, dhisRequest ), requestResolver,
( rr, scriptedResource ) -> rr.filterRules( scriptedResource, rules ), ri -> true, ( si, rr ) -> fhirClient );
}

@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public List<RuleInfo<? extends AbstractRule>> resolveRules( @Nonnull ScriptedDhi

@Nonnull
@Override
public List<RuleInfo<? extends AbstractRule>> resolveRules( @Nonnull ScriptedDhisResource dhisResource, @Nonnull List<RuleInfo<? extends AbstractRule>> rules )
public List<RuleInfo<? extends AbstractRule>> filterRules( @Nonnull ScriptedDhisResource dhisResource, @Nonnull List<RuleInfo<? extends AbstractRule>> rules )
{
return rules.stream().map( ri -> new RuleInfo<>( (EnrollmentRule) ri.getRule(), ri.getDhisDataReferences() ) )
.sorted().collect( Collectors.toList() );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,13 @@ protected AbstractDhisMetadataToFhirRequestResolver( @Nonnull FhirClientReposito
@Override
public List<RuleInfo<? extends AbstractRule>> resolveRules( @Nonnull ScriptedDhisResource dhisResource )
{
return ruleRepository.findAllExp( dhisResource.getResourceType() ).stream().sorted().collect( Collectors.toList() );
return ruleRepository.findAllExp( dhisResource.getResourceType() ).stream()
.sorted().collect( Collectors.toList() );
}

@Nonnull
@Override
public List<RuleInfo<? extends AbstractRule>> resolveRules( @Nonnull ScriptedDhisResource dhisResource, @Nonnull List<RuleInfo<? extends AbstractRule>> rules )
public List<RuleInfo<? extends AbstractRule>> filterRules( @Nonnull ScriptedDhisResource dhisResource, @Nonnull List<RuleInfo<? extends AbstractRule>> rules )
{
return rules.stream().sorted().collect( Collectors.toList() );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public class ProgramStageToFhirRequestResolver extends AbstractDhisToFhirRequest
{
private final ProgramMetadataService programMetadataService;

private final ProgramStageRuleRepository ruleRepository;
private final ProgramStageRuleRepository programStageRuleRepository;

private final TrackedEntityService trackedEntityService;

Expand All @@ -87,7 +87,7 @@ public class ProgramStageToFhirRequestResolver extends AbstractDhisToFhirRequest
public ProgramStageToFhirRequestResolver(
@Nonnull FhirClientRepository fhirClientRepository,
@Nonnull ProgramMetadataService programMetadataService,
@Nonnull ProgramStageRuleRepository ruleRepository,
@Nonnull ProgramStageRuleRepository programStageRuleRepository,
@Nonnull TrackedEntityService trackedEntityService,
@Nonnull TrackedEntityMetadataService trackedEntityMetadataService,
@Nonnull ScriptExecutionContext scriptExecutionContext,
Expand All @@ -96,7 +96,7 @@ public ProgramStageToFhirRequestResolver(
super( fhirClientRepository );

this.programMetadataService = programMetadataService;
this.ruleRepository = ruleRepository;
this.programStageRuleRepository = programStageRuleRepository;
this.trackedEntityService = trackedEntityService;
this.trackedEntityMetadataService = trackedEntityMetadataService;
this.scriptExecutionContext = scriptExecutionContext;
Expand All @@ -116,13 +116,13 @@ public List<RuleInfo<? extends AbstractRule>> resolveRules( @Nonnull ScriptedDhi
{
final ScriptedEvent event = (ScriptedEvent) dhisResource;

return ruleRepository.findAllExp( event.getProgram().getAllReferences(), event.getProgramStage().getAllReferences(), null )
return programStageRuleRepository.findAllExp( event.getProgram().getAllReferences(), event.getProgramStage().getAllReferences(), null )
.stream().sorted().collect( Collectors.toList() );
}

@Nonnull
@Override
public List<RuleInfo<? extends AbstractRule>> resolveRules( @Nonnull ScriptedDhisResource dhisResource, @Nonnull List<RuleInfo<? extends AbstractRule>> rules )
public List<RuleInfo<? extends AbstractRule>> filterRules( @Nonnull ScriptedDhisResource dhisResource, @Nonnull List<RuleInfo<? extends AbstractRule>> rules )
{
final ScriptedEvent event = (ScriptedEvent) dhisResource;
final Program program = event.getProgram();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public List<RuleInfo<? extends AbstractRule>> resolveRules( @Nonnull ScriptedDhi

@Nonnull
@Override
public List<RuleInfo<? extends AbstractRule>> resolveRules( @Nonnull ScriptedDhisResource dhisResource, @Nonnull List<RuleInfo<? extends AbstractRule>> rules )
public List<RuleInfo<? extends AbstractRule>> filterRules( @Nonnull ScriptedDhisResource dhisResource, @Nonnull List<RuleInfo<? extends AbstractRule>> rules )
{
final ScriptedTrackedEntityInstance tei = (ScriptedTrackedEntityInstance) dhisResource;
final TrackedEntityType type = tei.getType();
Expand Down

0 comments on commit fcb9625

Please sign in to comment.