@Test public void transformInternal() { final WritableProgram program = new WritableProgram(); program.setId( "x72638dsydu" ); 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(); final CarePlan fhirCarePlan = new CarePlan(); fhirCarePlan.addInstantiatesUri( "PlanDefinition/x72638dsydu" ); fhirCarePlan.setStatus( CarePlan.CarePlanStatus.COMPLETED ); fhirCarePlan.getPeriod().setStart( Date.from( ZonedDateTime.parse( "2011-12-03T10:15:30+01:00" ).toInstant() ) ); LocationExtensionUtils.setValue( fhirCarePlan, new Reference( "Location/j82jdy28dusx" ) ); IncidentDateExtensionUtils.setValue( fhirCarePlan, Date.from( ZonedDateTime.parse( "2011-12-01T10:11:30+01:00" ).toInstant() ), ResourceFactory::createType ); final Map<String, Object> scriptVariables = new HashMap<>(); Mockito.doReturn( orgUnitExecutableScript ).when( fhirResourceMapping ) .getImpEnrollmentOrgLookupScript(); Mockito.doReturn( org.dhis2.fhir.adapter.dhis.model.Reference.createIdReference( "j82jdy28dusx" ) ) .when( scriptExecutor ).execute( Mockito.same( orgUnitExecutableScript ), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any() ); transformer.transformInternal( transformerContext, new RuleInfo<>( new EnrollmentRule(), Collections.emptyList() ), scriptVariables, fhirResourceMapping, program, fhirCarePlan, scriptedTrackedEntityInstance, new WritableScriptedEnrollment( program, enrollment, scriptedTrackedEntityInstance, scriptExecutionContext, valueConverter ) ); Assert.assertEquals( "x72638dsydu", enrollment.getProgramId() ); Assert.assertEquals( "j82jdy28dusx", enrollment.getOrgUnitId() ); Assert.assertEquals( "lyau3syaixys", enrollment.getTrackedEntityInstanceId() ); Assert.assertEquals( EnrollmentStatus.COMPLETED, enrollment.getStatus() ); Assert.assertEquals( ZonedDateTime.parse( "2011-12-03T10:15:30+01:00" ).toLocalDateTime(), enrollment.getEnrollmentDate().toLocalDateTime() ); Assert.assertEquals( ZonedDateTime.parse( "2011-12-01T10:11:30+01:00" ).toLocalDateTime(), enrollment.getIncidentDate().toLocalDateTime() ); }
@Override protected void transformInternal( @Nonnull FhirToDhisTransformerContext context, @Nonnull RuleInfo<EnrollmentRule> ruleInfo, @Nonnull Map<String, Object> scriptVariables, @Nonnull FhirResourceMapping fhirResourceMapping, @Nonnull Program program, @Nonnull IBaseResource carePlan, @Nonnull ScriptedTrackedEntityInstance scriptedTrackedEntityInstance, @Nonnull WritableScriptedEnrollment scriptedEnrollment ) throws TransformerException { final CarePlan fhirCarePlan = (CarePlan) carePlan; final Enrollment enrollment = (Enrollment) scriptedEnrollment.getDhisResource(); enrollment.setProgramId( program.getId() ); enrollment.setStatus( convertStatus( fhirCarePlan.getStatus() ) ); enrollment.setOrgUnitId( getOrgUnitId( context, ruleInfo, fhirResourceMapping.getImpEnrollmentOrgLookupScript(), scriptVariables ) .orElseThrow( () -> new TransformerMappingException( "Care plan contains location that cannot be mapped." ) ) ); enrollment.setTrackedEntityInstanceId( scriptedTrackedEntityInstance.getId() ); final Date enrollmentDate = fhirCarePlan.getPeriod().getStart(); enrollment.setEnrollmentDate( enrollmentDate == null ? null : ZonedDateTime.ofInstant( enrollmentDate.toInstant(), zoneId ) ); final Date incidentDate = IncidentDateExtensionUtils.getValue( fhirCarePlan ); enrollment.setIncidentDate( incidentDate == null ? null : ZonedDateTime.ofInstant( incidentDate.toInstant(), zoneId ) ); enrollment.setModified(); }
R4FhirCarePlanToEnrollmentTransformer extends AbstractFhirCarePlanToEnrollmentTransformer { @Override protected void transformInternal( @Nonnull FhirToDhisTransformerContext context, @Nonnull RuleInfo<EnrollmentRule> ruleInfo, @Nonnull Map<String, Object> scriptVariables, @Nonnull FhirResourceMapping fhirResourceMapping, @Nonnull Program program, @Nonnull IBaseResource carePlan, @Nonnull ScriptedTrackedEntityInstance scriptedTrackedEntityInstance, @Nonnull WritableScriptedEnrollment scriptedEnrollment ) throws TransformerException { final CarePlan fhirCarePlan = (CarePlan) carePlan; final Enrollment enrollment = (Enrollment) scriptedEnrollment.getDhisResource(); enrollment.setProgramId( program.getId() ); enrollment.setStatus( convertStatus( fhirCarePlan.getStatus() ) ); enrollment.setOrgUnitId( getOrgUnitId( context, ruleInfo, fhirResourceMapping.getImpEnrollmentOrgLookupScript(), scriptVariables ) .orElseThrow( () -> new TransformerMappingException( "Care plan contains location that cannot be mapped." ) ) ); enrollment.setTrackedEntityInstanceId( scriptedTrackedEntityInstance.getId() ); final Date enrollmentDate = fhirCarePlan.getPeriod().getStart(); enrollment.setEnrollmentDate( enrollmentDate == null ? null : ZonedDateTime.ofInstant( enrollmentDate.toInstant(), zoneId ) ); final Date incidentDate = IncidentDateExtensionUtils.getValue( fhirCarePlan ); enrollment.setIncidentDate( incidentDate == null ? null : ZonedDateTime.ofInstant( incidentDate.toInstant(), zoneId ) ); enrollment.setModified(); } }
R4FhirCarePlanToEnrollmentTransformer extends AbstractFhirCarePlanToEnrollmentTransformer { @Override protected void transformInternal( @Nonnull FhirToDhisTransformerContext context, @Nonnull RuleInfo<EnrollmentRule> ruleInfo, @Nonnull Map<String, Object> scriptVariables, @Nonnull FhirResourceMapping fhirResourceMapping, @Nonnull Program program, @Nonnull IBaseResource carePlan, @Nonnull ScriptedTrackedEntityInstance scriptedTrackedEntityInstance, @Nonnull WritableScriptedEnrollment scriptedEnrollment ) throws TransformerException { final CarePlan fhirCarePlan = (CarePlan) carePlan; final Enrollment enrollment = (Enrollment) scriptedEnrollment.getDhisResource(); enrollment.setProgramId( program.getId() ); enrollment.setStatus( convertStatus( fhirCarePlan.getStatus() ) ); enrollment.setOrgUnitId( getOrgUnitId( context, ruleInfo, fhirResourceMapping.getImpEnrollmentOrgLookupScript(), scriptVariables ) .orElseThrow( () -> new TransformerMappingException( "Care plan contains location that cannot be mapped." ) ) ); enrollment.setTrackedEntityInstanceId( scriptedTrackedEntityInstance.getId() ); final Date enrollmentDate = fhirCarePlan.getPeriod().getStart(); enrollment.setEnrollmentDate( enrollmentDate == null ? null : ZonedDateTime.ofInstant( enrollmentDate.toInstant(), zoneId ) ); final Date incidentDate = IncidentDateExtensionUtils.getValue( fhirCarePlan ); enrollment.setIncidentDate( incidentDate == null ? null : ZonedDateTime.ofInstant( incidentDate.toInstant(), zoneId ) ); enrollment.setModified(); } 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 ); }
R4FhirCarePlanToEnrollmentTransformer extends AbstractFhirCarePlanToEnrollmentTransformer { @Override protected void transformInternal( @Nonnull FhirToDhisTransformerContext context, @Nonnull RuleInfo<EnrollmentRule> ruleInfo, @Nonnull Map<String, Object> scriptVariables, @Nonnull FhirResourceMapping fhirResourceMapping, @Nonnull Program program, @Nonnull IBaseResource carePlan, @Nonnull ScriptedTrackedEntityInstance scriptedTrackedEntityInstance, @Nonnull WritableScriptedEnrollment scriptedEnrollment ) throws TransformerException { final CarePlan fhirCarePlan = (CarePlan) carePlan; final Enrollment enrollment = (Enrollment) scriptedEnrollment.getDhisResource(); enrollment.setProgramId( program.getId() ); enrollment.setStatus( convertStatus( fhirCarePlan.getStatus() ) ); enrollment.setOrgUnitId( getOrgUnitId( context, ruleInfo, fhirResourceMapping.getImpEnrollmentOrgLookupScript(), scriptVariables ) .orElseThrow( () -> new TransformerMappingException( "Care plan contains location that cannot be mapped." ) ) ); enrollment.setTrackedEntityInstanceId( scriptedTrackedEntityInstance.getId() ); final Date enrollmentDate = fhirCarePlan.getPeriod().getStart(); enrollment.setEnrollmentDate( enrollmentDate == null ? null : ZonedDateTime.ofInstant( enrollmentDate.toInstant(), zoneId ) ); final Date incidentDate = IncidentDateExtensionUtils.getValue( fhirCarePlan ); enrollment.setIncidentDate( incidentDate == null ? null : ZonedDateTime.ofInstant( incidentDate.toInstant(), zoneId ) ); enrollment.setModified(); } 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 ); @Nonnull @Override Set<FhirVersion> getFhirVersions(); }
R4FhirCarePlanToEnrollmentTransformer extends AbstractFhirCarePlanToEnrollmentTransformer { @Override protected void transformInternal( @Nonnull FhirToDhisTransformerContext context, @Nonnull RuleInfo<EnrollmentRule> ruleInfo, @Nonnull Map<String, Object> scriptVariables, @Nonnull FhirResourceMapping fhirResourceMapping, @Nonnull Program program, @Nonnull IBaseResource carePlan, @Nonnull ScriptedTrackedEntityInstance scriptedTrackedEntityInstance, @Nonnull WritableScriptedEnrollment scriptedEnrollment ) throws TransformerException { final CarePlan fhirCarePlan = (CarePlan) carePlan; final Enrollment enrollment = (Enrollment) scriptedEnrollment.getDhisResource(); enrollment.setProgramId( program.getId() ); enrollment.setStatus( convertStatus( fhirCarePlan.getStatus() ) ); enrollment.setOrgUnitId( getOrgUnitId( context, ruleInfo, fhirResourceMapping.getImpEnrollmentOrgLookupScript(), scriptVariables ) .orElseThrow( () -> new TransformerMappingException( "Care plan contains location that cannot be mapped." ) ) ); enrollment.setTrackedEntityInstanceId( scriptedTrackedEntityInstance.getId() ); final Date enrollmentDate = fhirCarePlan.getPeriod().getStart(); enrollment.setEnrollmentDate( enrollmentDate == null ? null : ZonedDateTime.ofInstant( enrollmentDate.toInstant(), zoneId ) ); final Date incidentDate = IncidentDateExtensionUtils.getValue( fhirCarePlan ); enrollment.setIncidentDate( incidentDate == null ? null : ZonedDateTime.ofInstant( incidentDate.toInstant(), zoneId ) ); enrollment.setModified(); } 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 ); @Nonnull @Override Set<FhirVersion> getFhirVersions();  }