@Test public void testCreateMessageFromCertificate() throws CertificateSenderException { final var subject = ArendeAmne.OVRIGT; final var unitId = "unitId"; final var certificateId = "certificateId"; final var certificateType = "certificateType"; final var messageText = "messageText"; final var patientPersonId = "191212121212"; final var header = "header"; final var signedBy = "signedBy"; final var givenName = "Test"; final var surname = "Testorsson Svensson"; final var careGiverName = "Test Testorsson Svensson"; final var unitName = "unitName"; final var careProviderName = "careProviderName"; final var now = LocalDateTime.now(); Utkast utkast = new Utkast(); utkast.setPatientPersonnummer(Personnummer.createPersonnummer(patientPersonId).get()); final var certificate = mock(Utlatande.class); doReturn(certificateType).when(certificate).getTyp(); doReturn(certificateId).when(certificate).getId(); final var basicData = mock(GrundData.class); doReturn(basicData).when(certificate).getGrundData(); final var patient = mock(Patient.class); doReturn(patient).when(basicData).getPatient(); doReturn(Personnummer.createPersonnummer(patientPersonId).get()).when(patient).getPersonId(); final var createdBy = mock(HoSPersonal.class); doReturn(createdBy).when(basicData).getSkapadAv(); doReturn(signedBy).when(createdBy).getPersonId(); final var unit = mock(Vardenhet.class); doReturn(unit).when(createdBy).getVardenhet(); doReturn(unitId).when(unit).getEnhetsid(); doReturn(unitName).when(unit).getEnhetsnamn(); final var careProvider = mock(Vardgivare.class); doReturn(careProvider).when(unit).getVardgivare(); doReturn(careProviderName).when(careProvider).getVardgivarnamn(); when(hsaEmployeeService.getEmployee(signedBy, null)).thenReturn(createHsaResponse(givenName, surname)); Arende res = ArendeConverter.createMessageFromCertificate(subject, header, messageText, certificate, now, careGiverName, hsaEmployeeService); assertNotNull(res); assertEquals(subject, res.getAmne()); assertEquals(unitId, res.getEnhetId()); assertEquals(unitName, res.getEnhetName()); assertEquals(careProviderName, res.getVardgivareName()); assertEquals(certificateId, res.getIntygsId()); assertEquals(certificateType, res.getIntygTyp()); assertEquals(messageText, res.getMeddelande()); assertNotNull(res.getMeddelandeId()); assertNull(res.getPaminnelseMeddelandeId()); assertEquals(patientPersonId, res.getPatientPersonId()); assertNull(res.getReferensId()); assertEquals(header, res.getRubrik()); assertEquals(now, res.getSenasteHandelse()); assertEquals(now, res.getSkickatTidpunkt()); assertEquals(now, res.getTimestamp()); assertEquals(signedBy, res.getSigneratAv()); assertEquals(givenName + " " + surname, res.getSigneratAvName()); assertNull(res.getSistaDatumForSvar()); assertEquals(FrageStallare.WEBCERT.getKod(), res.getSkickatAv()); assertEquals(Status.PENDING_EXTERNAL_ACTION, res.getStatus()); assertNull(res.getSvarPaId()); assertNull(res.getSvarPaReferens()); assertEquals(Boolean.FALSE, res.getVidarebefordrad()); assertEquals(careGiverName, res.getVardaktorName()); }
public static Arende createMessageFromCertificate(ArendeAmne subject, String header, String messageText, Utlatande certificate, LocalDateTime timestamp, String nameOfCareGiver, HsaEmployeeService hsaEmployeeService) { final var message = new Arende(); message.setStatus(Status.PENDING_EXTERNAL_ACTION); message.setAmne(subject); message.setEnhetId(certificate.getGrundData().getSkapadAv().getVardenhet().getEnhetsid()); message.setEnhetName(certificate.getGrundData().getSkapadAv().getVardenhet().getEnhetsnamn()); message.setVardgivareName(certificate.getGrundData().getSkapadAv().getVardenhet().getVardgivare().getVardgivarnamn()); message.setIntygsId(certificate.getId()); message.setIntygTyp(certificate.getTyp()); message.setMeddelande(messageText); message.setPatientPersonId(certificate.getGrundData().getPatient().getPersonId().getPersonnummer()); message.setRubrik(header); message.setSigneratAv(certificate.getGrundData().getSkapadAv().getPersonId()); message.setSigneratAvName(getNameByHsaId(message.getSigneratAv(), hsaEmployeeService)); decorateOutgoingArende(message, timestamp, nameOfCareGiver); return message; }
ArendeConverter { public static Arende createMessageFromCertificate(ArendeAmne subject, String header, String messageText, Utlatande certificate, LocalDateTime timestamp, String nameOfCareGiver, HsaEmployeeService hsaEmployeeService) { final var message = new Arende(); message.setStatus(Status.PENDING_EXTERNAL_ACTION); message.setAmne(subject); message.setEnhetId(certificate.getGrundData().getSkapadAv().getVardenhet().getEnhetsid()); message.setEnhetName(certificate.getGrundData().getSkapadAv().getVardenhet().getEnhetsnamn()); message.setVardgivareName(certificate.getGrundData().getSkapadAv().getVardenhet().getVardgivare().getVardgivarnamn()); message.setIntygsId(certificate.getId()); message.setIntygTyp(certificate.getTyp()); message.setMeddelande(messageText); message.setPatientPersonId(certificate.getGrundData().getPatient().getPersonId().getPersonnummer()); message.setRubrik(header); message.setSigneratAv(certificate.getGrundData().getSkapadAv().getPersonId()); message.setSigneratAvName(getNameByHsaId(message.getSigneratAv(), hsaEmployeeService)); decorateOutgoingArende(message, timestamp, nameOfCareGiver); return message; } }
ArendeConverter { public static Arende createMessageFromCertificate(ArendeAmne subject, String header, String messageText, Utlatande certificate, LocalDateTime timestamp, String nameOfCareGiver, HsaEmployeeService hsaEmployeeService) { final var message = new Arende(); message.setStatus(Status.PENDING_EXTERNAL_ACTION); message.setAmne(subject); message.setEnhetId(certificate.getGrundData().getSkapadAv().getVardenhet().getEnhetsid()); message.setEnhetName(certificate.getGrundData().getSkapadAv().getVardenhet().getEnhetsnamn()); message.setVardgivareName(certificate.getGrundData().getSkapadAv().getVardenhet().getVardgivare().getVardgivarnamn()); message.setIntygsId(certificate.getId()); message.setIntygTyp(certificate.getTyp()); message.setMeddelande(messageText); message.setPatientPersonId(certificate.getGrundData().getPatient().getPersonId().getPersonnummer()); message.setRubrik(header); message.setSigneratAv(certificate.getGrundData().getSkapadAv().getPersonId()); message.setSigneratAvName(getNameByHsaId(message.getSigneratAv(), hsaEmployeeService)); decorateOutgoingArende(message, timestamp, nameOfCareGiver); return message; } private  ArendeConverter(); }
ArendeConverter { public static Arende createMessageFromCertificate(ArendeAmne subject, String header, String messageText, Utlatande certificate, LocalDateTime timestamp, String nameOfCareGiver, HsaEmployeeService hsaEmployeeService) { final var message = new Arende(); message.setStatus(Status.PENDING_EXTERNAL_ACTION); message.setAmne(subject); message.setEnhetId(certificate.getGrundData().getSkapadAv().getVardenhet().getEnhetsid()); message.setEnhetName(certificate.getGrundData().getSkapadAv().getVardenhet().getEnhetsnamn()); message.setVardgivareName(certificate.getGrundData().getSkapadAv().getVardenhet().getVardgivare().getVardgivarnamn()); message.setIntygsId(certificate.getId()); message.setIntygTyp(certificate.getTyp()); message.setMeddelande(messageText); message.setPatientPersonId(certificate.getGrundData().getPatient().getPersonId().getPersonnummer()); message.setRubrik(header); message.setSigneratAv(certificate.getGrundData().getSkapadAv().getPersonId()); message.setSigneratAvName(getNameByHsaId(message.getSigneratAv(), hsaEmployeeService)); decorateOutgoingArende(message, timestamp, nameOfCareGiver); return message; } private  ArendeConverter(); static Arende convert(SendMessageToCareType request); static void decorateArendeFromUtkast(Arende arende, Utkast utkast, LocalDateTime now, HsaEmployeeService hsaEmployeeService); static void decorateMessageFromCertificate(Arende arende, Utlatande certificate, LocalDateTime timestamp); static Arende createArendeFromUtkast(ArendeAmne amne, String rubrik, String meddelande, Utkast utkast, LocalDateTime now,
        String vardaktorNamn, HsaEmployeeService hsaEmployeeService); static Arende createMessageFromCertificate(ArendeAmne subject, String header, String messageText, Utlatande certificate,
        LocalDateTime timestamp, String nameOfCareGiver, HsaEmployeeService hsaEmployeeService); static Arende createAnswerFromArende(String meddelande, Arende svarPaMeddelande, LocalDateTime now, String vardaktorNamn); static Map<String, String> getNamesByHsaIds(Collection<String> hsaIds, HsaEmployeeService hsaEmployeeService); }
ArendeConverter { public static Arende createMessageFromCertificate(ArendeAmne subject, String header, String messageText, Utlatande certificate, LocalDateTime timestamp, String nameOfCareGiver, HsaEmployeeService hsaEmployeeService) { final var message = new Arende(); message.setStatus(Status.PENDING_EXTERNAL_ACTION); message.setAmne(subject); message.setEnhetId(certificate.getGrundData().getSkapadAv().getVardenhet().getEnhetsid()); message.setEnhetName(certificate.getGrundData().getSkapadAv().getVardenhet().getEnhetsnamn()); message.setVardgivareName(certificate.getGrundData().getSkapadAv().getVardenhet().getVardgivare().getVardgivarnamn()); message.setIntygsId(certificate.getId()); message.setIntygTyp(certificate.getTyp()); message.setMeddelande(messageText); message.setPatientPersonId(certificate.getGrundData().getPatient().getPersonId().getPersonnummer()); message.setRubrik(header); message.setSigneratAv(certificate.getGrundData().getSkapadAv().getPersonId()); message.setSigneratAvName(getNameByHsaId(message.getSigneratAv(), hsaEmployeeService)); decorateOutgoingArende(message, timestamp, nameOfCareGiver); return message; } private  ArendeConverter(); static Arende convert(SendMessageToCareType request); static void decorateArendeFromUtkast(Arende arende, Utkast utkast, LocalDateTime now, HsaEmployeeService hsaEmployeeService); static void decorateMessageFromCertificate(Arende arende, Utlatande certificate, LocalDateTime timestamp); static Arende createArendeFromUtkast(ArendeAmne amne, String rubrik, String meddelande, Utkast utkast, LocalDateTime now,
        String vardaktorNamn, HsaEmployeeService hsaEmployeeService); static Arende createMessageFromCertificate(ArendeAmne subject, String header, String messageText, Utlatande certificate,
        LocalDateTime timestamp, String nameOfCareGiver, HsaEmployeeService hsaEmployeeService); static Arende createAnswerFromArende(String meddelande, Arende svarPaMeddelande, LocalDateTime now, String vardaktorNamn); static Map<String, String> getNamesByHsaIds(Collection<String> hsaIds, HsaEmployeeService hsaEmployeeService);  }