Skip to content

Commit

Permalink
Solved merge conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
johanna-skylight committed Oct 12, 2023
2 parents 394f8e3 + 1d35920 commit e8161d5
Show file tree
Hide file tree
Showing 57 changed files with 4,185 additions and 2,992 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/testingWorkflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ jobs:
outputs:
version: ${{ steps.set_backend_version.outputs.version }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Build Backend Image
id: set_backend_version
uses: ./.github/actions/docker-buildx
Expand All @@ -96,7 +96,7 @@ jobs:
outputs:
version: ${{ steps.set_cypress_version.outputs.version }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Build Cypress Image
id: set_cypress_version
uses: ./.github/actions/docker-buildx
Expand All @@ -121,7 +121,7 @@ jobs:
outputs:
version: ${{ steps.set_database_version.outputs.version }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Build Database Image
id: set_database_version
uses: ./.github/actions/docker-buildx
Expand All @@ -146,7 +146,7 @@ jobs:
outputs:
version: ${{ steps.set_frontend_version.outputs.version }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Build Frontend Image
id: set_frontend_version
uses: ./.github/actions/docker-buildx
Expand Down Expand Up @@ -179,7 +179,7 @@ jobs:
outputs:
version: ${{ steps.set_frontend_lighthouse_version.outputs.version }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Build Frontend Lighthouse Image
id: set_frontend_lighthouse_version
uses: ./.github/actions/docker-buildx
Expand Down Expand Up @@ -210,7 +210,7 @@ jobs:
outputs:
version: ${{ steps.set_nginx_version.outputs.version }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Build Nginx Image
id: set_nginx_version
uses: ./.github/actions/docker-buildx
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package gov.cdc.usds.simplereport.api.converter;

import lombok.Builder;
import lombok.Getter;
import org.hl7.fhir.r4.model.Observation;
import org.hl7.fhir.r4.model.Patient;

@Builder
@Getter
public class ConditionAgnosticConvertToDiagnosticReportProps {
private String testPerformedCode;
private Patient patient;
private Observation observation;
private String testEffectiveDate;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package gov.cdc.usds.simplereport.api.converter;

import gov.cdc.usds.simplereport.db.model.auxiliary.TestCorrectionStatus;
import lombok.Builder;
import lombok.Getter;
import org.hl7.fhir.r4.model.Patient;

@Builder
@Getter
public class ConditionAgnosticConvertToObservationProps {
private TestCorrectionStatus correctionStatus;
private String testPerformedCode;
private Patient patient;
private String resultValue;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package gov.cdc.usds.simplereport.api.converter;

import lombok.Builder;
import lombok.Getter;

@Builder
@Getter
public class ConditionAgnosticConvertToPatientProps {
private String id;
private String firstName;
private String lastName;
private String nameAbsentReason;
private String gender;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package gov.cdc.usds.simplereport.api.converter;

import java.util.List;
import lombok.Builder;
import lombok.Getter;
import org.hl7.fhir.r4.model.DiagnosticReport;
import org.hl7.fhir.r4.model.Observation;
import org.hl7.fhir.r4.model.Patient;
import org.springframework.boot.info.GitProperties;

@Builder
@Getter
public class ConditionAgnosticCreateFhirBundleProps {
private Patient patient;
private List<Observation> resultObservations;
private DiagnosticReport diagnosticReport;
private GitProperties gitProperties;
private String processingId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,16 @@ private FhirConstants() {

public static final String ORDER_EFFECTIVE_DATE_EXTENSION_URL =
"https://reportstream.cdc.gov/fhir/StructureDefinition/order-effective-date";

public static final String OBSERVATION_CATEGORY_CODE_SYSTEM =
"https://terminology.hl7.org/5.2.0/CodeSystem-observation-category.html";
public static final String DATA_ABSENT_REASON_EXTENSION_URL =
"http://hl7.org/fhir/StructureDefinition/data-absent-reason";

public static final String DIAGNOSTIC_CODE_SYSTEM =
"https://terminology.hl7.org/5.2.0/CodeSystem-v2-0074.html";

// Hardcoded category values for our initial condition agnostic spec
public static final String LAB_STRING_LITERAL = "LAB";
public static final String LABORATORY_STRING_LITERAL = "laboratory";
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import static gov.cdc.usds.simplereport.api.converter.FhirConstants.UNIVERSAL_ID_SYSTEM;
import static gov.cdc.usds.simplereport.api.converter.FhirConstants.YESNO_CODE_SYSTEM;
import static gov.cdc.usds.simplereport.api.model.TestEventExport.FALLBACK_DEFAULT_TEST_MINUTES;
import static gov.cdc.usds.simplereport.api.model.TestEventExport.UNKNOWN_ADDRESS_INDICATOR;
import static gov.cdc.usds.simplereport.db.model.PersonUtils.getResidenceTypeMap;
import static gov.cdc.usds.simplereport.db.model.PersonUtils.pregnancyStatusDisplayMap;
import static gov.cdc.usds.simplereport.db.model.PersonUtils.pregnancyStatusSnomedMap;
Expand Down Expand Up @@ -454,16 +455,35 @@ public Organization convertToOrganization(
return org;
}

public Patient convertToPatient(Person person) {
public StreetAddress getPatientAddress(Person person, Facility facility) {
var personAddress = person.getAddress();
if (UNKNOWN_ADDRESS_INDICATOR.equalsIgnoreCase(person.getStreet()) && facility != null) {
var facilityAddress = facility.getAddress();
personAddress.setCity(facilityAddress.getCity());
personAddress.setState(facilityAddress.getState());
personAddress.setPostalCode(facilityAddress.getPostalCode());
personAddress.setCounty(facilityAddress.getCounty());
}
return personAddress;
}

public List<PhoneNumber> getPatientPhoneNumbers(Person person, Facility facility) {
if (person.getPhoneNumbers() == null || person.getPhoneNumbers().isEmpty()) {
return List.of(new PhoneNumber(PhoneType.LANDLINE, facility.getTelephone()));
}
return person.getPhoneNumbers();
}

public Patient convertToPatient(Person person, Facility facility) {
return convertToPatient(
ConvertToPatientProps.builder()
.id(person.getInternalId().toString())
.name(person.getNameInfo())
.phoneNumbers(person.getPhoneNumbers())
.phoneNumbers(getPatientPhoneNumbers(person, facility))
.emails(person.getEmails())
.gender(person.getGender())
.dob(person.getBirthDate())
.address(person.getAddress())
.address(getPatientAddress(person, facility))
.country(person.getCountry())
.race(person.getRace())
.ethnicity(person.getEthnicity())
Expand Down Expand Up @@ -1081,7 +1101,7 @@ public Bundle createFhirBundle(

return createFhirBundle(
CreateFhirBundleProps.builder()
.patient(convertToPatient(testEvent.getPatient()))
.patient(convertToPatient(testEvent.getPatient(), testEvent.getFacility()))
.testingLab(convertToOrganization(testEvent.getFacility()))
.orderingFacility(null)
.practitioner(convertToPractitioner(testEvent.getProviderData()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
public class TestEventExport {
public static final int FALLBACK_DEFAULT_TEST_MINUTES = 15;
public static final String USA = "USA";
public static final String UNKNOWN_ADDRESS_INDICATOR = "** Unknown / Not Given **";
private String processingModeCode = "P";
private final TestEvent testEvent;
private final Optional<Person> patient;
Expand Down Expand Up @@ -293,21 +294,37 @@ public String getPatientStreetTwo() {

@JsonProperty("Patient_city")
public String getPatientCity() {
var street = patient.map(Person::getStreet).orElse(null);
if (UNKNOWN_ADDRESS_INDICATOR.equalsIgnoreCase(street)) {
return getOrderingFacilityCity();
}
return patient.map(Person::getCity).orElse(null);
}

@JsonProperty("Patient_county")
public String getPatientCounty() {
var street = patient.map(Person::getStreet).orElse(null);
if (UNKNOWN_ADDRESS_INDICATOR.equalsIgnoreCase(street)) {
return getOrderingFacilityCounty();
}
return patient.map(Person::getCounty).orElse(null);
}

@JsonProperty("Patient_state")
public String getPatientState() {
var street = patient.map(Person::getStreet).orElse(null);
if (UNKNOWN_ADDRESS_INDICATOR.equalsIgnoreCase(street)) {
return getOrderingFacilityState();
}
return patient.map(Person::getState).orElse(null);
}

@JsonProperty("Patient_zip_code")
public String getPatientZipCode() {
var street = patient.map(Person::getStreet).orElse(null);
if (UNKNOWN_ADDRESS_INDICATOR.equalsIgnoreCase(street)) {
return getOrderingFacilityZipCode();
}
return patient.map(Person::getZipCode).orElse(null);
}

Expand All @@ -318,7 +335,11 @@ public String getPatientCountry() {

@JsonProperty("Patient_phone_number")
public String getPatientPhoneNumber() {
return patient.map(Person::getTelephone).orElse(null);
var phone = patient.map(Person::getTelephone).orElse(null);
if (phone == null || phone.isBlank()) {
return getOrderingFacilityPhoneNumber();
}
return phone;
}

@JsonProperty("Patient_email")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
package gov.cdc.usds.simplereport.api.model.filerow;

import static gov.cdc.usds.simplereport.validators.CsvValidatorUtils.getValue;
import static gov.cdc.usds.simplereport.validators.CsvValidatorUtils.validateBiologicalSex;
import static gov.cdc.usds.simplereport.validators.CsvValidatorUtils.validateDataAbsentReason;
import static gov.cdc.usds.simplereport.validators.CsvValidatorUtils.validateDateTime;
import static gov.cdc.usds.simplereport.validators.CsvValidatorUtils.validateTestPerformedCode;
import static gov.cdc.usds.simplereport.validators.CsvValidatorUtils.validateTestResult;
import static gov.cdc.usds.simplereport.validators.CsvValidatorUtils.validateTestResultStatus;

import gov.cdc.usds.simplereport.service.model.reportstream.FeedbackMessage;
import gov.cdc.usds.simplereport.validators.CsvValidatorUtils.ValueOrError;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;

@Getter
public class ConditionAgnosticResultRow implements FileRow {
final ValueOrError testResultStatus;
final ValueOrError testResultEffectiveDate;
final ValueOrError testPerformedCode;
final ValueOrError testResultValue;
final ValueOrError patientId;
final ValueOrError patientFirstName;
final ValueOrError patientLastName;
final ValueOrError patientNameAbsentReason;
final ValueOrError patientAdminGender;

public static final String TEST_RESULT_STATUS = "test_result_status";
public static final String TEST_RESULT_EFFECTIVE_DATE = "test_result_effective_date";
public static final String TEST_PERFORMED_CODE = "test_performed_code";
public static final String TEST_RESULT_VALUE = "test_result_value";
public static final String PATIENT_ID = "patient_id";
public static final String PATIENT_LAST_NAME = "patient_last_name";
public static final String PATIENT_FIRST_NAME = "patient_first_name";
public static final String PATIENT_NAME_ABSENT_REASON = "patient_name_absent_reason";
public static final String PATIENT_ADMIN_GENDER = "patient_admin_gender";

private static List<String> initialRequiredFields =
List.of(
TEST_RESULT_STATUS,
TEST_RESULT_EFFECTIVE_DATE,
TEST_PERFORMED_CODE,
TEST_RESULT_VALUE,
PATIENT_ID,
PATIENT_ADMIN_GENDER);

private List<String> requiredFields;

public ConditionAgnosticResultRow(Map<String, String> rawRow) {
this.requiredFields = generateRequiredFields(rawRow);
testResultStatus = getValue(rawRow, TEST_RESULT_STATUS, isRequired(TEST_RESULT_STATUS));
testResultEffectiveDate =
getValue(rawRow, TEST_RESULT_EFFECTIVE_DATE, isRequired(TEST_RESULT_EFFECTIVE_DATE));
testPerformedCode = getValue(rawRow, TEST_PERFORMED_CODE, isRequired(TEST_PERFORMED_CODE));
testResultValue = getValue(rawRow, TEST_RESULT_VALUE, isRequired(TEST_RESULT_VALUE));
patientId = getValue(rawRow, PATIENT_ID, isRequired(PATIENT_ID));
patientNameAbsentReason =
getValue(rawRow, PATIENT_NAME_ABSENT_REASON, isRequired(PATIENT_NAME_ABSENT_REASON));
patientFirstName = getValue(rawRow, PATIENT_FIRST_NAME, isRequired(PATIENT_FIRST_NAME));
patientLastName = getValue(rawRow, PATIENT_LAST_NAME, isRequired(PATIENT_LAST_NAME));
patientAdminGender = getValue(rawRow, PATIENT_ADMIN_GENDER, isRequired(PATIENT_ADMIN_GENDER));
}

// The schema expects that (first_name || last_name) XOR name_absent_reason be present, so add the
// name-related fields to the required fields list accordingly
private static List<String> generateRequiredFields(Map<String, String> rawRow) {
String firstNameVal = getValue(rawRow, PATIENT_FIRST_NAME, false).getValue();
String lastNameVal = getValue(rawRow, PATIENT_LAST_NAME, false).getValue();

boolean firstNameAbsent = StringUtils.isBlank(firstNameVal);
boolean lastNameAbsent = StringUtils.isBlank(lastNameVal);

List<String> requiredFields = new ArrayList<>(initialRequiredFields);

if (firstNameAbsent ^ lastNameAbsent) {
if (firstNameAbsent) requiredFields.add(PATIENT_LAST_NAME);
else requiredFields.add(PATIENT_FIRST_NAME);
} else if (firstNameAbsent && lastNameAbsent) {
requiredFields.add(PATIENT_NAME_ABSENT_REASON);
} else {
requiredFields.add(PATIENT_LAST_NAME);
requiredFields.add(PATIENT_FIRST_NAME);
}

return requiredFields;
}

@Override
public Boolean isRequired(String rowName) {
return requiredFields.contains(rowName);
}

@Override
public List<FeedbackMessage> validateRequiredFields() {
return getPossibleErrorsFromFields();
}

@Override
public List<String> getRequiredFields() {
return requiredFields;
}

@Override
public List<FeedbackMessage> validateIndividualValues() {
var errors = new ArrayList<FeedbackMessage>();
errors.addAll(validateBiologicalSex(patientAdminGender));
errors.addAll(validateDataAbsentReason(patientNameAbsentReason));
errors.addAll(validateTestResultStatus(testResultStatus));
errors.addAll(validateDateTime(testResultEffectiveDate));
errors.addAll(validateTestPerformedCode(testPerformedCode));
errors.addAll(validateTestResult(testResultValue));
return errors;
}
}
Loading

0 comments on commit e8161d5

Please sign in to comment.