Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CNFT1-2780 API: Create Extended patient data entry form for Mortality #1877

Merged
merged 6 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import gov.cdc.nbs.patient.profile.birth.BirthDemographic;
import gov.cdc.nbs.patient.profile.ethnicity.EthnicityDemographic;
import gov.cdc.nbs.patient.profile.gender.GenderDemographic;
import gov.cdc.nbs.patient.profile.mortality.MortalityDemographic;
import gov.cdc.nbs.patient.profile.names.NameDemographic;
import gov.cdc.nbs.time.json.FormattedLocalDateJsonDeserializer;

Expand All @@ -24,7 +25,8 @@ public record NewPatient(
List<Phone> phoneEmails,
List<Race> races,
List<Identification> identifications,
EthnicityDemographic ethnicity) {
EthnicityDemographic ethnicity,
MortalityDemographic mortality) {

public record Phone(
@JsonDeserialize(using = FormattedLocalDateJsonDeserializer.class) LocalDate asOf,
Expand Down Expand Up @@ -63,6 +65,7 @@ public NewPatient() {
Collections.emptyList(),
Collections.emptyList(),
Collections.emptyList(),
null,
null);
}

Expand All @@ -76,7 +79,8 @@ public NewPatient withAdministrative(final Administrative administrative) {
phoneEmails(),
races(),
identifications(),
ethnicity());
ethnicity(),
mortality());
}

public NewPatient withName(final NameDemographic name) {
Expand All @@ -89,7 +93,8 @@ public NewPatient withName(final NameDemographic name) {
phoneEmails(),
races(),
identifications(),
ethnicity());
ethnicity(),
mortality());
}

public NewPatient withAddress(final AddressDemographic value) {
Expand All @@ -102,7 +107,8 @@ public NewPatient withAddress(final AddressDemographic value) {
phoneEmails(),
races(),
identifications(),
ethnicity());
ethnicity(),
mortality());
}

public NewPatient withPhoneEmail(final Phone value) {
Expand All @@ -115,7 +121,8 @@ public NewPatient withPhoneEmail(final Phone value) {
Including.include(phoneEmails(), value),
races(),
identifications(),
ethnicity());
ethnicity(),
mortality());
}

public NewPatient withRace(final Race value) {
Expand All @@ -128,7 +135,8 @@ public NewPatient withRace(final Race value) {
phoneEmails(),
Including.include(races(), value),
identifications(),
ethnicity());
ethnicity(),
mortality());
}

public NewPatient withIdentification(final Identification value) {
Expand All @@ -141,7 +149,8 @@ public NewPatient withIdentification(final Identification value) {
phoneEmails(),
races(),
Including.include(identifications(), value),
ethnicity());
ethnicity(),
mortality());
}

public NewPatient withBirth(final BirthDemographic value) {
Expand All @@ -154,7 +163,8 @@ public NewPatient withBirth(final BirthDemographic value) {
phoneEmails(),
races(),
identifications(),
ethnicity());
ethnicity(),
mortality());
}

public NewPatient withEthnicity(final EthnicityDemographic ethnicity) {
Expand All @@ -167,7 +177,22 @@ public NewPatient withEthnicity(final EthnicityDemographic ethnicity) {
phoneEmails(),
races(),
identifications(),
ethnicity);
ethnicity,
mortality());
}

public NewPatient withMortality(final MortalityDemographic mortality) {
return new NewPatient(
administrative(),
birth(),
gender(),
names(),
addresses(),
phoneEmails(),
races(),
identifications(),
ethnicity(),
mortality);
}

public NewPatient withGender(final GenderDemographic value) {
Expand All @@ -180,7 +205,8 @@ public NewPatient withGender(final GenderDemographic value) {
phoneEmails(),
races(),
identifications(),
ethnicity());
ethnicity(),
mortality());
}

public Optional<Administrative> maybeAdministrative() {
Expand All @@ -199,5 +225,9 @@ public Optional<GenderDemographic> maybeGender() {
return Optional.ofNullable(gender());
}

public Optional<MortalityDemographic> maybeMortality() {
return Optional.ofNullable(mortality());
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import static gov.cdc.nbs.patient.profile.ethnicity.EthnicityPatientCommandMapper.asUpdateEthnicityInfo;
import static gov.cdc.nbs.patient.profile.gender.GenderDemographicPatientCommandMapper.asUpdateGender;
import static gov.cdc.nbs.patient.profile.names.NameDemographicPatientCommandMapper.asAddName;
import static gov.cdc.nbs.patient.profile.mortality.MortalityDemographicPatientCommandMapper.asUpdateMortality;

@Component
class PatientCreationService {
Expand All @@ -30,8 +31,7 @@ class PatientCreationService {
PatientCreationService(
final PatientIdentifierGenerator patientIdentifierGenerator,
final AddressIdentifierGenerator addressIdentifierGenerator,
final EntityManager entityManager
) {
final EntityManager entityManager) {
this.patientIdentifierGenerator = patientIdentifierGenerator;
this.addressIdentifierGenerator = addressIdentifierGenerator;
this.entityManager = entityManager;
Expand All @@ -40,18 +40,15 @@ class PatientCreationService {
@Transactional
public CreatedPatient create(
final RequestContext context,
final NewPatient newPatient
) {
final NewPatient newPatient) {
PatientIdentifier identifier = patientIdentifierGenerator.generate();

Person patient = new Person(
new PatientCommand.CreatePatient(
identifier.id(),
identifier.local(),
context.requestedBy(),
context.requestedAt()
)
);
context.requestedAt()));

newPatient.maybeAdministrative()
.map(administrative -> asUpdateAdministrativeInfo(identifier.id(), context, administrative))
Expand Down Expand Up @@ -81,6 +78,10 @@ public CreatedPatient create(
.map(demographic -> asAddName(identifier.id(), context, demographic))
.forEach(patient::add);

newPatient.maybeMortality()
.map(demographic -> asUpdateMortality(identifier.id(), context, demographic))
.ifPresent(command -> patient.update(command, addressIdentifierGenerator));

this.entityManager.persist(patient);

return new CreatedPatient(identifier.id(), identifier.shortId(), identifier.local());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package gov.cdc.nbs.patient.profile.mortality;

import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import gov.cdc.nbs.time.json.FormattedLocalDateJsonDeserializer;

import java.time.LocalDate;



public record MortalityDemographic(
@JsonDeserialize(using = FormattedLocalDateJsonDeserializer.class) LocalDate asOf,
String deceased,
@JsonDeserialize(using = FormattedLocalDateJsonDeserializer.class) LocalDate deceasedOn,
String city,
String state,
String county,
String country) {

public MortalityDemographic(final LocalDate asOf) {
this(asOf, null, null, null, null, null, null);
}

public MortalityDemographic withDeceased(final String deceased) {
return new MortalityDemographic(asOf(), deceased, deceasedOn(), city(), state(), county(), country());
}

public MortalityDemographic withDeceasedOn(final LocalDate deceasedOn) {
return new MortalityDemographic(asOf(), deceased(), deceasedOn, city(), state(), county(), country());
}

public MortalityDemographic withCity(final String city) {
return new MortalityDemographic(asOf(), deceased(), deceasedOn(), city, state(), county(), country());
}

public MortalityDemographic withState(final String state) {
return new MortalityDemographic(asOf(), deceased(), deceasedOn(), city(), state, county(), country());
}

public MortalityDemographic withCounty(final String county) {
return new MortalityDemographic(asOf(), deceased(), deceasedOn(), city(), state(), county, country());
}

public MortalityDemographic withCountry(final String country) {
return new MortalityDemographic(asOf(), deceased(), deceasedOn(), city(), state(), county(), country);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package gov.cdc.nbs.patient.profile.mortality;

import gov.cdc.nbs.patient.PatientCommand;
import gov.cdc.nbs.patient.RequestContext;
import java.time.Instant;
import java.time.ZoneId;

public class MortalityDemographicPatientCommandMapper {

public static PatientCommand.UpdateMortality asUpdateMortality(
final long patient,
final RequestContext context,
final MortalityDemographic demographic) {

Instant asOf = demographic.asOf().atStartOfDay(ZoneId.systemDefault()).toInstant();

return new PatientCommand.UpdateMortality(
patient,
asOf,
demographic.deceased(),
demographic.deceasedOn(),
demographic.city(),
demographic.state(),
demographic.county(),
demographic.country(),
context.requestedBy(),
context.requestedAt());
}

private MortalityDemographicPatientCommandMapper() {
// static
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import gov.cdc.nbs.patient.profile.birth.BirthDemographic;
import gov.cdc.nbs.patient.profile.ethnicity.EthnicityDemographic;
import gov.cdc.nbs.patient.profile.gender.GenderDemographic;
import gov.cdc.nbs.patient.profile.mortality.MortalityDemographic;
import gov.cdc.nbs.patient.profile.names.NameDemographic;
import gov.cdc.nbs.testing.support.Active;
import io.cucumber.java.en.Given;
Expand All @@ -15,6 +16,7 @@ public class PatientCreateEntrySteps {
private final Active<GenderDemographic> activeGenderDemographic;
private final Active<NameDemographic> activeName;
private final Active<EthnicityDemographic> activeEthnicity;
private final Active<MortalityDemographic> activeMortalityDemographic;
private final Active<NewPatient> input;

public PatientCreateEntrySteps(
Expand All @@ -23,10 +25,12 @@ public PatientCreateEntrySteps(
final Active<GenderDemographic> activeGenderDemographic,
final Active<NameDemographic> activeName,
final Active<EthnicityDemographic> activeEthnicity,
final Active<MortalityDemographic> activeMortalityDemographic,
final Active<NewPatient> input) {
this.activeAdministrative = activeAdministrative;
this.activeBirthDemographic = activeBirthDemographic;
this.activeGenderDemographic = activeGenderDemographic;
this.activeMortalityDemographic = activeMortalityDemographic;
this.activeName = activeName;
this.activeEthnicity = activeEthnicity;
this.input = input;
Expand Down Expand Up @@ -61,4 +65,10 @@ public void the_gender_demographics_are_included_in_the_extended_patient_data()
this.activeGenderDemographic.maybeActive()
.ifPresent(demographic -> this.input.active(current -> current.withGender(demographic)));
}

@Given("the mortality demographics are included in the extended patient data")
public void the_mortality_demographics_are_included_in_the_extended_patient_data() {
this.activeMortalityDemographic.maybeActive()
.ifPresent(demographic -> this.input.active(current -> current.withMortality(demographic)));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package gov.cdc.nbs.patient.profile.mortality;

import gov.cdc.nbs.testing.support.Active;
import io.cucumber.java.en.Given;

import java.time.LocalDate;

public class MortalityDemographicEntrySteps {

private final Active<MortalityDemographic> input;

MortalityDemographicEntrySteps(final Active<MortalityDemographic> input) {
this.input = input;
}

@Given("I am entering the mortality as of date {localDate}")
public void i_am_entering_patient_mortality_as_of(final LocalDate asOf) {
this.input.active(new MortalityDemographic(asOf, null, null, null, null, null, null));
}

@Given("I enter the mortality city {string}")
public void i_enter_the_patient_mortality_city(final String city) {
this.input.active(current -> current.withCity(city));
}

@Given("I enter the mortality country {country}")
public void i_enter_the_patient_mortality_country(final String country) {
this.input.active(current -> current.withCountry(country));
}

@Given("I enter the mortality county {county}")
public void i_enter_the_patient_mortality_county(final String county) {
this.input.active(current -> current.withCounty(county));
}

@Given("I enter the mortality state {state}")
public void i_enter_the_patient_mortality_state(final String state) {
this.input.active(current -> current.withState(state));
}

@Given("I enter the mortality deceased on date of {localDate}")
public void i_am_entering_patient_mortality_deceased_on_date_of(final LocalDate deceasedOn) {
this.input.active(current -> current.withDeceasedOn(deceasedOn));
}

@Given("I enter the mortality deceased option as {indicator}")
public void i_enter_the_patient_mortality_deceased_option_as(final String indicator) {
this.input.active(current -> current.withDeceased(indicator));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package gov.cdc.nbs.patient.profile.mortality;

import gov.cdc.nbs.testing.support.Active;
import io.cucumber.spring.ScenarioScope;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.time.Clock;
import java.time.LocalDate;

@Configuration
class MortalityDemographicSupportConfiguration {

@Bean
@ScenarioScope
Active<MortalityDemographic> activeMortalityDemographic(final Clock clock) {
return new Active<>(() -> new MortalityDemographic(LocalDate.now(clock)));
}
}
Loading
Loading