HospitalModel { @Nullable public HospitalContactData queryHospitalData(@NotNull String sampleId, @NotNull String coreRequesterName, @NotNull String coreRequesterEmail) { String hospitalId = getHospitalIdForSample(sampleId); if (hospitalId == null) { return null; } HospitalAddress address = hospitalAddressMap().get(hospitalId); LimsStudy study = LimsStudy.fromSampleId(sampleId); HospitalPersons persons = findPersonsForStudy(hospitalId, study); if (address == null || (persons == null && (study == LimsStudy.CPCT || study == LimsStudy.WIDE || study == LimsStudy.DRUP))) { return null; } String requesterName = null; String requesterEmail = null; if (study == LimsStudy.CORE) { requesterName = coreRequesterName; requesterEmail = coreRequesterEmail; } else if (persons != null) { requesterName = persons.requesterName(); requesterEmail = persons.requesterEmail(); } return ImmutableHospitalContactData.builder() .hospitalPI(persons != null ? persons.hospitalPI() : Lims.NOT_AVAILABLE_STRING) .requesterName(requesterName != null ? requesterName : Lims.NOT_AVAILABLE_STRING) .requesterEmail(requesterEmail != null ? requesterEmail : Lims.NOT_AVAILABLE_STRING) .hospitalName(address.hospitalName()) .hospitalAddress(address.hospitalZip() + " " + address.hospitalCity()) .build(); }  @Nullable HospitalContactData queryHospitalData(@NotNull String sampleId, @NotNull String coreRequesterName,
            @NotNull String coreRequesterEmail);  }
@Test public void canExtractHospitalDataFromHospitalModel() { String hospitalId = "01"; HospitalModel model = buildTestHospitalModel(hospitalId); HospitalContactData dataCPCT = model.queryHospitalData("CPCT02010001T", CORE_REQUESTER_NAME, CORE_REQUESTER_EMAIL); assertEquals(CPCT_PI, dataCPCT.hospitalPI()); assertEquals(Lims.NOT_AVAILABLE_STRING, dataCPCT.requesterName()); assertEquals(Lims.NOT_AVAILABLE_STRING, dataCPCT.requesterEmail()); assertEquals(HOSPITAL_NAME, dataCPCT.hospitalName()); assertEquals(EXPECTED_HOSPITAL_ADDRESS, dataCPCT.hospitalAddress()); HospitalContactData dataDRUP = model.queryHospitalData("DRUP02010001T", CORE_REQUESTER_NAME, CORE_REQUESTER_EMAIL); assertEquals(DRUP_PI, dataDRUP.hospitalPI()); assertEquals(Lims.NOT_AVAILABLE_STRING, dataDRUP.requesterName()); assertEquals(Lims.NOT_AVAILABLE_STRING, dataDRUP.requesterEmail()); assertEquals(HOSPITAL_NAME, dataDRUP.hospitalName()); assertEquals(EXPECTED_HOSPITAL_ADDRESS, dataDRUP.hospitalAddress()); HospitalContactData dataWIDE = model.queryHospitalData("WIDE02010001T", CORE_REQUESTER_NAME, CORE_REQUESTER_EMAIL); assertEquals(WIDE_PI, dataWIDE.hospitalPI()); assertEquals(WIDE_REQUESTER_NAME, dataWIDE.requesterName()); assertEquals(WIDE_REQUESTER_EMAIL, dataWIDE.requesterEmail()); assertEquals(HOSPITAL_NAME, dataWIDE.hospitalName()); assertEquals(EXPECTED_HOSPITAL_ADDRESS, dataWIDE.hospitalAddress()); HospitalContactData dataCORE = model.queryHospitalData("CORE02010001T", CORE_REQUESTER_NAME, CORE_REQUESTER_EMAIL); assertEquals(Lims.NOT_AVAILABLE_STRING, dataCORE.hospitalPI()); assertEquals(CORE_REQUESTER_NAME, dataCORE.requesterName()); assertEquals(CORE_REQUESTER_EMAIL, dataCORE.requesterEmail()); assertEquals(HOSPITAL_NAME, dataCORE.hospitalName()); assertEquals(EXPECTED_HOSPITAL_ADDRESS, dataCORE.hospitalAddress()); HospitalContactData dataCOREManuallyMapped = model.queryHospitalData(MANUALLY_MAPPED_CORE_SAMPLE, CORE_REQUESTER_NAME, CORE_REQUESTER_EMAIL); assertEquals(Lims.NOT_AVAILABLE_STRING, dataCOREManuallyMapped.hospitalPI()); assertEquals(CORE_REQUESTER_NAME, dataCOREManuallyMapped.requesterName()); assertEquals(CORE_REQUESTER_EMAIL, dataCOREManuallyMapped.requesterEmail()); assertEquals(HOSPITAL_NAME, dataCOREManuallyMapped.hospitalName()); assertEquals(EXPECTED_HOSPITAL_ADDRESS, dataCOREManuallyMapped.hospitalAddress()); HospitalContactData dataSampleDoesNotExist = model.queryHospitalData("I Don't exist", CORE_REQUESTER_NAME, CORE_REQUESTER_EMAIL); assertNull(dataSampleDoesNotExist); HospitalContactData dataHospitalDoesNotExist = model.queryHospitalData("CPCT02020202T", CORE_REQUESTER_NAME, CORE_REQUESTER_EMAIL); assertNull(dataHospitalDoesNotExist); }