SormasToSormasFacadeEjb implements SormasToSormasFacade { @Override @Transactional public void saveSharedCase(SormasToSormasEncryptedDataDto encryptedData) throws SormasToSormasException { SormasToSormasCaseDto shareCaseDto = decryptSharedData(encryptedData, SormasToSormasCaseDto.class); PersonDto person = shareCaseDto.getPerson(); CaseDataDto caze = shareCaseDto.getCaze(); List<SormasToSormasCaseDto.AssociatedContactDto> associatedContacts = shareCaseDto.getAssociatedContacts(); SormasToSormasOriginInfoDto originInfo = shareCaseDto.getOriginInfo(); validateCase(caze); processOriginInfo(originInfo); processCaseData(caze, person, associatedContacts, originInfo); personFacade.savePerson(person); CaseDataDto savedCase = caseFacade.saveCase(caze); if (associatedContacts != null) { associatedContacts.forEach(associatedContact -> { personFacade.savePerson(associatedContact.getPerson()); ContactDto contact = associatedContact.getContact(); contact.setSormasToSormasOriginInfo(savedCase.getSormasToSormasOriginInfo()); contactFacade.saveContact(contact); }); } } SormasToSormasFacadeEjb(); @Override @Transactional void saveSharedCase(SormasToSormasEncryptedDataDto encryptedData); @Override @Transactional void saveSharedContact(SormasToSormasEncryptedDataDto sharedData); @Override void shareCase(String uuid, SormasToSormasOptionsDto options); @Override void shareContact(String uuid, SormasToSormasOptionsDto options); @Override List<ServerAccessDataReferenceDto> getAvailableOrganizations(); @Override List<SormasToSormasShareInfoDto> getShareInfoIndexList(SormasToSormasShareInfoCriteria criteria, Integer first, Integer max); @Override boolean isFeatureEnabled(); @Override ServerAccessDataReferenceDto getOrganizationRef(String id); SormasToSormasOriginInfo fromSormasToSormasOriginInfoDto(SormasToSormasOriginInfoDto source); static SormasToSormasOriginInfoDto toSormasToSormasOriginInfoDto(SormasToSormasOriginInfo source); SormasToSormasShareInfoDto toSormasToSormasShareInfoDto(SormasToSormasShareInfo source); static final String SAVE_SHARED_CASE_ENDPOINT; }
@Test public void testSaveSharedCase() throws JsonProcessingException, SormasToSormasException { MappableRdcf rdcf = createRDCF(); PersonDto person = createPersonDto(rdcf); person.setFirstName("James"); person.setLastName("Smith"); CaseDataDto caze = createRemoteCaseDto(rdcf, person); caze.getHospitalization().setAdmittedToHealthFacility(YesNoUnknown.YES); caze.getSymptoms().setAgitation(SymptomState.YES); caze.getEpiData().setKindOfExposureTouch(YesNoUnknown.YES); caze.getClinicalCourse().getHealthConditions().setAsplenia(YesNoUnknown.YES); caze.getMaternalHistory().setChildrenNumber(2); byte[] encryptedData = encryptShareData(new SormasToSormasCaseDto(person, caze, createSormasToSormasOriginInfo())); getSormasToSormasFacade().saveSharedCase(new SormasToSormasEncryptedDataDto(DEFAULT_SERVER_ACCESS_CN, encryptedData)); CaseDataDto savedCase = getCaseFacade().getCaseDataByUuid(caze.getUuid()); assertThat(savedCase, is(notNullValue())); assertThat(savedCase.getRegion(), is(rdcf.localRdcf.region)); assertThat(savedCase.getDistrict(), is(rdcf.localRdcf.district)); assertThat(savedCase.getCommunity(), is(rdcf.localRdcf.community)); assertThat(savedCase.getHealthFacility(), is(rdcf.localRdcf.facility)); assertThat(savedCase.getHospitalization().getAdmittedToHealthFacility(), is(YesNoUnknown.YES)); assertThat(savedCase.getSymptoms().getAgitation(), is(SymptomState.YES)); assertThat(savedCase.getEpiData().getKindOfExposureTouch(), is(YesNoUnknown.YES)); assertThat(savedCase.getClinicalCourse().getHealthConditions().getAsplenia(), is(YesNoUnknown.YES)); assertThat(savedCase.getMaternalHistory().getChildrenNumber(), is(2)); assertThat(savedCase.getSormasToSormasOriginInfo().getOrganizationId(), is("testHealthDep")); assertThat(savedCase.getSormasToSormasOriginInfo().getSenderName(), is("John doe")); PersonDto savedPerson = getPersonFacade().getPersonByUuid(savedCase.getPerson().getUuid()); assertThat(savedPerson, is(notNullValue())); assertThat(savedPerson.getAddress().getRegion(), is(rdcf.localRdcf.region)); assertThat(savedPerson.getAddress().getDistrict(), is(rdcf.localRdcf.district)); assertThat(savedPerson.getAddress().getCommunity(), is(rdcf.localRdcf.community)); assertThat(savedPerson.getFirstName(), is("James")); assertThat(savedPerson.getLastName(), is("Smith")); }