@Test public void transformInternal() { final TrackedEntityRule rule2 = new TrackedEntityRule(); rule2.setEvaluationOrder( 100 ); rule2.setFhirResourceType( FhirResourceType.PATIENT ); Mockito.doReturn( Optional.of( new WritableTrackedEntityType( "a1234567890", "Test", Collections.emptyList() ) ) ) .when( trackedEntityMetadataService ).findTypeByReference( Mockito.eq( new Reference( "a1234567890", ReferenceType.ID ) ) ); Mockito.doReturn( Collections.singletonList( rule2 ) ).when( trackedEntityRuleRepository ).findByTypeRefs( Mockito.eq( new HashSet<>( Arrays.asList( new Reference( "a1234567890", ReferenceType.ID ), new Reference( "Test", ReferenceType.NAME ) ) ) ) ); final WritableProgram program = new WritableProgram(); program.setName( "Test Program" ); program.setDescription( "Test Description" ); program.setWithoutRegistration( false ); program.setTrackedEntityTypeId( "a1234567890" ); program.setStages( new ArrayList<>() ); WritableProgramStage programStage = new WritableProgramStage(); programStage.setId( "b1234567890" ); programStage.setName( "Test Stage 1" ); programStage.setDescription( "Test Description 1" ); programStage.setRepeatable( false ); program.getStages().add( programStage ); programStage = new WritableProgramStage(); programStage.setId( "b1234567891" ); programStage.setName( "Test Stage 2" ); programStage.setDescription( "Test Description 2" ); programStage.setRepeatable( true ); program.getStages().add( programStage ); final PlanDefinition fhirPlanDefinition = new PlanDefinition(); transformer.transformInternal( fhirClient, context, new RuleInfo<>( new ProgramMetadataRule(), Collections.emptyList() ), new HashMap<>(), new WritableScriptedDhisMetadata( program, scriptExecutionContext ), fhirPlanDefinition ); Assert.assertEquals( "Test Program", fhirPlanDefinition.getTitle() ); Assert.assertEquals( "Test Description", fhirPlanDefinition.getDescription() ); Assert.assertEquals( 2, fhirPlanDefinition.getAction().size() ); Assert.assertEquals( 1, fhirPlanDefinition.getExtension().size() ); Assert.assertEquals( ResourceTypeExtensionUtils.URL, fhirPlanDefinition.getExtension().get( 0 ).getUrl() ); Assert.assertEquals( "Patient", fhirPlanDefinition.getExtension().get( 0 ).getValue().toString() ); Assert.assertEquals( "b1234567890", fhirPlanDefinition.getAction().get( 0 ).getId() ); Assert.assertEquals( "Test Stage 1", fhirPlanDefinition.getAction().get( 0 ).getTitle() ); Assert.assertEquals( "Test Description 1", fhirPlanDefinition.getAction().get( 0 ).getDescription() ); Assert.assertEquals( PlanDefinition.ActionCardinalityBehavior.SINGLE, fhirPlanDefinition.getAction().get( 0 ).getCardinalityBehavior() ); Assert.assertEquals( "Questionnaire/b1234567890", fhirPlanDefinition.getAction().get( 0 ).getDefinition().primitiveValue() ); Assert.assertEquals( "b1234567891", fhirPlanDefinition.getAction().get( 1 ).getId() ); Assert.assertEquals( "Test Stage 2", fhirPlanDefinition.getAction().get( 1 ).getTitle() ); Assert.assertEquals( "Test Description 2", fhirPlanDefinition.getAction().get( 1 ).getDescription() ); Assert.assertEquals( PlanDefinition.ActionCardinalityBehavior.MULTIPLE, fhirPlanDefinition.getAction().get( 1 ).getCardinalityBehavior() ); Assert.assertEquals( "Questionnaire/b1234567891", fhirPlanDefinition.getAction().get( 1 ).getDefinition().primitiveValue() ); }
@Override protected boolean transformInternal( @Nonnull FhirClient fhirClient, @Nonnull DhisToFhirTransformerContext context, @Nonnull RuleInfo<ProgramMetadataRule> ruleInfo, @Nonnull Map<String, Object> scriptVariables, @Nonnull AccessibleScriptedDhisMetadata input, @Nonnull IBaseResource output ) { final Program dhisProgram = (Program) input.getDhisResource(); final PlanDefinition fhirPlanDefinition = (PlanDefinition) output; if ( !addSubjectResourceType( dhisProgram, fhirPlanDefinition ) ) { return false; } fhirPlanDefinition.setUrl( dhisProgram.getId() ); fhirPlanDefinition.setName( dhisProgram.getCode() ); fhirPlanDefinition.setTitle( dhisProgram.getName() ); fhirPlanDefinition.setStatus( Enumerations.PublicationStatus.ACTIVE ); fhirPlanDefinition.setDescription( dhisProgram.getDescription() ); fhirPlanDefinition.setAction( null ); dhisProgram.getStages().forEach( dhisProgramStage -> { final PlanDefinitionActionComponent action = fhirPlanDefinition.addAction(); action.setId( dhisProgramStage.getId() ); action.setTitle( dhisProgramStage.getName() ); action.setDescription( dhisProgramStage.getDescription() ); action.setCardinalityBehavior( dhisProgramStage.isRepeatable() ? PlanDefinition.ActionCardinalityBehavior.MULTIPLE : PlanDefinition.ActionCardinalityBehavior.SINGLE ); action.setDefinition( new CanonicalType( FhirResourceType.QUESTIONNAIRE.getResourceTypeName() + "/" + dhisProgramStage.getId() ) ); } ); return true; }
R4ProgramMetadataToFhirPlanDefinitionTransformer extends AbstractProgramMetadataToFhirPlanDefinitionTransformer<PlanDefinition> { @Override protected boolean transformInternal( @Nonnull FhirClient fhirClient, @Nonnull DhisToFhirTransformerContext context, @Nonnull RuleInfo<ProgramMetadataRule> ruleInfo, @Nonnull Map<String, Object> scriptVariables, @Nonnull AccessibleScriptedDhisMetadata input, @Nonnull IBaseResource output ) { final Program dhisProgram = (Program) input.getDhisResource(); final PlanDefinition fhirPlanDefinition = (PlanDefinition) output; if ( !addSubjectResourceType( dhisProgram, fhirPlanDefinition ) ) { return false; } fhirPlanDefinition.setUrl( dhisProgram.getId() ); fhirPlanDefinition.setName( dhisProgram.getCode() ); fhirPlanDefinition.setTitle( dhisProgram.getName() ); fhirPlanDefinition.setStatus( Enumerations.PublicationStatus.ACTIVE ); fhirPlanDefinition.setDescription( dhisProgram.getDescription() ); fhirPlanDefinition.setAction( null ); dhisProgram.getStages().forEach( dhisProgramStage -> { final PlanDefinitionActionComponent action = fhirPlanDefinition.addAction(); action.setId( dhisProgramStage.getId() ); action.setTitle( dhisProgramStage.getName() ); action.setDescription( dhisProgramStage.getDescription() ); action.setCardinalityBehavior( dhisProgramStage.isRepeatable() ? PlanDefinition.ActionCardinalityBehavior.MULTIPLE : PlanDefinition.ActionCardinalityBehavior.SINGLE ); action.setDefinition( new CanonicalType( FhirResourceType.QUESTIONNAIRE.getResourceTypeName() + "/" + dhisProgramStage.getId() ) ); } ); return true; } }
R4ProgramMetadataToFhirPlanDefinitionTransformer extends AbstractProgramMetadataToFhirPlanDefinitionTransformer<PlanDefinition> { @Override protected boolean transformInternal( @Nonnull FhirClient fhirClient, @Nonnull DhisToFhirTransformerContext context, @Nonnull RuleInfo<ProgramMetadataRule> ruleInfo, @Nonnull Map<String, Object> scriptVariables, @Nonnull AccessibleScriptedDhisMetadata input, @Nonnull IBaseResource output ) { final Program dhisProgram = (Program) input.getDhisResource(); final PlanDefinition fhirPlanDefinition = (PlanDefinition) output; if ( !addSubjectResourceType( dhisProgram, fhirPlanDefinition ) ) { return false; } fhirPlanDefinition.setUrl( dhisProgram.getId() ); fhirPlanDefinition.setName( dhisProgram.getCode() ); fhirPlanDefinition.setTitle( dhisProgram.getName() ); fhirPlanDefinition.setStatus( Enumerations.PublicationStatus.ACTIVE ); fhirPlanDefinition.setDescription( dhisProgram.getDescription() ); fhirPlanDefinition.setAction( null ); dhisProgram.getStages().forEach( dhisProgramStage -> { final PlanDefinitionActionComponent action = fhirPlanDefinition.addAction(); action.setId( dhisProgramStage.getId() ); action.setTitle( dhisProgramStage.getName() ); action.setDescription( dhisProgramStage.getDescription() ); action.setCardinalityBehavior( dhisProgramStage.isRepeatable() ? PlanDefinition.ActionCardinalityBehavior.MULTIPLE : PlanDefinition.ActionCardinalityBehavior.SINGLE ); action.setDefinition( new CanonicalType( FhirResourceType.QUESTIONNAIRE.getResourceTypeName() + "/" + dhisProgramStage.getId() ) ); } ); return true; } R4ProgramMetadataToFhirPlanDefinitionTransformer( @Nonnull ScriptExecutor scriptExecutor, @Nonnull LockManager lockManager, @Nonnull SystemRepository systemRepository, @Nonnull FhirResourceRepository fhirResourceRepository,
        @Nonnull FhirDhisAssignmentRepository fhirDhisAssignmentRepository, @Nonnull OrganizationUnitService organizationUnitService,
        @Nonnull TrackedEntityMetadataService trackedEntityMetadataService, @Nonnull TrackedEntityRuleRepository trackedEntityRuleRepository ); }
R4ProgramMetadataToFhirPlanDefinitionTransformer extends AbstractProgramMetadataToFhirPlanDefinitionTransformer<PlanDefinition> { @Override protected boolean transformInternal( @Nonnull FhirClient fhirClient, @Nonnull DhisToFhirTransformerContext context, @Nonnull RuleInfo<ProgramMetadataRule> ruleInfo, @Nonnull Map<String, Object> scriptVariables, @Nonnull AccessibleScriptedDhisMetadata input, @Nonnull IBaseResource output ) { final Program dhisProgram = (Program) input.getDhisResource(); final PlanDefinition fhirPlanDefinition = (PlanDefinition) output; if ( !addSubjectResourceType( dhisProgram, fhirPlanDefinition ) ) { return false; } fhirPlanDefinition.setUrl( dhisProgram.getId() ); fhirPlanDefinition.setName( dhisProgram.getCode() ); fhirPlanDefinition.setTitle( dhisProgram.getName() ); fhirPlanDefinition.setStatus( Enumerations.PublicationStatus.ACTIVE ); fhirPlanDefinition.setDescription( dhisProgram.getDescription() ); fhirPlanDefinition.setAction( null ); dhisProgram.getStages().forEach( dhisProgramStage -> { final PlanDefinitionActionComponent action = fhirPlanDefinition.addAction(); action.setId( dhisProgramStage.getId() ); action.setTitle( dhisProgramStage.getName() ); action.setDescription( dhisProgramStage.getDescription() ); action.setCardinalityBehavior( dhisProgramStage.isRepeatable() ? PlanDefinition.ActionCardinalityBehavior.MULTIPLE : PlanDefinition.ActionCardinalityBehavior.SINGLE ); action.setDefinition( new CanonicalType( FhirResourceType.QUESTIONNAIRE.getResourceTypeName() + "/" + dhisProgramStage.getId() ) ); } ); return true; } R4ProgramMetadataToFhirPlanDefinitionTransformer( @Nonnull ScriptExecutor scriptExecutor, @Nonnull LockManager lockManager, @Nonnull SystemRepository systemRepository, @Nonnull FhirResourceRepository fhirResourceRepository,
        @Nonnull FhirDhisAssignmentRepository fhirDhisAssignmentRepository, @Nonnull OrganizationUnitService organizationUnitService,
        @Nonnull TrackedEntityMetadataService trackedEntityMetadataService, @Nonnull TrackedEntityRuleRepository trackedEntityRuleRepository ); @Nonnull @Override Set<FhirVersion> getFhirVersions(); }
R4ProgramMetadataToFhirPlanDefinitionTransformer extends AbstractProgramMetadataToFhirPlanDefinitionTransformer<PlanDefinition> { @Override protected boolean transformInternal( @Nonnull FhirClient fhirClient, @Nonnull DhisToFhirTransformerContext context, @Nonnull RuleInfo<ProgramMetadataRule> ruleInfo, @Nonnull Map<String, Object> scriptVariables, @Nonnull AccessibleScriptedDhisMetadata input, @Nonnull IBaseResource output ) { final Program dhisProgram = (Program) input.getDhisResource(); final PlanDefinition fhirPlanDefinition = (PlanDefinition) output; if ( !addSubjectResourceType( dhisProgram, fhirPlanDefinition ) ) { return false; } fhirPlanDefinition.setUrl( dhisProgram.getId() ); fhirPlanDefinition.setName( dhisProgram.getCode() ); fhirPlanDefinition.setTitle( dhisProgram.getName() ); fhirPlanDefinition.setStatus( Enumerations.PublicationStatus.ACTIVE ); fhirPlanDefinition.setDescription( dhisProgram.getDescription() ); fhirPlanDefinition.setAction( null ); dhisProgram.getStages().forEach( dhisProgramStage -> { final PlanDefinitionActionComponent action = fhirPlanDefinition.addAction(); action.setId( dhisProgramStage.getId() ); action.setTitle( dhisProgramStage.getName() ); action.setDescription( dhisProgramStage.getDescription() ); action.setCardinalityBehavior( dhisProgramStage.isRepeatable() ? PlanDefinition.ActionCardinalityBehavior.MULTIPLE : PlanDefinition.ActionCardinalityBehavior.SINGLE ); action.setDefinition( new CanonicalType( FhirResourceType.QUESTIONNAIRE.getResourceTypeName() + "/" + dhisProgramStage.getId() ) ); } ); return true; } R4ProgramMetadataToFhirPlanDefinitionTransformer( @Nonnull ScriptExecutor scriptExecutor, @Nonnull LockManager lockManager, @Nonnull SystemRepository systemRepository, @Nonnull FhirResourceRepository fhirResourceRepository,
        @Nonnull FhirDhisAssignmentRepository fhirDhisAssignmentRepository, @Nonnull OrganizationUnitService organizationUnitService,
        @Nonnull TrackedEntityMetadataService trackedEntityMetadataService, @Nonnull TrackedEntityRuleRepository trackedEntityRuleRepository ); @Nonnull @Override Set<FhirVersion> getFhirVersions();  }