@Test public void transformInternal() { final WritableProgram program = new WritableProgram(); program.setName( "Test Program" ); program.setDescription( "Test Description" ); program.setWithoutRegistration( false ); program.setTrackedEntityTypeId( "a1234567890" ); program.setStages( new ArrayList<>() ); final Patient patient = new Patient(); patient.setId( new IdDt( "Patient/lyau3syaixys" ) ); final ScriptedTrackedEntityInstance scriptedTrackedEntityInstance = new WritableScriptedTrackedEntityInstance( trackedEntityMetadataService, trackedEntityService, trackedEntityAttributes, trackedEntityType, "lyau3syaixys", scriptExecutionContext, valueConverter ); final Enrollment enrollment = new Enrollment(); enrollment.setProgramId( "x72638dsydu" ); enrollment.setOrgUnitId( "j82jdy28dusx" ); enrollment.setTrackedEntityInstanceId( "lyau3syaixys" ); enrollment.setStatus( EnrollmentStatus.COMPLETED ); enrollment.setEnrollmentDate( ZonedDateTime.parse( "2011-12-03T10:15:30+01:00" ) ); enrollment.setIncidentDate( ZonedDateTime.parse( "2011-12-01T10:11:30+01:00" ) ); final CarePlan fhirCarePlan = new CarePlan(); final Map<String, Object> scriptVariables = new HashMap<>(); scriptVariables.put( "assignmentUtils", assignmentUtils ); Mockito.doReturn( new Reference( "Location/j82jdy28dusx" ) ).when( assignmentUtils ).getMappedFhirId( Mockito.same( context ), Mockito.any(), Mockito.eq( DhisResourceType.ORGANIZATION_UNIT ), Mockito.eq( "j82jdy28dusx" ), Mockito.eq( FhirResourceType.LOCATION ) ); transformer.transformInternal( fhirClient, context, new RuleInfo<>( new EnrollmentRule(), Collections.emptyList() ), scriptVariables, new ImmutableScriptedEnrollment( new WritableScriptedEnrollment( program, enrollment, scriptedTrackedEntityInstance, scriptExecutionContext, valueConverter ) ), fhirCarePlan, patient ); Assert.assertEquals( 1, fhirCarePlan.getInstantiatesUri().size() ); Assert.assertEquals( "PlanDefinition/x72638dsydu", fhirCarePlan.getInstantiatesUri().get( 0 ).asStringValue() ); Assert.assertEquals( 1, fhirCarePlan.getInstantiatesCanonical().size() ); Assert.assertEquals( "PlanDefinition/x72638dsydu", fhirCarePlan.getInstantiatesCanonical().get( 0 ).asStringValue() ); Assert.assertEquals( CarePlan.CarePlanIntent.PLAN, fhirCarePlan.getIntent() ); Assert.assertEquals( CarePlan.CarePlanStatus.COMPLETED, fhirCarePlan.getStatus() ); Assert.assertEquals( "Patient/lyau3syaixys", fhirCarePlan.getSubject().getReference() ); Assert.assertEquals( "Location/j82jdy28dusx", Objects.requireNonNull( LocationExtensionUtils.getValue( fhirCarePlan ) ).getReferenceElement().getValue() ); Assert.assertEquals( Date.from( ZonedDateTime.parse( "2011-12-03T10:15:30+01:00" ).toInstant() ), fhirCarePlan.getPeriod().getStart() ); Assert.assertEquals( Date.from( ZonedDateTime.parse( "2011-12-01T10:11:30+01:00" ).toInstant() ), IncidentDateExtensionUtils.getValue( fhirCarePlan ) ); }
@Override protected boolean transformInternal( @Nonnull FhirClient fhirClient, @Nonnull DhisToFhirTransformerContext context, @Nonnull RuleInfo<EnrollmentRule> ruleInfo, @Nonnull Map<String, Object> scriptVariables, @Nonnull ScriptedEnrollment input, @Nonnull IBaseResource output, @Nonnull IBaseResource trackedEntityResource ) { final Enrollment enrollment = (Enrollment) input.getDhisResource(); final CarePlan fhirCarePlan = (CarePlan) output; final String planDefinitionUri = FhirResourceType.PLAN_DEFINITION.withId( enrollment.getProgramId() ); fhirCarePlan.setInstantiatesUri( Collections.singletonList( new UriType( planDefinitionUri ) ) ); fhirCarePlan.setInstantiatesCanonical( Collections.singletonList( new CanonicalType( planDefinitionUri ) ) ); fhirCarePlan.setIntent( CarePlan.CarePlanIntent.PLAN ); fhirCarePlan.setStatus( convertStatus( enrollment.getStatus() ) ); LocationExtensionUtils.setValue( fhirCarePlan, createAssignedFhirReference( context, ruleInfo, scriptVariables, DhisResourceType.ORGANIZATION_UNIT, enrollment.getOrgUnitId(), FhirResourceType.LOCATION ) ); fhirCarePlan.setSubject( new Reference( trackedEntityResource.getIdElement() ) ); fhirCarePlan.setPeriod( null ); fhirCarePlan.getPeriod().setStart( Date.from( enrollment.getEnrollmentDate().toInstant() ) ); IncidentDateExtensionUtils.setValue( fhirCarePlan, enrollment.getIncidentDate() == null ? null : Date.from( enrollment.getIncidentDate().toInstant() ), ResourceFactory::createType ); return true; }
R4EnrollmentToFhirCarePlanTransformer extends AbstractEnrollmentToFhirCarePlanTransformer { @Override protected boolean transformInternal( @Nonnull FhirClient fhirClient, @Nonnull DhisToFhirTransformerContext context, @Nonnull RuleInfo<EnrollmentRule> ruleInfo, @Nonnull Map<String, Object> scriptVariables, @Nonnull ScriptedEnrollment input, @Nonnull IBaseResource output, @Nonnull IBaseResource trackedEntityResource ) { final Enrollment enrollment = (Enrollment) input.getDhisResource(); final CarePlan fhirCarePlan = (CarePlan) output; final String planDefinitionUri = FhirResourceType.PLAN_DEFINITION.withId( enrollment.getProgramId() ); fhirCarePlan.setInstantiatesUri( Collections.singletonList( new UriType( planDefinitionUri ) ) ); fhirCarePlan.setInstantiatesCanonical( Collections.singletonList( new CanonicalType( planDefinitionUri ) ) ); fhirCarePlan.setIntent( CarePlan.CarePlanIntent.PLAN ); fhirCarePlan.setStatus( convertStatus( enrollment.getStatus() ) ); LocationExtensionUtils.setValue( fhirCarePlan, createAssignedFhirReference( context, ruleInfo, scriptVariables, DhisResourceType.ORGANIZATION_UNIT, enrollment.getOrgUnitId(), FhirResourceType.LOCATION ) ); fhirCarePlan.setSubject( new Reference( trackedEntityResource.getIdElement() ) ); fhirCarePlan.setPeriod( null ); fhirCarePlan.getPeriod().setStart( Date.from( enrollment.getEnrollmentDate().toInstant() ) ); IncidentDateExtensionUtils.setValue( fhirCarePlan, enrollment.getIncidentDate() == null ? null : Date.from( enrollment.getIncidentDate().toInstant() ), ResourceFactory::createType ); return true; } }
R4EnrollmentToFhirCarePlanTransformer extends AbstractEnrollmentToFhirCarePlanTransformer { @Override protected boolean transformInternal( @Nonnull FhirClient fhirClient, @Nonnull DhisToFhirTransformerContext context, @Nonnull RuleInfo<EnrollmentRule> ruleInfo, @Nonnull Map<String, Object> scriptVariables, @Nonnull ScriptedEnrollment input, @Nonnull IBaseResource output, @Nonnull IBaseResource trackedEntityResource ) { final Enrollment enrollment = (Enrollment) input.getDhisResource(); final CarePlan fhirCarePlan = (CarePlan) output; final String planDefinitionUri = FhirResourceType.PLAN_DEFINITION.withId( enrollment.getProgramId() ); fhirCarePlan.setInstantiatesUri( Collections.singletonList( new UriType( planDefinitionUri ) ) ); fhirCarePlan.setInstantiatesCanonical( Collections.singletonList( new CanonicalType( planDefinitionUri ) ) ); fhirCarePlan.setIntent( CarePlan.CarePlanIntent.PLAN ); fhirCarePlan.setStatus( convertStatus( enrollment.getStatus() ) ); LocationExtensionUtils.setValue( fhirCarePlan, createAssignedFhirReference( context, ruleInfo, scriptVariables, DhisResourceType.ORGANIZATION_UNIT, enrollment.getOrgUnitId(), FhirResourceType.LOCATION ) ); fhirCarePlan.setSubject( new Reference( trackedEntityResource.getIdElement() ) ); fhirCarePlan.setPeriod( null ); fhirCarePlan.getPeriod().setStart( Date.from( enrollment.getEnrollmentDate().toInstant() ) ); IncidentDateExtensionUtils.setValue( fhirCarePlan, enrollment.getIncidentDate() == null ? null : Date.from( enrollment.getIncidentDate().toInstant() ), ResourceFactory::createType ); return true; } R4EnrollmentToFhirCarePlanTransformer( @Nonnull ScriptExecutor scriptExecutor, @Nonnull LockManager lockManager, @Nonnull SystemRepository systemRepository, @Nonnull FhirResourceRepository fhirResourceRepository,
        @Nonnull FhirResourceMappingRepository resourceMappingRepository, @Nonnull FhirDhisAssignmentRepository fhirDhisAssignmentRepository, @Nonnull TrackedEntityMetadataService trackedEntityMetadataService,
        @Nonnull TrackedEntityRuleRepository trackedEntityRuleRepository, @Nonnull ProgramMetadataService programMetadataService ); }
R4EnrollmentToFhirCarePlanTransformer extends AbstractEnrollmentToFhirCarePlanTransformer { @Override protected boolean transformInternal( @Nonnull FhirClient fhirClient, @Nonnull DhisToFhirTransformerContext context, @Nonnull RuleInfo<EnrollmentRule> ruleInfo, @Nonnull Map<String, Object> scriptVariables, @Nonnull ScriptedEnrollment input, @Nonnull IBaseResource output, @Nonnull IBaseResource trackedEntityResource ) { final Enrollment enrollment = (Enrollment) input.getDhisResource(); final CarePlan fhirCarePlan = (CarePlan) output; final String planDefinitionUri = FhirResourceType.PLAN_DEFINITION.withId( enrollment.getProgramId() ); fhirCarePlan.setInstantiatesUri( Collections.singletonList( new UriType( planDefinitionUri ) ) ); fhirCarePlan.setInstantiatesCanonical( Collections.singletonList( new CanonicalType( planDefinitionUri ) ) ); fhirCarePlan.setIntent( CarePlan.CarePlanIntent.PLAN ); fhirCarePlan.setStatus( convertStatus( enrollment.getStatus() ) ); LocationExtensionUtils.setValue( fhirCarePlan, createAssignedFhirReference( context, ruleInfo, scriptVariables, DhisResourceType.ORGANIZATION_UNIT, enrollment.getOrgUnitId(), FhirResourceType.LOCATION ) ); fhirCarePlan.setSubject( new Reference( trackedEntityResource.getIdElement() ) ); fhirCarePlan.setPeriod( null ); fhirCarePlan.getPeriod().setStart( Date.from( enrollment.getEnrollmentDate().toInstant() ) ); IncidentDateExtensionUtils.setValue( fhirCarePlan, enrollment.getIncidentDate() == null ? null : Date.from( enrollment.getIncidentDate().toInstant() ), ResourceFactory::createType ); return true; } R4EnrollmentToFhirCarePlanTransformer( @Nonnull ScriptExecutor scriptExecutor, @Nonnull LockManager lockManager, @Nonnull SystemRepository systemRepository, @Nonnull FhirResourceRepository fhirResourceRepository,
        @Nonnull FhirResourceMappingRepository resourceMappingRepository, @Nonnull FhirDhisAssignmentRepository fhirDhisAssignmentRepository, @Nonnull TrackedEntityMetadataService trackedEntityMetadataService,
        @Nonnull TrackedEntityRuleRepository trackedEntityRuleRepository, @Nonnull ProgramMetadataService programMetadataService ); @Nonnull @Override Set<FhirVersion> getFhirVersions(); }
R4EnrollmentToFhirCarePlanTransformer extends AbstractEnrollmentToFhirCarePlanTransformer { @Override protected boolean transformInternal( @Nonnull FhirClient fhirClient, @Nonnull DhisToFhirTransformerContext context, @Nonnull RuleInfo<EnrollmentRule> ruleInfo, @Nonnull Map<String, Object> scriptVariables, @Nonnull ScriptedEnrollment input, @Nonnull IBaseResource output, @Nonnull IBaseResource trackedEntityResource ) { final Enrollment enrollment = (Enrollment) input.getDhisResource(); final CarePlan fhirCarePlan = (CarePlan) output; final String planDefinitionUri = FhirResourceType.PLAN_DEFINITION.withId( enrollment.getProgramId() ); fhirCarePlan.setInstantiatesUri( Collections.singletonList( new UriType( planDefinitionUri ) ) ); fhirCarePlan.setInstantiatesCanonical( Collections.singletonList( new CanonicalType( planDefinitionUri ) ) ); fhirCarePlan.setIntent( CarePlan.CarePlanIntent.PLAN ); fhirCarePlan.setStatus( convertStatus( enrollment.getStatus() ) ); LocationExtensionUtils.setValue( fhirCarePlan, createAssignedFhirReference( context, ruleInfo, scriptVariables, DhisResourceType.ORGANIZATION_UNIT, enrollment.getOrgUnitId(), FhirResourceType.LOCATION ) ); fhirCarePlan.setSubject( new Reference( trackedEntityResource.getIdElement() ) ); fhirCarePlan.setPeriod( null ); fhirCarePlan.getPeriod().setStart( Date.from( enrollment.getEnrollmentDate().toInstant() ) ); IncidentDateExtensionUtils.setValue( fhirCarePlan, enrollment.getIncidentDate() == null ? null : Date.from( enrollment.getIncidentDate().toInstant() ), ResourceFactory::createType ); return true; } R4EnrollmentToFhirCarePlanTransformer( @Nonnull ScriptExecutor scriptExecutor, @Nonnull LockManager lockManager, @Nonnull SystemRepository systemRepository, @Nonnull FhirResourceRepository fhirResourceRepository,
        @Nonnull FhirResourceMappingRepository resourceMappingRepository, @Nonnull FhirDhisAssignmentRepository fhirDhisAssignmentRepository, @Nonnull TrackedEntityMetadataService trackedEntityMetadataService,
        @Nonnull TrackedEntityRuleRepository trackedEntityRuleRepository, @Nonnull ProgramMetadataService programMetadataService ); @Nonnull @Override Set<FhirVersion> getFhirVersions();  }