Skip to content

Commit

Permalink
model supports multiple providers and default provider
Browse files Browse the repository at this point in the history
  • Loading branch information
mehansen committed Nov 5, 2024
1 parent 87711d4 commit 4a95cda
Show file tree
Hide file tree
Showing 16 changed files with 138 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public List<DeviceType> getDeviceTypes() {
}

public ApiProvider getOrderingProvider() {
return Optional.ofNullable(getWrapped().getOrderingProvider())
return Optional.ofNullable(getWrapped().getDefaultOrderingProvider())
.map(ApiProvider::new)
.orElse(null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,24 @@ public PxpVerifyResponseV2(Person person, TestEvent testEvent) {
.orderingProvider(
Facility.OrderingProvider.builder()
.firstName(
testEvent.getFacility().getOrderingProvider().getNameInfo().getFirstName())
testEvent
.getFacility()
.getDefaultOrderingProvider()
.getNameInfo()
.getFirstName())
.middleName(
testEvent.getFacility().getOrderingProvider().getNameInfo().getMiddleName())
testEvent
.getFacility()
.getDefaultOrderingProvider()
.getNameInfo()
.getMiddleName())
.lastName(
testEvent.getFacility().getOrderingProvider().getNameInfo().getLastName())
.npi(testEvent.getFacility().getOrderingProvider().getProviderId())
testEvent
.getFacility()
.getDefaultOrderingProvider()
.getNameInfo()
.getLastName())
.npi(testEvent.getFacility().getDefaultOrderingProvider().getProviderId())
.build())
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public Facility makeRealFacility(
.facilityAddress(getAddress())
.phone(getTelephone())
.email(getEmail())
.orderingProvider(provider)
.defaultOrderingProvider(provider)
.defaultDeviceType(defaultDeviceType)
.defaultSpecimenType(defaultSpecimenType)
.configuredDevices(configured)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import jakarta.persistence.JoinTable;
import jakarta.persistence.ManyToMany;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
Expand All @@ -33,10 +34,9 @@ public class Facility extends OrganizationScopedEternalEntity implements Located
@Column @Getter @Setter private String cliaNumber;

@ManyToOne(optional = false)
@JoinColumn(name = "ordering_provider_id", nullable = false)
@JoinColumn(name = "default_ordering_provider_id", nullable = false)
@Getter
@Setter
private Provider orderingProvider;
private Provider defaultOrderingProvider;

@ManyToOne(optional = true, fetch = FetchType.EAGER)
@JoinColumn(name = "default_device_type_id")
Expand All @@ -55,6 +55,13 @@ public class Facility extends OrganizationScopedEternalEntity implements Located
inverseJoinColumns = @JoinColumn(name = "device_type_id"))
private Set<DeviceType> configuredDeviceTypes = new HashSet<>();

@OneToMany
@JoinTable(
name = "facility_providers",
joinColumns = @JoinColumn(name = "facility_id"),
inverseJoinColumns = @JoinColumn(name = "provider_id"))
private Set<Provider> orderingProviders = new HashSet<>();

protected Facility() {
/* for hibernate */ }

Expand All @@ -65,7 +72,8 @@ public Facility(FacilityBuilder facilityBuilder) {
this.address = facilityBuilder.facilityAddress;
this.telephone = facilityBuilder.phone;
this.email = facilityBuilder.email;
this.orderingProvider = facilityBuilder.orderingProvider;
this.defaultOrderingProvider = facilityBuilder.defaultOrderingProvider;
this.orderingProviders.add(facilityBuilder.defaultOrderingProvider);
this.configuredDeviceTypes.addAll(facilityBuilder.configuredDevices);
this.setDefaultDeviceTypeSpecimenType(
facilityBuilder.defaultDeviceType, facilityBuilder.defaultSpecimenType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class FacilityBuilder {
StreetAddress facilityAddress;
String phone;
String email;
Provider orderingProvider;
Provider defaultOrderingProvider;
DeviceType defaultDeviceType;
SpecimenType defaultSpecimenType;
List<DeviceType> configuredDevices;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public TestEvent(TestOrder order, Boolean hasPriorTests) {
Hibernate.initialize(getPatient().getPhoneNumbers());

this.patientData = getPatient();
this.providerData = getFacility().getOrderingProvider();
this.providerData = getFacility().getDefaultOrderingProvider();
this.order = order;
this.patientHasPriorTests = hasPriorTests;
setDateTestedBackdate(order.getDateTestedBackdate());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ public Facility updateFacility(
facility.setEmail(email);
facility.setAddress(facilityAddress);

Provider p = facility.getOrderingProvider();
Provider p = facility.getDefaultOrderingProvider();
p.getNameInfo().setFirstName(orderingProviderName.getFirstName());
p.getNameInfo().setMiddleName(orderingProviderName.getMiddleName());
p.getNameInfo().setLastName(orderingProviderName.getLastName());
Expand Down Expand Up @@ -421,7 +421,7 @@ private Facility createFacilityNoPermissions(
.facilityAddress(facilityAddress)
.phone(phone)
.email(email)
.orderingProvider(orderingProvider)
.defaultOrderingProvider(orderingProvider)
.configuredDevices(configuredDevices)
.build());
facility = facilityRepository.save(facility);
Expand Down
59 changes: 56 additions & 3 deletions backend/src/main/resources/db/changelog/db.changelog-master.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5626,7 +5626,6 @@ databaseChangeLog:
references: role
- sql: |
GRANT SELECT ON ${database.defaultSchemaName}.api_user_role TO ${noPhiUsername};
- changeSet:
id: add-timer-started-at-to-test_order-table
author: [email protected]
Expand All @@ -5643,7 +5642,6 @@ databaseChangeLog:
- dropColumn:
tableName: test_order
columnName: timer_started_at

- changeSet:
id: add-hepatitis-c-to-supported_disease-table
author: [email protected]
Expand All @@ -5661,4 +5659,59 @@ databaseChangeLog:
(gen_random_uuid(), 'Hepatitis-C', 'LP14400-3')
rollback:
- sql:
sql: DELETE FROM ${database.defaultSchemaName}.supported_disease WHERE name = 'Hepatitis-C';
sql: DELETE FROM ${database.defaultSchemaName}.supported_disease WHERE name = 'Hepatitis-C';
- changeSet:
id: create-facility_providers-table
author: [email protected]
changes:
- tagDatabase:
tag: add-facility-providers-table
- createTable:
tableName: facility_providers
remarks: Join table for mapping multiple providers to a facility.
columns:
- column:
name: facility_id
type: uuid
constraints:
nullable: false
foreignKeyName: fk__facility_providers__facility
references: facility
- column:
name: provider_id
type: uuid
constraints:
nullable: false
foreignKeyName: fk__facility_providers__provider
references: provider
- changeSet:
id: populate-facility-providers-table
author: [email protected]
changes:
- tagDatabase:
tag: populate-facility-providers-table
- sql:
sql: |
INSERT INTO ${database.defaultSchemaName}.facility_providers (
facility_id,
provider_id
)
SELECT
internal_id,
ordering_provider_id
FROM ${database.defaultSchemaName}.facility;
rollback:
- sql:
sql: |
TRUNCATE TABLE ${database.defaultSchemaName}.facility_providers;
- changeSet:
id: rename-facility-provider-column
author: [email protected]
changes:
- tagDatabase:
tag: rename-facility-provider-column
- renameColumn:
tableName: facility
oldColumnName: ordering_provider_id
newColumnName: default_ordering_provider_id
remarks: The default healthcare provider for tests ordered at this facility.
Original file line number Diff line number Diff line change
Expand Up @@ -1933,7 +1933,7 @@ void createFhirBundle_TestEvent_matchesJson() throws IOException {
.facilityAddress(address)
.phone("7735551234")
.email("[email protected]")
.orderingProvider(provider)
.defaultOrderingProvider(provider)
.defaultDeviceType(deviceType)
.defaultSpecimenType(specimenType)
.configuredDevices(Collections.emptyList())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,18 +110,18 @@ void addFacility_withDeviceIds_success() {
.email(facility.getEmail())
.orderingProvider(
ProviderInput.builder()
.firstName(facility.getOrderingProvider().getNameInfo().getFirstName())
.middleName(facility.getOrderingProvider().getNameInfo().getMiddleName())
.lastName(facility.getOrderingProvider().getNameInfo().getLastName())
.suffix(facility.getOrderingProvider().getNameInfo().getSuffix())
.npi(facility.getOrderingProvider().getProviderId())
.street(facility.getOrderingProvider().getAddress().getStreetOne())
.streetTwo(facility.getOrderingProvider().getAddress().getStreetTwo())
.city(facility.getOrderingProvider().getAddress().getCity())
.county(facility.getOrderingProvider().getAddress().getCounty())
.state(facility.getOrderingProvider().getAddress().getState())
.zipCode(facility.getOrderingProvider().getAddress().getPostalCode())
.phone(facility.getOrderingProvider().getTelephone())
.firstName(facility.getDefaultOrderingProvider().getNameInfo().getFirstName())
.middleName(facility.getDefaultOrderingProvider().getNameInfo().getMiddleName())
.lastName(facility.getDefaultOrderingProvider().getNameInfo().getLastName())
.suffix(facility.getDefaultOrderingProvider().getNameInfo().getSuffix())
.npi(facility.getDefaultOrderingProvider().getProviderId())
.street(facility.getDefaultOrderingProvider().getAddress().getStreetOne())
.streetTwo(facility.getDefaultOrderingProvider().getAddress().getStreetTwo())
.city(facility.getDefaultOrderingProvider().getAddress().getCity())
.county(facility.getDefaultOrderingProvider().getAddress().getCounty())
.state(facility.getDefaultOrderingProvider().getAddress().getState())
.zipCode(facility.getDefaultOrderingProvider().getAddress().getPostalCode())
.phone(facility.getDefaultOrderingProvider().getTelephone())
.build())
.deviceIds(List.of(deviceId))
.build());
Expand All @@ -135,8 +135,8 @@ void addFacility_withDeviceIds_success() {
eq("(555) 867-5309"),
eq("[email protected]"),
deviceIdTypeCaptor.capture(),
eq(facility.getOrderingProvider().getNameInfo()),
eq(facility.getOrderingProvider().getAddress()),
eq(facility.getDefaultOrderingProvider().getNameInfo()),
eq(facility.getDefaultOrderingProvider().getAddress()),
eq("(800) 555-1212"),
eq("DOOOOOOM"));

Expand Down Expand Up @@ -173,18 +173,18 @@ void updateFacility_success() {
.email(facility.getEmail())
.orderingProvider(
ProviderInput.builder()
.firstName(facility.getOrderingProvider().getNameInfo().getFirstName())
.middleName(facility.getOrderingProvider().getNameInfo().getMiddleName())
.lastName(facility.getOrderingProvider().getNameInfo().getLastName())
.suffix(facility.getOrderingProvider().getNameInfo().getSuffix())
.npi(facility.getOrderingProvider().getProviderId())
.street(facility.getOrderingProvider().getAddress().getStreetOne())
.streetTwo(facility.getOrderingProvider().getAddress().getStreetTwo())
.city(facility.getOrderingProvider().getAddress().getCity())
.county(facility.getOrderingProvider().getAddress().getCounty())
.state(facility.getOrderingProvider().getAddress().getState())
.zipCode(facility.getOrderingProvider().getAddress().getPostalCode())
.phone(facility.getOrderingProvider().getTelephone())
.firstName(facility.getDefaultOrderingProvider().getNameInfo().getFirstName())
.middleName(facility.getDefaultOrderingProvider().getNameInfo().getMiddleName())
.lastName(facility.getDefaultOrderingProvider().getNameInfo().getLastName())
.suffix(facility.getDefaultOrderingProvider().getNameInfo().getSuffix())
.npi(facility.getDefaultOrderingProvider().getProviderId())
.street(facility.getDefaultOrderingProvider().getAddress().getStreetOne())
.streetTwo(facility.getDefaultOrderingProvider().getAddress().getStreetTwo())
.city(facility.getDefaultOrderingProvider().getAddress().getCity())
.county(facility.getDefaultOrderingProvider().getAddress().getCounty())
.state(facility.getDefaultOrderingProvider().getAddress().getState())
.zipCode(facility.getDefaultOrderingProvider().getAddress().getPostalCode())
.phone(facility.getDefaultOrderingProvider().getTelephone())
.build())
.deviceIds(List.of(deviceId))
.build());
Expand All @@ -198,8 +198,8 @@ void updateFacility_success() {
eq(facility.getAddress()),
eq("(555) 867-5309"),
eq("[email protected]"),
eq(facility.getOrderingProvider().getNameInfo()),
eq(facility.getOrderingProvider().getAddress()),
eq(facility.getDefaultOrderingProvider().getNameInfo()),
eq(facility.getDefaultOrderingProvider().getAddress()),
eq("DOOOOOOM"),
eq("(800) 555-1212"),
deviceIdTypeCaptor.capture());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ void serialize_withFacility_noOrgOrFacility() throws IOException {
.facilityAddress(addy)
.phone("555-867-5309")
.email("[email protected]")
.orderingProvider(mccoy)
.defaultOrderingProvider(mccoy)
.defaultDeviceType(device)
.defaultSpecimenType(specimenType)
.configuredDevices(List.of(device))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ void smokeTestDeviceOperations() {
.facilityAddress(getAddress())
.phone("555-867-5309")
.email("[email protected]")
.orderingProvider(mccoy)
.defaultOrderingProvider(mccoy)
.defaultDeviceType(bill)
.defaultSpecimenType(spec)
.configuredDevices(configuredDevices)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -536,15 +536,16 @@ void updateFacilityTest() {
assertThat(updatedFacility.getEmail()).isEqualTo("[email protected]");
assertThat(updatedFacility.getAddress()).isEqualTo(newFacilityAddress);

assertThat(updatedFacility.getOrderingProvider().getNameInfo().getFirstName())
assertThat(updatedFacility.getDefaultOrderingProvider().getNameInfo().getFirstName())
.isEqualTo("Bill");
assertThat(updatedFacility.getOrderingProvider().getNameInfo().getMiddleName())
assertThat(updatedFacility.getDefaultOrderingProvider().getNameInfo().getMiddleName())
.isEqualTo("Foo");
assertThat(updatedFacility.getOrderingProvider().getNameInfo().getLastName())
assertThat(updatedFacility.getDefaultOrderingProvider().getNameInfo().getLastName())
.isEqualTo("Nye");
assertThat(updatedFacility.getOrderingProvider().getNameInfo().getSuffix()).isEqualTo("Jr.");
assertThat(updatedFacility.getOrderingProvider().getProviderId()).isEqualTo("npi");
assertThat(updatedFacility.getOrderingProvider().getAddress())
assertThat(updatedFacility.getDefaultOrderingProvider().getNameInfo().getSuffix())
.isEqualTo("Jr.");
assertThat(updatedFacility.getDefaultOrderingProvider().getProviderId()).isEqualTo("npi");
assertThat(updatedFacility.getDefaultOrderingProvider().getAddress())
.isEqualTo(newOrderingProviderAddress);

assertThat(updatedFacility.getDeviceTypes()).hasSize(2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1556,10 +1556,10 @@ void markAsErrorTest_usesCorrectDeviceAndSpecimenFacilityHasBeenUpdated() {
facility.getAddress(),
facility.getTelephone(),
facility.getEmail(),
facility.getOrderingProvider().getNameInfo(),
facility.getOrderingProvider().getAddress(),
facility.getOrderingProvider().getProviderId(),
facility.getOrderingProvider().getTelephone(),
facility.getDefaultOrderingProvider().getNameInfo(),
facility.getDefaultOrderingProvider().getAddress(),
facility.getDefaultOrderingProvider().getProviderId(),
facility.getDefaultOrderingProvider().getTelephone(),
facility.getDeviceTypes().stream().map(IdentifiedEntity::getInternalId).toList());

String reasonMsg = "Testing correction marking as error " + LocalDateTime.now();
Expand Down Expand Up @@ -1825,10 +1825,10 @@ void correctTest_usesCorrectDeviceAndSpecimenFacilityHasBeenUpdated() {
facility.getAddress(),
facility.getTelephone(),
facility.getEmail(),
facility.getOrderingProvider().getNameInfo(),
facility.getOrderingProvider().getAddress(),
facility.getOrderingProvider().getProviderId(),
facility.getOrderingProvider().getTelephone(),
facility.getDefaultOrderingProvider().getNameInfo(),
facility.getDefaultOrderingProvider().getAddress(),
facility.getDefaultOrderingProvider().getProviderId(),
facility.getDefaultOrderingProvider().getTelephone(),
facility.getDeviceTypes().stream().map(IdentifiedEntity::getInternalId).toList());

// Re-open the original test as a correction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ public static Facility createFacility() {
.facilityAddress(getAddress())
.phone("555-867-5309")
.email("[email protected]")
.orderingProvider(doc)
.defaultOrderingProvider(doc)
.defaultDeviceType(deviceType)
.defaultSpecimenType(specimenType)
.configuredDevices(List.of(deviceType))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ public Facility createValidFacility(
.facilityAddress(facilityStreetAddress)
.phone("555-867-5309")
.email("[email protected]")
.orderingProvider(doc)
.defaultOrderingProvider(doc)
.defaultDeviceType(defaultDevice)
.defaultSpecimenType(defaultSpecimen)
.configuredDevices(configuredDevices)
Expand Down

0 comments on commit 4a95cda

Please sign in to comment.