class R4FhirCarePlanToEnrollmentTransformer extends AbstractFhirCarePlanToEnrollmentTransformer {

    @Nonnull
    @Override
    protected Reference getProgramRef( @Nonnull FhirToDhisTransformerContext context, @Nonnull RuleInfo<EnrollmentRule> ruleInfo, @Nonnull Map<String, Object> scriptVariables, @Nonnull IBaseResource carePlan )
    {
        final CarePlan fhirCarePlan = (CarePlan) carePlan;
        String uri = null;

        if ( !fhirCarePlan.getInstantiatesUri().isEmpty() )
        {
            uri = fhirCarePlan.getInstantiatesUri().get( 0 ).getValueAsString();
        }
        else if ( !fhirCarePlan.getInstantiatesCanonical().isEmpty() )
        {
            uri = fhirCarePlan.getInstantiatesCanonical().get( 0 ).getValueAsString();
        }

        if ( uri == null )
        {
            throw new TransformerDataException( "No reference to a plan definition that is instantiated by this care plan has been given." );
        }

        final IIdType id;
        try
        {
            id = FhirUriUtils.createIdFromUri( uri, FhirResourceType.PLAN_DEFINITION );
        }
        catch ( IllegalArgumentException e )
        {
            throw new TransformerDataException( e.getMessage(), e );
        }

        return Reference.createIdReference( id.getIdPart() );
    }

    public  R4FhirCarePlanToEnrollmentTransformer( @Nonnull ScriptExecutor scriptExecutor, @Nonnull TrackedEntityMetadataService trackedEntityMetadataService, @Nonnull TrackedEntityService trackedEntityService,
        @Nonnull TrackedEntityRuleRepository trackedEntityRuleRepository, @Nonnull OrganizationUnitService organizationUnitService, @Nonnull ProgramMetadataService programMetadataService, @Nonnull EnrollmentService enrollmentService,
        @Nonnull FhirResourceMappingRepository resourceMappingRepository, @Nonnull FhirDhisAssignmentRepository fhirDhisAssignmentRepository, @Nonnull ScriptExecutionContext scriptExecutionContext, @Nonnull ValueConverter valueConverter );

}