Skip to content

Commit

Permalink
Refactoring of business rules, and bunch of bug fixes (#1188)
Browse files Browse the repository at this point in the history
* api fix

* api changes, and some frontend implementation

* add business rules almost done

* target question added, need some tweaking

* edit almost complete

* rule description now works

* filering of target questions works now

* small fixes for target questions

* api change merge

* merge main

* everything functional

* delete unnecessary files

* some more files deleted

* resolved some more small bugs

* almost done with all bugs

* trying to disable edit button

* complete

* build fail

* build fail
  • Loading branch information
alaapbharadwaj authored Mar 15, 2024
1 parent b9f49e3 commit e54f0b6
Show file tree
Hide file tree
Showing 36 changed files with 2,456 additions and 1,820 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,170 +23,170 @@

public class PatientProfilePhoneChangeSteps {

private final Faker faker = new Faker(new Locale("en-us"));

@Autowired
Available<PatientIdentifier> patients;

@Autowired
PatientPhoneChangeController controller;

@Autowired
EntityManager entityManager;

private NewPatientPhoneInput newRequest;
private UpdatePatientPhoneInput updateRequest;
private DeletePatientPhoneInput deleteRequest;

@Before("@patient-profile-phone-change")
public void reset() {
newRequest = null;
updateRequest = null;
deleteRequest = null;
}

@When("a patient's phone is added")
public void a_patient_phone_is_added() {
long patient = patients.one().id();

newRequest = new NewPatientPhoneInput(
patient,
RandomUtil.getRandomDateInPast(),
RandomUtil.oneFrom("AN", "BP", "CP", "NET", "FAX", "PH"),
RandomUtil.oneFrom("SB", "EC", "H", "MC", "WP", "TMP"),
RandomUtil.getRandomString(),
faker.phoneNumber().cellPhone(),
faker.phoneNumber().extension(),
faker.internet().emailAddress(),
faker.internet().url(),
RandomUtil.getRandomString());

controller.add(newRequest);
}

@Then("the patient has the new phone")
@Transactional
public void the_patient_has_the_new_phone() {
PatientIdentifier patient = this.patients.one();

Person person = this.entityManager.find(Person.class, patient.id());

assertThat(person.phones()).anySatisfy(
actual -> assertThat(actual)
.returns(newRequest.type(), TeleEntityLocatorParticipation::getCd)
.returns(newRequest.use(), TeleEntityLocatorParticipation::getUseCd)
.returns(newRequest.asOf(), TeleEntityLocatorParticipation::getAsOfDate)
.returns(newRequest.comment(), TeleEntityLocatorParticipation::getLocatorDescTxt)
.satisfies(
phone -> assertThat(phone)
.extracting(TeleEntityLocatorParticipation::getId)
.returns(newRequest.patient(), EntityLocatorParticipationId::getEntityUid))
.satisfies(
phone -> assertThat(phone).extracting(TeleEntityLocatorParticipation::getLocator)
.returns(newRequest.countryCode(), TeleLocator::getCntryCd)
.returns(newRequest.number(), TeleLocator::getPhoneNbrTxt)
.returns(newRequest.extension(), TeleLocator::getExtensionTxt)
.returns(newRequest.email(), TeleLocator::getEmailAddress)
.returns(newRequest.url(), TeleLocator::getUrlAddress)));
}

@When("a patient's phone is changed")
@Transactional
public void a_patient_phone_is_changed() {
TeleEntityLocatorParticipation existing = this.entityManager.find(Person.class, patients.one().id())
.phones()
.stream()
.findFirst()
.orElseThrow();

updateRequest = new UpdatePatientPhoneInput(
existing.getId().getEntityUid(),
existing.getId().getLocatorUid(),
RandomUtil.getRandomDateInPast(),
RandomUtil.oneFrom("AN", "BP", "CP", "NET", "FAX", "PH"),
RandomUtil.oneFrom("SB", "EC", "H", "MC", "WP", "TMP"),
RandomUtil.getRandomString(),
faker.phoneNumber().cellPhone(),
faker.phoneNumber().extension(),
faker.internet().emailAddress(),
faker.internet().url(),
RandomUtil.getRandomString());

controller.update(updateRequest);
}

@Then("the patient has the expected phone")
@Transactional
public void the_patient_has_the_expected_phone() {
PatientIdentifier patient = this.patients.one();

Person person = this.entityManager.find(Person.class, patient.id());

assertThat(person.phones()).anySatisfy(
actual -> assertThat(actual)
.returns(updateRequest.type(), TeleEntityLocatorParticipation::getCd)
.returns(updateRequest.use(), TeleEntityLocatorParticipation::getUseCd)
.returns(updateRequest.asOf(), TeleEntityLocatorParticipation::getAsOfDate)
.returns(updateRequest.comment(), TeleEntityLocatorParticipation::getLocatorDescTxt)
.satisfies(
phone -> assertThat(phone)
.extracting(TeleEntityLocatorParticipation::getId)
.returns(updateRequest.patient(), EntityLocatorParticipationId::getEntityUid))
.satisfies(
phone -> assertThat(phone).extracting(TeleEntityLocatorParticipation::getLocator)
.returns(updateRequest.countryCode(), TeleLocator::getCntryCd)
.returns(updateRequest.number(), TeleLocator::getPhoneNbrTxt)
.returns(updateRequest.extension(), TeleLocator::getExtensionTxt)
.returns(updateRequest.email(), TeleLocator::getEmailAddress)
.returns(updateRequest.url(), TeleLocator::getUrlAddress)));
}

@When("a patient's phone is removed")
@Transactional
public void a_patient_phone_is_removed() {

Person patient = this.entityManager.find(Person.class, patients.one().id());

this.deleteRequest = patient.phones()
.stream()
.findFirst()
.map(TeleEntityLocatorParticipation::getId)
.map(id -> new DeletePatientPhoneInput(id.getEntityUid(), id.getLocatorUid()))
.orElseThrow();

this.controller.delete(this.deleteRequest);
}

@Then("the patient does not have the expected phone")
@Transactional
public void the_patient_does_not_have_the_expected_phone() {
PatientIdentifier patient = this.patients.one();

Person actual = this.entityManager.find(Person.class, patient.id());

assertThat(actual.phones())
.noneSatisfy(
phone -> assertThat(phone)
.extracting(TeleEntityLocatorParticipation::getId)
.returns(deleteRequest.patient(), EntityLocatorParticipationId::getEntityUid)
.returns(deleteRequest.id(), EntityLocatorParticipationId::getLocatorUid));
}

@Then("I am unable to add a patient's phone")
public void i_am_unable_to_add_a_patient_ethnicity() {
assertThatThrownBy(() -> controller.add(newRequest))
.isInstanceOf(AccessDeniedException.class);
}

@Then("I am unable to change a patient's phone")
public void i_am_unable_to_change_a_patient_ethnicity() {
assertThatThrownBy(() -> controller.update(updateRequest))
.isInstanceOf(AccessDeniedException.class);
}

@Then("I am unable to remove a patient's phone")
public void i_am_unable_to_remove_a_patient_ethnicity() {
assertThatThrownBy(() -> controller.delete(deleteRequest))
.isInstanceOf(AccessDeniedException.class);
}
private final Faker faker = new Faker(new Locale("en-us"));

@Autowired
Available<PatientIdentifier> patients;

@Autowired
PatientPhoneChangeController controller;

@Autowired
EntityManager entityManager;

private NewPatientPhoneInput newRequest;
private UpdatePatientPhoneInput updateRequest;
private DeletePatientPhoneInput deleteRequest;

@Before("@patient-profile-phone-change")
public void reset() {
newRequest = null;
updateRequest = null;
deleteRequest = null;
}

@When("a patient's phone is added")
public void a_patient_phone_is_added() {
long patient = patients.one().id();

newRequest = new NewPatientPhoneInput(
patient,
RandomUtil.getRandomDateInPast(),
RandomUtil.oneFrom("AN", "BP", "CP", "NET", "FAX", "PH"),
RandomUtil.oneFrom("SB", "EC", "H", "MC", "WP", "TMP"),
RandomUtil.getRandomString(),
faker.phoneNumber().cellPhone(),
faker.phoneNumber().extension(),
faker.internet().emailAddress(),
faker.internet().url(),
RandomUtil.getRandomString(15));

controller.add(newRequest);
}

@Then("the patient has the new phone")
@Transactional
public void the_patient_has_the_new_phone() {
PatientIdentifier patient = this.patients.one();

Person person = this.entityManager.find(Person.class, patient.id());

assertThat(person.phones()).anySatisfy(
actual -> assertThat(actual)
.returns(newRequest.type(), TeleEntityLocatorParticipation::getCd)
.returns(newRequest.use(), TeleEntityLocatorParticipation::getUseCd)
.returns(newRequest.asOf(), TeleEntityLocatorParticipation::getAsOfDate)
.returns(newRequest.comment(), TeleEntityLocatorParticipation::getLocatorDescTxt)
.satisfies(
phone -> assertThat(phone)
.extracting(TeleEntityLocatorParticipation::getId)
.returns(newRequest.patient(), EntityLocatorParticipationId::getEntityUid))
.satisfies(
phone -> assertThat(phone).extracting(TeleEntityLocatorParticipation::getLocator)
.returns(newRequest.countryCode(), TeleLocator::getCntryCd)
.returns(newRequest.number(), TeleLocator::getPhoneNbrTxt)
.returns(newRequest.extension(), TeleLocator::getExtensionTxt)
.returns(newRequest.email(), TeleLocator::getEmailAddress)
.returns(newRequest.url(), TeleLocator::getUrlAddress)));
}

@When("a patient's phone is changed")
@Transactional
public void a_patient_phone_is_changed() {
TeleEntityLocatorParticipation existing = this.entityManager.find(Person.class, patients.one().id())
.phones()
.stream()
.findFirst()
.orElseThrow();

updateRequest = new UpdatePatientPhoneInput(
existing.getId().getEntityUid(),
existing.getId().getLocatorUid(),
RandomUtil.getRandomDateInPast(),
RandomUtil.oneFrom("AN", "BP", "CP", "NET", "FAX", "PH"),
RandomUtil.oneFrom("SB", "EC", "H", "MC", "WP", "TMP"),
RandomUtil.getRandomString(),
faker.phoneNumber().cellPhone(),
faker.phoneNumber().extension(),
faker.internet().emailAddress(),
faker.internet().url(),
RandomUtil.getRandomString(15));

controller.update(updateRequest);
}

@Then("the patient has the expected phone")
@Transactional
public void the_patient_has_the_expected_phone() {
PatientIdentifier patient = this.patients.one();

Person person = this.entityManager.find(Person.class, patient.id());

assertThat(person.phones()).anySatisfy(
actual -> assertThat(actual)
.returns(updateRequest.type(), TeleEntityLocatorParticipation::getCd)
.returns(updateRequest.use(), TeleEntityLocatorParticipation::getUseCd)
.returns(updateRequest.asOf(), TeleEntityLocatorParticipation::getAsOfDate)
.returns(updateRequest.comment(), TeleEntityLocatorParticipation::getLocatorDescTxt)
.satisfies(
phone -> assertThat(phone)
.extracting(TeleEntityLocatorParticipation::getId)
.returns(updateRequest.patient(), EntityLocatorParticipationId::getEntityUid))
.satisfies(
phone -> assertThat(phone).extracting(TeleEntityLocatorParticipation::getLocator)
.returns(updateRequest.countryCode(), TeleLocator::getCntryCd)
.returns(updateRequest.number(), TeleLocator::getPhoneNbrTxt)
.returns(updateRequest.extension(), TeleLocator::getExtensionTxt)
.returns(updateRequest.email(), TeleLocator::getEmailAddress)
.returns(updateRequest.url(), TeleLocator::getUrlAddress)));
}

@When("a patient's phone is removed")
@Transactional
public void a_patient_phone_is_removed() {

Person patient = this.entityManager.find(Person.class, patients.one().id());

this.deleteRequest = patient.phones()
.stream()
.findFirst()
.map(TeleEntityLocatorParticipation::getId)
.map(id -> new DeletePatientPhoneInput(id.getEntityUid(), id.getLocatorUid()))
.orElseThrow();

this.controller.delete(this.deleteRequest);
}

@Then("the patient does not have the expected phone")
@Transactional
public void the_patient_does_not_have_the_expected_phone() {
PatientIdentifier patient = this.patients.one();

Person actual = this.entityManager.find(Person.class, patient.id());

assertThat(actual.phones())
.noneSatisfy(
phone -> assertThat(phone)
.extracting(TeleEntityLocatorParticipation::getId)
.returns(deleteRequest.patient(), EntityLocatorParticipationId::getEntityUid)
.returns(deleteRequest.id(), EntityLocatorParticipationId::getLocatorUid));
}

@Then("I am unable to add a patient's phone")
public void i_am_unable_to_add_a_patient_ethnicity() {
assertThatThrownBy(() -> controller.add(newRequest))
.isInstanceOf(AccessDeniedException.class);
}

@Then("I am unable to change a patient's phone")
public void i_am_unable_to_change_a_patient_ethnicity() {
assertThatThrownBy(() -> controller.update(updateRequest))
.isInstanceOf(AccessDeniedException.class);
}

@Then("I am unable to remove a patient's phone")
public void i_am_unable_to_remove_a_patient_ethnicity() {
assertThatThrownBy(() -> controller.delete(deleteRequest))
.isInstanceOf(AccessDeniedException.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import { PreviewPage } from './page/management/preview';
import { PageDetails } from './page/management/preview/PageDetails/PageDetails';
import { AddNewPage } from './pages/AddNewPage/AddNewPage';
import { BusinessRulesLibrary } from './pages/BusinessRulesLibrary/BusinessRulesLibrary';
import AddBusinessRule from './pages/BusinessRulesLibrary/Add/AddBusinessRule';
import { PageProvider } from 'page';
import { ViewBusinessRule } from './pages/BusinessRulesLibrary/ViewBusinessRule/ViewBusinessRule';
import { AddBusinessRule } from './pages/BusinessRulesLibrary/Add/AddBusinessRules';
import { EditBusinessRule } from './pages/BusinessRulesLibrary/Edit/EditBusinessRules';

const routing: RouteObject[] = [
{
Expand Down Expand Up @@ -79,12 +80,12 @@ const routing: RouteObject[] = [
{
path: 'add',
element: <AddBusinessRule />
},
{
path: 'edit/:ruleId',
element: <EditBusinessRule />
}
]
},
{
path: ':ruleId',
element: <AddBusinessRule />
}
]
}
Expand Down
Loading

0 comments on commit e54f0b6

Please sign in to comment.