Skip to content

Commit

Permalink
feat: add new identification configuration and rework identificationS…
Browse files Browse the repository at this point in the history
…tate
  • Loading branch information
SimonDmz committed Dec 18, 2024
1 parent e77a6e2 commit 0839cfc
Show file tree
Hide file tree
Showing 23 changed files with 469 additions and 154 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
package fr.insee.pearljam.api.domain;

public enum IdentificationConfiguration {
IASCO("Identification - Access - Situation - Category - Occupant"),
IASCO("Identification - Access - Situation - Category - Occupant"),// will be replaced by `HOUSEF2F`
HOUSEF2F("Household identification - Face to face"),
HOUSETEL("Household identification - Telephone"),
HOUSETELWSR("Household identification - Telephone - including secondary residence"),
INDF2F("Individual identification - Face to face"),
INDF2FNOR("Individual identification - Face to face - including Non Ordinary residence"),
INDTEL("Individual identification - Telephone"),
INDTELNOR("Individual identification - Telephone - including Non Ordinary residence"),
SRCVREINT("Only for SRCV campaign re-interrogation"),
NOIDENT("No identification");

/**
Expand Down
39 changes: 10 additions & 29 deletions src/main/java/fr/insee/pearljam/api/dto/statedata/StateDataDto.java
Original file line number Diff line number Diff line change
@@ -1,36 +1,17 @@
package fr.insee.pearljam.api.dto.statedata;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@NoArgsConstructor
@AllArgsConstructor
@Getter
@Setter
public class StateDataDto {
private String state;
private Long date;
private String currentPage;

public StateDataDto() {
super();
}

public StateDataDto(String state, Long date, String currentPage) {
super();
this.state = state;
this.date = date;
this.currentPage = currentPage;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public Long getDate() {
return date;
}
public void setDate(Long date) {
this.date = date;
}
public String getCurrentPage() {
return currentPage;
}
public void setCurrentPage(String currentPage) {
this.currentPage = currentPage;
}

}
Original file line number Diff line number Diff line change
@@ -1,26 +1,21 @@
package fr.insee.pearljam.api.dto.surveyunit;

import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;

import fr.insee.pearljam.api.domain.ClosingCauseType;
import fr.insee.pearljam.api.domain.InseeAddress;
import fr.insee.pearljam.api.domain.InseeSampleIdentifier;
import fr.insee.pearljam.api.domain.State;
import fr.insee.pearljam.api.domain.StateType;
import fr.insee.pearljam.api.domain.SurveyUnit;
import fr.insee.pearljam.api.surveyunit.dto.CommentDto;
import fr.insee.pearljam.api.domain.*;
import fr.insee.pearljam.api.dto.contactoutcome.ContactOutcomeDto;
import fr.insee.pearljam.api.dto.interviewer.InterviewerDto;
import fr.insee.pearljam.api.surveyunit.dto.CommentDto;
import fr.insee.pearljam.domain.surveyunit.model.IdentificationState;
import lombok.Getter;
import lombok.Setter;

import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

@JsonInclude(JsonInclude.Include.NON_NULL)
@Getter
@Setter
Expand All @@ -41,6 +36,9 @@ public class SurveyUnitCampaignDto {
private IdentificationState identificationState;
private List<CommentDto> comments;

@JsonIgnore // used to process identificationState server side, not exposed via API
private IdentificationConfiguration identificationConfiguration;

@JsonIgnoreProperties(value = { "surveyUnitCount" })
private InterviewerDto interviewer;

Expand Down Expand Up @@ -83,6 +81,7 @@ public SurveyUnitCampaignDto(SurveyUnit su) {
}
this.state = currentState == null ? null : currentState.getType();
this.campaign = su.getCampaign().getLabel();
this.identificationConfiguration = su.getCampaign().getIdentificationConfiguration();
this.interviewer = su.getInterviewer() != null ? new InterviewerDto(su.getInterviewer()) : null;
this.comments = CommentDto.fromModel(su.getModelComments());
if (su.getContactOucome() != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
package fr.insee.pearljam.api.service.impl;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import com.fasterxml.jackson.databind.JsonNode;
import fr.insee.pearljam.api.bussinessrules.BussinessRules;
import fr.insee.pearljam.api.constants.Constants;
import fr.insee.pearljam.api.domain.*;
import fr.insee.pearljam.api.dto.contactoutcome.ContactOutcomeDto;
import fr.insee.pearljam.api.dto.organizationunit.OrganizationUnitDto;
import fr.insee.pearljam.api.dto.person.PersonDto;
import fr.insee.pearljam.api.dto.state.StateDto;
import fr.insee.pearljam.api.dto.surveyunit.*;
import fr.insee.pearljam.api.exception.BadRequestException;
import fr.insee.pearljam.api.repository.*;
import fr.insee.pearljam.api.service.SurveyUnitService;
import fr.insee.pearljam.api.service.SurveyUnitUpdateService;
import fr.insee.pearljam.api.service.UserService;
import fr.insee.pearljam.api.service.UtilsService;
import fr.insee.pearljam.api.surveyunit.dto.SurveyUnitInterviewerResponseDto;
import fr.insee.pearljam.api.surveyunit.dto.SurveyUnitUpdateDto;
import fr.insee.pearljam.api.surveyunit.dto.SurveyUnitVisibilityDto;
Expand All @@ -21,32 +24,19 @@
import fr.insee.pearljam.domain.exception.PersonNotFoundException;
import fr.insee.pearljam.domain.exception.SurveyUnitNotFoundException;
import fr.insee.pearljam.domain.surveyunit.model.IdentificationState;
import fr.insee.pearljam.api.service.SurveyUnitUpdateService;
import fr.insee.pearljam.domain.surveyunit.model.SurveyUnitForInterviewer;
import jakarta.servlet.http.HttpServletRequest;

import com.fasterxml.jackson.databind.JsonNode;
import fr.insee.pearljam.api.domain.*;
import fr.insee.pearljam.api.repository.*;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.HttpStatusCode;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import fr.insee.pearljam.api.bussinessrules.BussinessRules;
import fr.insee.pearljam.api.constants.Constants;
import fr.insee.pearljam.api.dto.contactoutcome.ContactOutcomeDto;
import fr.insee.pearljam.api.dto.organizationunit.OrganizationUnitDto;
import fr.insee.pearljam.api.dto.person.PersonDto;
import fr.insee.pearljam.api.dto.state.StateDto;
import fr.insee.pearljam.api.exception.BadRequestException;
import fr.insee.pearljam.api.service.SurveyUnitService;
import fr.insee.pearljam.api.service.UserService;
import fr.insee.pearljam.api.service.UtilsService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
* @author scorcaud
Expand Down Expand Up @@ -303,7 +293,7 @@ private void updateAddress(SurveyUnit surveyUnit, SurveyUnitUpdateDto surveyUnit
@Transactional
public HttpStatus updateSurveyUnitViewed(String userId, String suId) {
Optional<SurveyUnit> surveyUnitOpt = surveyUnitRepository.findById(suId);
if (!surveyUnitOpt.isPresent()) {
if (surveyUnitOpt.isEmpty()) {
log.error(SU_ID_NOT_FOUND_FOR_INTERVIEWER, suId, userId);
return HttpStatus.NOT_FOUND;
}
Expand Down Expand Up @@ -367,7 +357,9 @@ public List<SurveyUnitCampaignDto> getClosableSurveyUnits(HttpServletRequest req

return suToCheck.stream().map(su -> {
SurveyUnitCampaignDto sudto = new SurveyUnitCampaignDto(su);
IdentificationState identificationResult = IdentificationState.getState(su.getModelIdentification());
IdentificationState identificationResult =
IdentificationState.getState(su.getModelIdentification(),
sudto.getIdentificationConfiguration());
sudto.setIdentificationState(identificationResult);
String questionnaireState = Optional.ofNullable(map.get(su.getId())).orElse(Constants.UNAVAILABLE);
sudto.setQuestionnaireState(questionnaireState);
Expand Down Expand Up @@ -493,7 +485,7 @@ private void addOrModifyClosingCause(SurveyUnit surveyUnit, ClosingCauseType typ

public List<StateDto> getListStatesBySurveyUnitId(String suId) {
Optional<SurveyUnit> su = surveyUnitRepository.findById(suId);
if (!su.isPresent()) {
if (su.isEmpty()) {
log.error("SU {} not found in database", suId);
return List.of();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
package fr.insee.pearljam.api.surveyunit.dto;

import com.fasterxml.jackson.annotation.JsonProperty;
import fr.insee.pearljam.domain.surveyunit.model.Identification;
import fr.insee.pearljam.domain.surveyunit.model.question.AccessQuestionValue;
import fr.insee.pearljam.domain.surveyunit.model.question.CategoryQuestionValue;
import fr.insee.pearljam.domain.surveyunit.model.question.IdentificationQuestionValue;
import fr.insee.pearljam.domain.surveyunit.model.question.OccupantQuestionValue;
import fr.insee.pearljam.domain.surveyunit.model.question.SituationQuestionValue;
import fr.insee.pearljam.domain.surveyunit.model.question.*;

public record IdentificationDto(
IdentificationQuestionValue identification,
AccessQuestionValue access,
SituationQuestionValue situation,
CategoryQuestionValue category,
OccupantQuestionValue occupant) {
OccupantQuestionValue occupant,
@JsonProperty("individual_status")
IndividualStatusQuestionValue individualStatus,
@JsonProperty("interviewer_can_process")
InterviewerCanProcessQuestionValue interviewerCanProcess,
@JsonProperty("number_of_respondents")
NumberOfRespondentsQuestionValue numberOfRespondents,
@JsonProperty("present_in_previous_home")
PresentInPreviousHomeQuestionValue presentInPreviousHome,
@JsonProperty("household_composition")
HouseholdCompositionQuestionValue householdComposition
) {

public static Identification toModel(IdentificationDto identificationDto) {
if(identificationDto == null) {
if (identificationDto == null) {
return null;
}

Expand All @@ -24,17 +32,29 @@ public static Identification toModel(IdentificationDto identificationDto) {
identificationDto.access(),
identificationDto.situation(),
identificationDto.category(),
identificationDto.occupant());
identificationDto.occupant(),
identificationDto.individualStatus(),
identificationDto.interviewerCanProcess(),
identificationDto.numberOfRespondents(),
identificationDto.presentInPreviousHome(),
identificationDto.householdComposition()
);
}

public static IdentificationDto fromModel(Identification identification) {
if(identification == null) {
if (identification == null) {
return null;
}
return new IdentificationDto(identification.identification(),
identification.access(),
identification.situation(),
identification.category(),
identification.occupant());
identification.occupant(),
identification.individualStatus(),
identification.interviewerCanProcess(),
identification.numberOfRespondents(),
identification.presentInPreviousHome(),
identification.householdComposition()
);
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
package fr.insee.pearljam.domain.surveyunit.model;

import fr.insee.pearljam.domain.surveyunit.model.question.*;
import lombok.Builder;

@Builder
public record Identification(
IdentificationQuestionValue identification,
AccessQuestionValue access,
SituationQuestionValue situation,
CategoryQuestionValue category,
OccupantQuestionValue occupant) {
OccupantQuestionValue occupant,
IndividualStatusQuestionValue individualStatus,
InterviewerCanProcessQuestionValue interviewerCanProcess,
NumberOfRespondentsQuestionValue numberOfRespondents,
PresentInPreviousHomeQuestionValue presentInPreviousHome,
HouseholdCompositionQuestionValue householdComposition
) {
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package fr.insee.pearljam.domain.surveyunit.model;

import fr.insee.pearljam.api.domain.IdentificationConfiguration;
import fr.insee.pearljam.domain.surveyunit.model.question.CategoryQuestionValue;
import fr.insee.pearljam.domain.surveyunit.model.question.IdentificationQuestionValue;
import fr.insee.pearljam.domain.surveyunit.model.question.SituationQuestionValue;
Expand All @@ -9,44 +10,66 @@ public enum IdentificationState {

/**
* Retrieve the identification state from the identification
* @param identification Identification form which the state is computed
*
* @param identification Identification from which the state is computed
* @param configuration Identification configuration to adapt rules
* @return the identification state
*/
public static IdentificationState getState(Identification identification) {
if(identification == null || identification.identification() == null) {
public static IdentificationState getState(Identification identification,
IdentificationConfiguration configuration) {
if (identification == null) {
return IdentificationState.MISSING;
}

return switch (configuration) {
case NOIDENT -> IdentificationState.MISSING;

case IASCO, HOUSEF2F -> houseF2F(identification);

// additional rules coming soon
case HOUSETEL, HOUSETELWSR, INDF2F, INDF2FNOR, INDTEL, INDTELNOR, SRCVREINT -> IdentificationState.MISSING;

};


}

private static IdentificationState houseF2F(Identification identification) {
IdentificationQuestionValue identificationQuestionValue = identification.identification();
if(identificationQuestionValue == IdentificationQuestionValue.DESTROY ||
if (identificationQuestionValue == null) {
return IdentificationState.MISSING;
}

if (identificationQuestionValue == IdentificationQuestionValue.DESTROY ||
identificationQuestionValue == IdentificationQuestionValue.UNIDENTIFIED) {
return IdentificationState.FINISHED;
}

if(identification.access() == null) {
if (identification.access() == null) {
return IdentificationState.ONGOING;
}

SituationQuestionValue situationQuestionValue = identification.situation();
if(situationQuestionValue == null) {
if (situationQuestionValue == null) {
return IdentificationState.ONGOING;
}

if(situationQuestionValue == SituationQuestionValue.ABSORBED ||
if (situationQuestionValue == SituationQuestionValue.ABSORBED ||
situationQuestionValue == SituationQuestionValue.NOORDINARY) {
return IdentificationState.FINISHED;
}

CategoryQuestionValue categoryQuestionValue = identification.category();
if(categoryQuestionValue == null) {
if (categoryQuestionValue == null) {
return IdentificationState.ONGOING;
}

if(categoryQuestionValue == CategoryQuestionValue.VACANT ||
if (categoryQuestionValue == CategoryQuestionValue.VACANT ||
categoryQuestionValue == CategoryQuestionValue.SECONDARY) {
return IdentificationState.FINISHED;
}

return identification.occupant() != null ? IdentificationState.FINISHED : IdentificationState.ONGOING;
return identification.occupant() == null ? IdentificationState.ONGOING : IdentificationState.FINISHED;
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package fr.insee.pearljam.domain.surveyunit.model.question;

public enum CategoryQuestionValue {
PRIMARY, OCCASIONAL, DK, SECONDARY, VACANT;
PRIMARY, OCCASIONAL, SECONDARY, VACANT;
}
Loading

0 comments on commit 0839cfc

Please sign in to comment.