Search in sources :

Example 36 with UserDto

use of de.symeda.sormas.api.user.UserDto in project SORMAS-Project by hzi-braunschweig.

the class CaseFacadeEjbTest method testCloneCaseActivityAsCaseIsCloned.

@Test
public void testCloneCaseActivityAsCaseIsCloned() {
    useNationalUserLogin();
    // 1. Create
    // Create aCase
    UserDto user = creator.createUser("", "", "", "", "");
    UserReferenceDto userReferenceDto = new UserReferenceDto(user.getUuid());
    PersonDto person = creator.createPerson("Max", "Smith");
    person.setBirthWeight(2);
    getPersonFacade().savePerson(person);
    PersonReferenceDto personReferenceDto = new PersonReferenceDto(person.getUuid());
    RDCF rdcf = creator.createRDCF();
    CaseDataDto aCase = creator.createCase(userReferenceDto, personReferenceDto, Disease.CHOLERA, CaseClassification.SUSPECT, InvestigationStatus.PENDING, new Date(), rdcf, (c) -> {
        c.setAdditionalDetails("Test other additional details");
        c.setFollowUpComment("Test other followup comment");
    });
    aCase.setClinicianName("name");
    aCase.getEpiData().setActivityAsCaseDetailsKnown(YesNoUnknown.YES);
    final ArrayList<ActivityAsCaseDto> otherActivitiesAsCase = new ArrayList<>();
    ActivityAsCaseDto activityAsCaseDto = new ActivityAsCaseDto();
    activityAsCaseDto.setActivityAsCaseType(ActivityAsCaseType.GATHERING);
    otherActivitiesAsCase.add(activityAsCaseDto);
    aCase.getEpiData().setActivitiesAsCase(otherActivitiesAsCase);
    CaseDataDto caseDataDto = getCaseFacade().save(aCase);
    // 2. Clone
    CaseDataDto clonedCase = getCaseFacade().cloneCase(caseDataDto);
    final EpiDataDto epiData = clonedCase.getEpiData();
    assertEquals(YesNoUnknown.YES, epiData.getActivityAsCaseDetailsKnown());
    final List<ActivityAsCaseDto> activitiesAsCase = epiData.getActivitiesAsCase();
    assertEquals(1, activitiesAsCase.size());
    assertEquals(ActivityAsCaseType.GATHERING, activitiesAsCase.get(0).getActivityAsCaseType());
}
Also used : UserReferenceDto(de.symeda.sormas.api.user.UserReferenceDto) EpiDataDto(de.symeda.sormas.api.epidata.EpiDataDto) RDCF(de.symeda.sormas.backend.TestDataCreator.RDCF) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) CasePersonDto(de.symeda.sormas.api.caze.CasePersonDto) PersonDto(de.symeda.sormas.api.person.PersonDto) UserDto(de.symeda.sormas.api.user.UserDto) PersonReferenceDto(de.symeda.sormas.api.person.PersonReferenceDto) ActivityAsCaseDto(de.symeda.sormas.api.activityascase.ActivityAsCaseDto) ArrayList(java.util.ArrayList) Date(java.util.Date) LocalDate(java.time.LocalDate) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) Test(org.junit.Test)

Example 37 with UserDto

use of de.symeda.sormas.api.user.UserDto in project SORMAS-Project by hzi-braunschweig.

the class CaseFacadeEjbTest method testOutcomePersonConditionUpdate.

@Test
public void testOutcomePersonConditionUpdate() {
    final Date today = new Date();
    RDCFEntities rdcf = creator.createRDCFEntities("Region", "District", "Community", "Facility");
    UserDto user = creator.createUser(rdcf.region.getUuid(), rdcf.district.getUuid(), rdcf.facility.getUuid(), "Surv", "Sup", UserRole.SURVEILLANCE_SUPERVISOR);
    PersonDto cazePerson = creator.createPerson("Case", "Person");
    CaseDataDto firstCase = creator.createCase(user.toReference(), cazePerson.toReference(), Disease.EVD, CaseClassification.PROBABLE, InvestigationStatus.PENDING, today, rdcf);
    // case deceased -> person should be set to dead, causeofdeath(disease) filled in
    firstCase.setOutcome(CaseOutcome.DECEASED);
    firstCase = getCaseFacade().save(firstCase);
    cazePerson = getPersonFacade().getPersonByUuid(cazePerson.getUuid());
    assertNull(firstCase.getOutcomeDate());
    assertEquals(PresentCondition.DEAD, cazePerson.getPresentCondition());
    assertEquals(CauseOfDeath.EPIDEMIC_DISEASE, cazePerson.getCauseOfDeath());
    assertEquals(firstCase.getDisease(), cazePerson.getCauseOfDeathDisease());
    // update just the outcomeDate -> person should also get the deathdate set
    firstCase.setOutcomeDate(today);
    firstCase = getCaseFacade().save(firstCase);
    cazePerson = getPersonFacade().getPersonByUuid(cazePerson.getUuid());
    assertTrue(DateHelper.isSameDay(firstCase.getOutcomeDate(), cazePerson.getDeathDate()));
    // case has no outcome again -> person should be alive
    firstCase.setOutcome(CaseOutcome.NO_OUTCOME);
    firstCase = getCaseFacade().save(firstCase);
    cazePerson = getPersonFacade().getPersonByUuid(cazePerson.getUuid());
    assertNull(firstCase.getOutcomeDate());
    assertEquals(PresentCondition.ALIVE, cazePerson.getPresentCondition());
    assertNull(cazePerson.getDeathDate());
    // additional, newer cases for the the person
    firstCase.setReportDate(DateHelper.subtractDays(today, 17));
    firstCase.getSymptoms().setOnsetDate(firstCase.getReportDate());
    firstCase = getCaseFacade().save(firstCase);
    CaseDataDto secondCase = creator.createCase(user.toReference(), cazePerson.toReference(), Disease.EVD, CaseClassification.PROBABLE, InvestigationStatus.PENDING, DateHelper.subtractDays(today, 12), rdcf);
    secondCase.setOutcome(CaseOutcome.RECOVERED);
    secondCase.setOutcomeDate(DateHelper.subtractDays(today, 10));
    secondCase = getCaseFacade().save(secondCase);
    CaseDataDto thirdCase = creator.createCase(user.toReference(), cazePerson.toReference(), Disease.MEASLES, CaseClassification.PROBABLE, InvestigationStatus.PENDING, DateHelper.subtractDays(today, 7), rdcf);
    thirdCase.setOutcome(CaseOutcome.DECEASED);
    thirdCase.setOutcomeDate(DateHelper.subtractDays(today, 5));
    thirdCase = getCaseFacade().save(thirdCase);
    // the newest case is set to deceased -> person should be dead
    cazePerson = getPersonFacade().getPersonByUuid(cazePerson.getUuid());
    firstCase = getCaseFacade().getCaseDataByUuid(firstCase.getUuid());
    secondCase = getCaseFacade().getCaseDataByUuid(secondCase.getUuid());
    assertEquals(PresentCondition.DEAD, cazePerson.getPresentCondition());
    assertEquals(CauseOfDeath.EPIDEMIC_DISEASE, cazePerson.getCauseOfDeath());
    assertEquals(thirdCase.getDisease(), cazePerson.getCauseOfDeathDisease());
    assertEquals(CaseOutcome.NO_OUTCOME, firstCase.getOutcome());
    assertEquals(CaseOutcome.RECOVERED, secondCase.getOutcome());
    assertEquals(CaseOutcome.DECEASED, thirdCase.getOutcome());
    assertTrue(DateHelper.isSameDay(cazePerson.getDeathDate(), thirdCase.getOutcomeDate()));
    // person alive again -> deceased case has to be set to no outcome
    cazePerson.setPresentCondition(PresentCondition.ALIVE);
    cazePerson = getPersonFacade().savePerson(cazePerson);
    firstCase = getCaseFacade().getCaseDataByUuid(firstCase.getUuid());
    secondCase = getCaseFacade().getCaseDataByUuid(secondCase.getUuid());
    thirdCase = getCaseFacade().getCaseDataByUuid(thirdCase.getUuid());
    assertEquals(CaseOutcome.NO_OUTCOME, firstCase.getOutcome());
    assertEquals(CaseOutcome.RECOVERED, secondCase.getOutcome());
    assertEquals(CaseOutcome.NO_OUTCOME, thirdCase.getOutcome());
    assertNull(thirdCase.getOutcomeDate());
    // move 1st and 3rd case to past, so that they should no longer be affected by anything
    firstCase.setReportDate(DateHelper.subtractDays(today, 100));
    firstCase.getSymptoms().setOnsetDate(firstCase.getReportDate());
    thirdCase.setReportDate(DateHelper.subtractDays(today, 100));
    thirdCase.getSymptoms().setOnsetDate(thirdCase.getReportDate());
    getCaseFacade().save(firstCase);
    getCaseFacade().save(thirdCase);
    // Set 2nd Case to deceased again
    secondCase.setOutcome(CaseOutcome.DECEASED);
    secondCase = getCaseFacade().save(secondCase);
    cazePerson = getPersonFacade().getPersonByUuid(cazePerson.getUuid());
    // manually set the persons deathdate to 32 days in the past
    cazePerson.setDeathDate(DateHelper.subtractDays(secondCase.getReportDate(), 32));
    cazePerson = getPersonFacade().savePerson(cazePerson);
    // Change Case to RECOVERD -> person should not change, because deathdate is over 30 days away from case reportdate
    secondCase.setOutcome(CaseOutcome.RECOVERED);
    secondCase = getCaseFacade().save(secondCase);
    cazePerson = getPersonFacade().getPersonByUuid(cazePerson.getUuid());
    assertEquals(PresentCondition.DEAD, cazePerson.getPresentCondition());
    // update the present condition to dead -> case should still not be affected because of the date threshold
    cazePerson.setPresentCondition(PresentCondition.DEAD);
    cazePerson.setDeathDate(today);
    cazePerson.setCauseOfDeath(CauseOfDeath.EPIDEMIC_DISEASE);
    cazePerson.setCauseOfDeathDisease(secondCase.getDisease());
    getPersonFacade().savePerson(cazePerson);
    secondCase = getCaseFacade().getCaseDataByUuid(secondCase.getUuid());
    assertEquals(CaseOutcome.RECOVERED, secondCase.getOutcome());
}
Also used : RDCFEntities(de.symeda.sormas.backend.TestDataCreator.RDCFEntities) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) CasePersonDto(de.symeda.sormas.api.caze.CasePersonDto) PersonDto(de.symeda.sormas.api.person.PersonDto) UserDto(de.symeda.sormas.api.user.UserDto) Date(java.util.Date) LocalDate(java.time.LocalDate) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) Test(org.junit.Test)

Example 38 with UserDto

use of de.symeda.sormas.api.user.UserDto in project SORMAS-Project by hzi-braunschweig.

the class CasePartialUpdateTest method testSetValueWhenNullBefore.

@Test
public void testSetValueWhenNullBefore() throws JsonProcessingException {
    TestDataCreator.RDCFEntities rdcf = creator.createRDCFEntities("Region", "District", "Community", "Facility");
    UserDto user = creator.createUser(rdcf.region.getUuid(), rdcf.district.getUuid(), rdcf.facility.getUuid(), "Surv", "Sup", UserRole.SURVEILLANCE_SUPERVISOR);
    PersonDto cazePerson = creator.createPerson("Case", "Person");
    CaseDataDto caze = creator.createCase(user.toReference(), cazePerson.toReference(), Disease.EVD, CaseClassification.PROBABLE, InvestigationStatus.PENDING, new Date(), rdcf);
    assertNull(caze.getSymptoms().getAbdominalPain());
    caze.getSymptoms().setAbdominalPain(SymptomState.YES);
    ObjectMapper mapper = new ObjectMapper();
    JsonNode caseJson = mapper.convertValue(caze, JsonNode.class);
    // check if the symptoms are the same in the converted json
    SymptomsDto symptomsDto = mapper.treeToValue(caseJson.get("symptoms"), SymptomsDto.class);
    assertEquals(symptomsDto, caze.getSymptoms());
    ((ObjectNode) caseJson).remove("caseClassification");
    ((ObjectNode) caseJson).remove("district");
    ((ObjectNode) caseJson).remove("community");
    ((ObjectNode) caseJson).remove("healthFacility");
    ((ObjectNode) caseJson).remove("epiData");
    ((ObjectNode) caseJson).remove("surveillanceOfficer");
    // check if the symptoms was updated
    CaseDataDto casePostUpdated = getCaseFacade().postUpdate(caze.getUuid(), caseJson);
    SymptomsDto symptomsDtoPostUpdate = mapper.treeToValue(caseJson.get("symptoms"), SymptomsDto.class);
    assertEquals(symptomsDtoPostUpdate, casePostUpdated.getSymptoms());
    casePostUpdated.getSymptoms().setVomiting(SymptomState.YES);
    JsonNode caseUpdatedJson = mapper.convertValue(casePostUpdated, JsonNode.class);
    assertFalse(caseJson.get("symptoms").get("abdominalPain").isNull());
    ((ObjectNode) caseJson.get("symptoms")).remove("abdominalPain");
    assertFalse(caseJson.get("symptoms").isNull());
    assertNull(caseJson.get("symptoms").get("abdominalPain"));
    CaseDataDto casePostUpdatedSymptoms = getCaseFacade().postUpdate(caze.getUuid(), caseUpdatedJson);
    assertEquals(casePostUpdated.getSymptoms(), casePostUpdatedSymptoms.getSymptoms());
}
Also used : SymptomsDto(de.symeda.sormas.api.symptoms.SymptomsDto) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) PersonDto(de.symeda.sormas.api.person.PersonDto) UserDto(de.symeda.sormas.api.user.UserDto) TestDataCreator(de.symeda.sormas.backend.TestDataCreator) JsonNode(com.fasterxml.jackson.databind.JsonNode) Date(java.util.Date) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) Test(org.junit.Test)

Example 39 with UserDto

use of de.symeda.sormas.api.user.UserDto in project SORMAS-Project by hzi-braunschweig.

the class CasePartialUpdateTest method testResetValue.

@Test
public void testResetValue() {
    TestDataCreator.RDCFEntities rdcf = creator.createRDCFEntities("Region", "District", "Community", "Facility");
    UserDto user = creator.createUser(rdcf.region.getUuid(), rdcf.district.getUuid(), rdcf.facility.getUuid(), "Surv", "Sup", UserRole.SURVEILLANCE_SUPERVISOR);
    PersonDto cazePerson = creator.createPerson("Case", "Person");
    CaseDataDto caze = creator.createCase(user.toReference(), cazePerson.toReference(), Disease.EVD, CaseClassification.PROBABLE, InvestigationStatus.PENDING, new Date(), rdcf);
    caze.setCaseOrigin(CaseOrigin.IN_COUNTRY);
    caze.setAdditionalDetails("additional details");
    caze = getCaseFacade().save(caze);
    ObjectMapper mapper = new ObjectMapper();
    JsonNode caseJson = mapper.convertValue(caze, JsonNode.class);
    // check if the reference person uuid is the same in the converted json
    CaseOrigin actualCaseOrigin = Enum.valueOf(CaseOrigin.class, caseJson.get("caseOrigin").textValue());
    String actualAdditionalDetails = caseJson.get("additionalDetails").textValue();
    assertEquals(CaseOrigin.IN_COUNTRY, actualCaseOrigin);
    assertEquals(caze.getAdditionalDetails(), actualAdditionalDetails);
    ((ObjectNode) caseJson).putNull("caseOrigin");
    ((ObjectNode) caseJson).putNull("additionalDetails");
    assertTrue(caseJson.get("caseOrigin").isNull());
    assertTrue(caseJson.get("additionalDetails").isNull());
    // remove from json some nodes
    ((ObjectNode) caseJson).remove("caseClassification");
    ((ObjectNode) caseJson).remove("district");
    ((ObjectNode) caseJson).remove("community");
    ((ObjectNode) caseJson).remove("healthFacility");
    ((ObjectNode) caseJson).remove("epiData");
    ((ObjectNode) caseJson).remove("surveillanceOfficer");
    ((ObjectNode) caseJson).remove("symptoms");
    assertNull(caseJson.get("caseClassification"));
    // call the partial update
    CaseDataDto casePostUpdated = getCaseFacade().postUpdate(caze.getUuid(), caseJson);
    // check if the fields has been set to null
    assertNull(casePostUpdated.getAdditionalDetails());
    assertNull(casePostUpdated.getCaseOrigin());
    // check if the fields that were not in the json file has not be deleted
    assertEquals(CaseClassification.PROBABLE, caze.getCaseClassification());
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) PersonDto(de.symeda.sormas.api.person.PersonDto) UserDto(de.symeda.sormas.api.user.UserDto) TestDataCreator(de.symeda.sormas.backend.TestDataCreator) JsonNode(com.fasterxml.jackson.databind.JsonNode) Date(java.util.Date) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) CaseOrigin(de.symeda.sormas.api.caze.CaseOrigin) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) Test(org.junit.Test)

Example 40 with UserDto

use of de.symeda.sormas.api.user.UserDto in project SORMAS-Project by hzi-braunschweig.

the class CasePartialUpdateTest method testDiseaseChangePartialUpdates.

@Test
public void testDiseaseChangePartialUpdates() {
    TestDataCreator.RDCFEntities rdcf = creator.createRDCFEntities("Region", "District", "Community", "Facility");
    UserDto user = creator.createUser(rdcf.region.getUuid(), rdcf.district.getUuid(), rdcf.facility.getUuid(), "Surv", "Sup", UserRole.SURVEILLANCE_SUPERVISOR);
    PersonDto cazePerson = creator.createPerson("Case", "Person");
    CaseDataDto caze = creator.createCase(user.toReference(), cazePerson.toReference(), Disease.EVD, CaseClassification.PROBABLE, InvestigationStatus.PENDING, new Date(), rdcf);
    ObjectMapper mapper = new ObjectMapper();
    JsonNode caseJson = mapper.convertValue(caze, JsonNode.class);
    // check if the disease is the same in the converted json
    Disease actualDisease = Enum.valueOf(Disease.class, caseJson.get("disease").textValue());
    assertEquals(Disease.EVD, actualDisease);
    // change the disease in the caze and convert to json
    // check if the disease in json reflects the modification
    caze.setDisease(Disease.MEASLES);
    caseJson = mapper.convertValue(caze, JsonNode.class);
    actualDisease = Enum.valueOf(Disease.class, caseJson.get("disease").textValue());
    assertEquals(Disease.MEASLES, actualDisease);
    // remove from json some nodes such as person, region, etc to simulate a partial json
    ((ObjectNode) caseJson).remove("person");
    ((ObjectNode) caseJson).remove("region");
    ((ObjectNode) caseJson).remove("district");
    ((ObjectNode) caseJson).remove("community");
    ((ObjectNode) caseJson).remove("healthFacility");
    ((ObjectNode) caseJson).remove("epiData");
    ((ObjectNode) caseJson).remove("surveillanceOfficer");
    ((ObjectNode) caseJson).remove("symptoms");
    // call the partial update
    CaseDataDto casePostUpdated = getCaseFacade().postUpdate(caze.getUuid(), caseJson);
    // check if the disease was changed
    assertEquals(Disease.MEASLES, casePostUpdated.getDisease());
    // check if the fields that were not in the json file has not be deleted
    assertEquals(cazePerson.toReference(), casePostUpdated.getPerson());
}
Also used : Disease(de.symeda.sormas.api.Disease) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) PersonDto(de.symeda.sormas.api.person.PersonDto) UserDto(de.symeda.sormas.api.user.UserDto) TestDataCreator(de.symeda.sormas.backend.TestDataCreator) JsonNode(com.fasterxml.jackson.databind.JsonNode) Date(java.util.Date) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) Test(org.junit.Test)

Aggregations

UserDto (de.symeda.sormas.api.user.UserDto)274 Test (org.junit.Test)210 AbstractBeanTest (de.symeda.sormas.backend.AbstractBeanTest)160 PersonDto (de.symeda.sormas.api.person.PersonDto)142 Date (java.util.Date)138 CaseDataDto (de.symeda.sormas.api.caze.CaseDataDto)121 RDCFEntities (de.symeda.sormas.backend.TestDataCreator.RDCFEntities)64 ContactDto (de.symeda.sormas.api.contact.ContactDto)57 LocalDate (java.time.LocalDate)57 RDCF (de.symeda.sormas.backend.TestDataCreator.RDCF)56 EventDto (de.symeda.sormas.api.event.EventDto)52 TestDataCreator (de.symeda.sormas.backend.TestDataCreator)47 RegionReferenceDto (de.symeda.sormas.api.infrastructure.region.RegionReferenceDto)43 AbstractBeanTest (de.symeda.sormas.ui.AbstractBeanTest)43 SampleDto (de.symeda.sormas.api.sample.SampleDto)41 File (java.io.File)41 TestDataCreator (de.symeda.sormas.ui.TestDataCreator)31 EventParticipantDto (de.symeda.sormas.api.event.EventParticipantDto)30 CasePersonDto (de.symeda.sormas.api.caze.CasePersonDto)27 ImportResultStatus (de.symeda.sormas.ui.importer.ImportResultStatus)27