@Test public void testGetPatientLatestEncounterNoStart() { expectedException.expect(SystemException.class); expectedException.expectMessage( "FHIR validation failed - Encounter.Period.Start is mandatory"); final Bundle result = new Bundle(); final Bundle.Entry entry = getEncounterResultBundleEntry( "encounter1", "patient1", EncounterClassEnum.INPATIENT, EncounterStateEnum.IN_PROGRESS, null, null, null, null, null, null); result.addEntry(entry); mockFhirClientResult(result); fhirEncounterProvider.getPatientLatestEncounter("patient1"); }
@Override public EncounterDto getPatientLatestEncounter(@Nonnull final String patientId) { Preconditions.checkArgument(StringUtils.isNotBlank(patientId), "patientId must not be blank"); final Bundle result; try { result = fhirClient .search() .forResource(Encounter.class) .include(Encounter.INCLUDE_LOCATION) .include(Encounter.INCLUDE_PRACTITIONER) .where(Encounter.PATIENT.hasChainedProperty( Patient.IDENTIFIER.exactly().identifier(new IdentifierDt(fhirPatientIdSystem, patientId)))) .and(Encounter.STATUS.exactly().identifiers( buildFhirEncounterStatusIdentifiers( EnumSet.of( EncounterStateEnum.ARRIVED, EncounterStateEnum.IN_PROGRESS, EncounterStateEnum.ON_LEAVE, EncounterStateEnum.FINISHED)))) .sort().descending(Encounter.DATE) .count(1) .returnBundle(Bundle.class) .execute(); } catch (final Exception exception) { throw new SystemException( Dictionary.getEntry( "fhir.error.reading.encounter.data", DefinedLocaleHolder.INSTANCE.getCalculatedNotNullLocale()), exception); } return result.getEntry().stream() .filter(e -> e.getResource() instanceof Encounter) .map(e -> getEncounterDto((Encounter)e.getResource(), patientId)) .filter(Objects::nonNull) .findFirst() .orElse(null); }
FhirEncounterProvider implements EncounterProvider { @Override public EncounterDto getPatientLatestEncounter(@Nonnull final String patientId) { Preconditions.checkArgument(StringUtils.isNotBlank(patientId), "patientId must not be blank"); final Bundle result; try { result = fhirClient .search() .forResource(Encounter.class) .include(Encounter.INCLUDE_LOCATION) .include(Encounter.INCLUDE_PRACTITIONER) .where(Encounter.PATIENT.hasChainedProperty( Patient.IDENTIFIER.exactly().identifier(new IdentifierDt(fhirPatientIdSystem, patientId)))) .and(Encounter.STATUS.exactly().identifiers( buildFhirEncounterStatusIdentifiers( EnumSet.of( EncounterStateEnum.ARRIVED, EncounterStateEnum.IN_PROGRESS, EncounterStateEnum.ON_LEAVE, EncounterStateEnum.FINISHED)))) .sort().descending(Encounter.DATE) .count(1) .returnBundle(Bundle.class) .execute(); } catch (final Exception exception) { throw new SystemException( Dictionary.getEntry( "fhir.error.reading.encounter.data", DefinedLocaleHolder.INSTANCE.getCalculatedNotNullLocale()), exception); } return result.getEntry().stream() .filter(e -> e.getResource() instanceof Encounter) .map(e -> getEncounterDto((Encounter)e.getResource(), patientId)) .filter(Objects::nonNull) .findFirst() .orElse(null); } }
FhirEncounterProvider implements EncounterProvider { @Override public EncounterDto getPatientLatestEncounter(@Nonnull final String patientId) { Preconditions.checkArgument(StringUtils.isNotBlank(patientId), "patientId must not be blank"); final Bundle result; try { result = fhirClient .search() .forResource(Encounter.class) .include(Encounter.INCLUDE_LOCATION) .include(Encounter.INCLUDE_PRACTITIONER) .where(Encounter.PATIENT.hasChainedProperty( Patient.IDENTIFIER.exactly().identifier(new IdentifierDt(fhirPatientIdSystem, patientId)))) .and(Encounter.STATUS.exactly().identifiers( buildFhirEncounterStatusIdentifiers( EnumSet.of( EncounterStateEnum.ARRIVED, EncounterStateEnum.IN_PROGRESS, EncounterStateEnum.ON_LEAVE, EncounterStateEnum.FINISHED)))) .sort().descending(Encounter.DATE) .count(1) .returnBundle(Bundle.class) .execute(); } catch (final Exception exception) { throw new SystemException( Dictionary.getEntry( "fhir.error.reading.encounter.data", DefinedLocaleHolder.INSTANCE.getCalculatedNotNullLocale()), exception); } return result.getEntry().stream() .filter(e -> e.getResource() instanceof Encounter) .map(e -> getEncounterDto((Encounter)e.getResource(), patientId)) .filter(Objects::nonNull) .findFirst() .orElse(null); }  }
FhirEncounterProvider implements EncounterProvider { @Override public EncounterDto getPatientLatestEncounter(@Nonnull final String patientId) { Preconditions.checkArgument(StringUtils.isNotBlank(patientId), "patientId must not be blank"); final Bundle result; try { result = fhirClient .search() .forResource(Encounter.class) .include(Encounter.INCLUDE_LOCATION) .include(Encounter.INCLUDE_PRACTITIONER) .where(Encounter.PATIENT.hasChainedProperty( Patient.IDENTIFIER.exactly().identifier(new IdentifierDt(fhirPatientIdSystem, patientId)))) .and(Encounter.STATUS.exactly().identifiers( buildFhirEncounterStatusIdentifiers( EnumSet.of( EncounterStateEnum.ARRIVED, EncounterStateEnum.IN_PROGRESS, EncounterStateEnum.ON_LEAVE, EncounterStateEnum.FINISHED)))) .sort().descending(Encounter.DATE) .count(1) .returnBundle(Bundle.class) .execute(); } catch (final Exception exception) { throw new SystemException( Dictionary.getEntry( "fhir.error.reading.encounter.data", DefinedLocaleHolder.INSTANCE.getCalculatedNotNullLocale()), exception); } return result.getEntry().stream() .filter(e -> e.getResource() instanceof Encounter) .map(e -> getEncounterDto((Encounter)e.getResource(), patientId)) .filter(Objects::nonNull) .findFirst() .orElse(null); }  @Required void setFhirClient(final IGenericClient fhirClient); @Required void setFhirPatientIdSystem(final String fhirPatientIdSystem); @Required void setFhirEncounterIdSystem(final String fhirEncounterIdSystem); @Required void setFhirWardIdSystem(final String fhirWardIdSystem); @Required void setFhirWardLocationPhysicalType(final String fhirWardLocationPhysicalType); @Required void setFhirLocationLocationPhysicalType(final String fhirLocationLocationPhysicalType); @Required void setFhirDoctorParticipantType(final String fhirDoctorParticipantType); @Override EncounterDto getPatientLatestEncounter(@Nonnull final String patientId); @Override List<EncounterDto> getPatientsActiveEncounters(@Nonnull final Collection<String> patientsIds); }
FhirEncounterProvider implements EncounterProvider { @Override public EncounterDto getPatientLatestEncounter(@Nonnull final String patientId) { Preconditions.checkArgument(StringUtils.isNotBlank(patientId), "patientId must not be blank"); final Bundle result; try { result = fhirClient .search() .forResource(Encounter.class) .include(Encounter.INCLUDE_LOCATION) .include(Encounter.INCLUDE_PRACTITIONER) .where(Encounter.PATIENT.hasChainedProperty( Patient.IDENTIFIER.exactly().identifier(new IdentifierDt(fhirPatientIdSystem, patientId)))) .and(Encounter.STATUS.exactly().identifiers( buildFhirEncounterStatusIdentifiers( EnumSet.of( EncounterStateEnum.ARRIVED, EncounterStateEnum.IN_PROGRESS, EncounterStateEnum.ON_LEAVE, EncounterStateEnum.FINISHED)))) .sort().descending(Encounter.DATE) .count(1) .returnBundle(Bundle.class) .execute(); } catch (final Exception exception) { throw new SystemException( Dictionary.getEntry( "fhir.error.reading.encounter.data", DefinedLocaleHolder.INSTANCE.getCalculatedNotNullLocale()), exception); } return result.getEntry().stream() .filter(e -> e.getResource() instanceof Encounter) .map(e -> getEncounterDto((Encounter)e.getResource(), patientId)) .filter(Objects::nonNull) .findFirst() .orElse(null); }  @Required void setFhirClient(final IGenericClient fhirClient); @Required void setFhirPatientIdSystem(final String fhirPatientIdSystem); @Required void setFhirEncounterIdSystem(final String fhirEncounterIdSystem); @Required void setFhirWardIdSystem(final String fhirWardIdSystem); @Required void setFhirWardLocationPhysicalType(final String fhirWardLocationPhysicalType); @Required void setFhirLocationLocationPhysicalType(final String fhirLocationLocationPhysicalType); @Required void setFhirDoctorParticipantType(final String fhirDoctorParticipantType); @Override EncounterDto getPatientLatestEncounter(@Nonnull final String patientId); @Override List<EncounterDto> getPatientsActiveEncounters(@Nonnull final Collection<String> patientsIds);  }