### Question:
R4FhirQuestionnaireResponseToProgramStageTransformer extends AbstractFhirQuestionnaireResponseToProgramStageTransformer { @Nonnull @Override protected Reference getProgramStageRef( @Nonnull FhirToDhisTransformerContext context, @Nonnull RuleInfo<ProgramStageRule> ruleInfo, @Nonnull Map<String, Object> scriptVariables, @Nonnull IBaseResource questionnaireResponse ) { final QuestionnaireResponse fhirQuestionnaireResponse = (QuestionnaireResponse) questionnaireResponse; final String uri = fhirQuestionnaireResponse.getQuestionnaire(); if ( uri == null ) { throw new TransformerDataException( "No reference to a questionnaire that is instantiated by this questionnaire response has been given." ); } final IIdType id; try { id = FhirUriUtils.createIdFromUri( uri, FhirResourceType.QUESTIONNAIRE ); } catch ( IllegalArgumentException e ) { throw new TransformerDataException( e.getMessage(), e ); } return Reference.createIdReference( id.getIdPart() ); } R4FhirQuestionnaireResponseToProgramStageTransformer( @Nonnull ScriptExecutor scriptExecutor, @Nonnull TrackedEntityMetadataService trackedEntityMetadataService, @Nonnull TrackedEntityService trackedEntityService,
        @Nonnull TrackedEntityRuleRepository trackedEntityRuleRepository, @Nonnull OrganizationUnitService organizationUnitService, @Nonnull ProgramMetadataService programMetadataService, @Nonnull ProgramStageMetadataService programStageMetadataService,
        @Nonnull EventService eventService, @Nonnull FhirResourceMappingRepository resourceMappingRepository, @Nonnull FhirDhisAssignmentRepository fhirDhisAssignmentRepository, @Nonnull ScriptExecutionContext scriptExecutionContext,
        @Nonnull ValueConverter valueConverter ); @Nonnull @Override Set<FhirVersion> getFhirVersions();  }### Answer:
@Test public void getProgramStageRef() { final QuestionnaireResponse questionnaireResponse = new QuestionnaireResponse(); questionnaireResponse.setQuestionnaire( "Questionnaire/sj87dhyui82" ); Assert.assertEquals( new org.dhis2.fhir.adapter.dhis.model.Reference( "sj87dhyui82", ReferenceType.ID ), transformer.getProgramStageRef( transformerContext, new RuleInfo<>( new ProgramStageRule(), Collections.emptyList() ), new HashMap<>(), questionnaireResponse ) ); }
@Test public void getProgramRefWithoutType() { final QuestionnaireResponse questionnaireResponse = new QuestionnaireResponse(); questionnaireResponse.setQuestionnaire( "sj87dhyui82" ); Assert.assertEquals( new org.dhis2.fhir.adapter.dhis.model.Reference( "sj87dhyui82", ReferenceType.ID ), transformer.getProgramStageRef( transformerContext, new RuleInfo<>( new ProgramStageRule(), Collections.emptyList() ), new HashMap<>(), questionnaireResponse ) ); }
@Test( expected = TransformerDataException.class ) public void getProgramRefNull() { final QuestionnaireResponse questionnaireResponse = new QuestionnaireResponse(); transformer.getProgramStageRef( transformerContext, new RuleInfo<>( new ProgramStageRule(), Collections.emptyList() ), new HashMap<>(), questionnaireResponse ); }