From c6d8948bc9ec50cc0c2c3b074217c6e34f1b760e Mon Sep 17 00:00:00 2001 From: Johanna Date: Fri, 21 Apr 2023 13:10:05 -0400 Subject: [PATCH] Refactored methods in FHIR converter --- .../converter/ConvertToObservationProps.java | 20 ++ .../api/converter/ConvertToPatientProps.java | 25 ++ .../api/converter/CreateFhirBundleProps.java | 34 ++ .../api/converter/FhirConverter.java | 299 +++++++++--------- .../utils/BulkUploadResultsToFhir.java | 91 +++--- .../api/converter/FhirConverterTest.java | 52 +-- 6 files changed, 306 insertions(+), 215 deletions(-) create mode 100644 backend/src/main/java/gov/cdc/usds/simplereport/api/converter/ConvertToObservationProps.java create mode 100644 backend/src/main/java/gov/cdc/usds/simplereport/api/converter/ConvertToPatientProps.java create mode 100644 backend/src/main/java/gov/cdc/usds/simplereport/api/converter/CreateFhirBundleProps.java diff --git a/backend/src/main/java/gov/cdc/usds/simplereport/api/converter/ConvertToObservationProps.java b/backend/src/main/java/gov/cdc/usds/simplereport/api/converter/ConvertToObservationProps.java new file mode 100644 index 0000000000..b8646837f4 --- /dev/null +++ b/backend/src/main/java/gov/cdc/usds/simplereport/api/converter/ConvertToObservationProps.java @@ -0,0 +1,20 @@ +package gov.cdc.usds.simplereport.api.converter; + +import gov.cdc.usds.simplereport.db.model.auxiliary.TestCorrectionStatus; +import lombok.Builder; +import lombok.Getter; + +@Builder +@Getter +public class ConvertToObservationProps { + private String diseaseCode; + private String diseaseName; + private String resultCode; + private TestCorrectionStatus correctionStatus; + private String correctionReason; + private String id; + private String resultDescription; + private String testkitNameId; + private String equipmentUid; + private String deviceModel; +} diff --git a/backend/src/main/java/gov/cdc/usds/simplereport/api/converter/ConvertToPatientProps.java b/backend/src/main/java/gov/cdc/usds/simplereport/api/converter/ConvertToPatientProps.java new file mode 100644 index 0000000000..38e27b7683 --- /dev/null +++ b/backend/src/main/java/gov/cdc/usds/simplereport/api/converter/ConvertToPatientProps.java @@ -0,0 +1,25 @@ +package gov.cdc.usds.simplereport.api.converter; + +import gov.cdc.usds.simplereport.db.model.PhoneNumber; +import gov.cdc.usds.simplereport.db.model.auxiliary.PersonName; +import gov.cdc.usds.simplereport.db.model.auxiliary.StreetAddress; +import java.time.LocalDate; +import java.util.List; +import lombok.Builder; +import lombok.Getter; + +@Builder +@Getter +public class ConvertToPatientProps { + private String id; + private PersonName name; + private List phoneNumbers; + private List emails; + private String gender; + private LocalDate dob; + private StreetAddress address; + private String country; + private String race; + private String ethnicity; + private List tribalAffiliations; +} diff --git a/backend/src/main/java/gov/cdc/usds/simplereport/api/converter/CreateFhirBundleProps.java b/backend/src/main/java/gov/cdc/usds/simplereport/api/converter/CreateFhirBundleProps.java new file mode 100644 index 0000000000..f21d50b467 --- /dev/null +++ b/backend/src/main/java/gov/cdc/usds/simplereport/api/converter/CreateFhirBundleProps.java @@ -0,0 +1,34 @@ +package gov.cdc.usds.simplereport.api.converter; + +import java.util.Date; +import java.util.List; +import java.util.Set; +import lombok.Builder; +import lombok.Getter; +import org.hl7.fhir.r4.model.Device; +import org.hl7.fhir.r4.model.DiagnosticReport; +import org.hl7.fhir.r4.model.Observation; +import org.hl7.fhir.r4.model.Organization; +import org.hl7.fhir.r4.model.Patient; +import org.hl7.fhir.r4.model.Practitioner; +import org.hl7.fhir.r4.model.ServiceRequest; +import org.hl7.fhir.r4.model.Specimen; +import org.springframework.boot.info.GitProperties; + +@Builder +@Getter +public class CreateFhirBundleProps { + private Patient patient; + private Organization testingLab; + private Organization orderingFacility; + private Practitioner practitioner; + private Device device; + private Specimen specimen; + private List resultObservations; + private Set aoeObservations; + private ServiceRequest serviceRequest; + private DiagnosticReport diagnosticReport; + private Date currentDate; + private GitProperties gitProperties; + private String processingId; +} diff --git a/backend/src/main/java/gov/cdc/usds/simplereport/api/converter/FhirConverter.java b/backend/src/main/java/gov/cdc/usds/simplereport/api/converter/FhirConverter.java index 4a1a23a27a..d1c702a092 100644 --- a/backend/src/main/java/gov/cdc/usds/simplereport/api/converter/FhirConverter.java +++ b/backend/src/main/java/gov/cdc/usds/simplereport/api/converter/FhirConverter.java @@ -385,46 +385,39 @@ public static Organization convertToOrganization( public static Patient convertToPatient(Person person) { return convertToPatient( - person.getInternalId().toString(), - person.getNameInfo(), - person.getPhoneNumbers(), - person.getEmails(), - person.getGender(), - person.getBirthDate(), - person.getAddress(), - person.getCountry(), - person.getRace(), - person.getEthnicity(), - person.getTribalAffiliation()); - } - - public static Patient convertToPatient( - String id, - PersonName name, - List phoneNumbers, - List emails, - String gender, - LocalDate dob, - StreetAddress address, - String country, - String race, - String ethnicity, - List tribalAffiliations) { + ConvertToPatientProps.builder() + .id(person.getInternalId().toString()) + .name(person.getNameInfo()) + .phoneNumbers(person.getPhoneNumbers()) + .emails(person.getEmails()) + .gender(person.getGender()) + .dob(person.getBirthDate()) + .address(person.getAddress()) + .country(person.getCountry()) + .race(person.getRace()) + .ethnicity(person.getEthnicity()) + .tribalAffiliations(person.getTribalAffiliation()) + .build()); + } + + public static Patient convertToPatient(ConvertToPatientProps props) { var patient = new Patient() - .addName(convertToHumanName(name)) - .setGender(convertToAdministrativeGender(gender)) - .setBirthDate(convertToDate(dob)) - .addAddress(convertToAddress(address, country)); - - patient.addExtension(convertToRaceExtension(race)); - patient.addExtension(convertToEthnicityExtension(ethnicity)); - patient.addExtension(convertToTribalAffiliationExtension(tribalAffiliations).orElse(null)); - - patient.setId(id); - patient.addIdentifier().setValue(id); - convertPhoneNumbersToContactPoint(phoneNumbers).forEach(patient::addTelecom); - convertEmailsToContactPoint(ContactPointUse.HOME, emails).forEach(patient::addTelecom); + .addName(convertToHumanName(props.getName())) + .setGender(convertToAdministrativeGender(props.getGender())) + .setBirthDate(convertToDate(props.getDob())) + .addAddress(convertToAddress(props.getAddress(), props.getCountry())); + + patient.addExtension(convertToRaceExtension(props.getRace())); + patient.addExtension(convertToEthnicityExtension(props.getEthnicity())); + patient.addExtension( + convertToTribalAffiliationExtension(props.getTribalAffiliations()).orElse(null)); + + patient.setId(props.getId()); + patient.addIdentifier().setValue(props.getId()); + convertPhoneNumbersToContactPoint(props.getPhoneNumbers()).forEach(patient::addTelecom); + convertEmailsToContactPoint(ContactPointUse.HOME, props.getEmails()) + .forEach(patient::addTelecom); return patient; } @@ -533,53 +526,51 @@ public static Observation convertToObservation( String equipmentUid, String deviceModel) { if (result != null && result.getDisease() != null) { + return convertToObservation( - testPerformedCode, - result.getDisease().getName(), - result.getResultLOINC(), - correctionStatus, - correctionReason, - result.getInternalId().toString(), - Translators.convertConceptCodeToConceptName(result.getResultLOINC()), - testkitNameId, - equipmentUid, - deviceModel); + ConvertToObservationProps.builder() + .diseaseCode(testPerformedCode) + .diseaseName(result.getDisease().getName()) + .resultCode(result.getResultLOINC()) + .correctionStatus(correctionStatus) + .correctionReason(correctionReason) + .id(result.getInternalId().toString()) + .resultDescription( + Translators.convertConceptCodeToConceptName(result.getResultLOINC())) + .testkitNameId(testkitNameId) + .equipmentUid(equipmentUid) + .deviceModel(deviceModel) + .build()); } return null; } - public static Observation convertToObservation( - String diseaseCode, - String diseaseName, - String resultCode, - TestCorrectionStatus correctionStatus, - String correctionReason, - String id, - String resultDescription, - String testkitNameId, - String equipmentUid, - String deviceModel) { + public static Observation convertToObservation(ConvertToObservationProps props) { var observation = new Observation(); - observation.setId(id); - setStatus(observation, correctionStatus); - observation.setCode(createLoincConcept(diseaseCode, "", diseaseName)); - addSNOMEDValue(resultCode, observation, resultDescription); - observation.getMethod().getCodingFirstRep().setDisplay(deviceModel); + observation.setId(props.getId()); + setStatus(observation, props.getCorrectionStatus()); + observation.setCode(createLoincConcept(props.getDiseaseCode(), "", props.getDiseaseName())); + addSNOMEDValue(props.getResultCode(), observation, props.getResultDescription()); + observation.getMethod().getCodingFirstRep().setDisplay(props.getDeviceModel()); observation .getMethod() .addExtension( new Extension() .setUrl(TESTKIT_NAME_ID_EXTENSION_URL) - .setValue(new CodeableConcept().addCoding().setCode(testkitNameId))) + .setValue(new CodeableConcept().addCoding().setCode(props.getTestkitNameId()))) .addExtension( new Extension() .setUrl(EQUIPMENT_UID_EXTENSION_URL) - .setValue(new CodeableConcept().addCoding().setCode(equipmentUid))); + .setValue(new CodeableConcept().addCoding().setCode(props.getEquipmentUid()))); addCorrectionNote( - correctionStatus != TestCorrectionStatus.ORIGINAL, correctionReason, observation); + props.getCorrectionStatus() != TestCorrectionStatus.ORIGINAL, + props.getCorrectionReason(), + observation); - observation.addInterpretation().addCoding(convertToAbnormalFlagInterpretation(resultCode)); + observation + .addInterpretation() + .addCoding(convertToAbnormalFlagInterpretation(props.getResultCode())); return observation; } @@ -809,51 +800,47 @@ public static Bundle createFhirBundle( GitProperties gitProperties, Date currentDate, String processingId) { - return createFhirBundle( - convertToPatient(testEvent.getPatient()), - convertToOrganization(testEvent.getFacility()), - null, - convertToPractitioner(testEvent.getProviderData()), - convertToDevice(testEvent.getDeviceType()), - convertToSpecimen(testEvent.getSpecimenType()), - convertToObservation( - testEvent.getResults(), - testEvent.getDeviceType(), - testEvent.getCorrectionStatus(), - testEvent.getReasonForCorrection()), - convertToAOEObservations(testEvent.getInternalId().toString(), testEvent.getSurveyData()), - convertToServiceRequest(testEvent.getOrder()), - convertToDiagnosticReport(testEvent), - currentDate, - gitProperties, - processingId); - } - public static Bundle createFhirBundle( - Patient patient, - Organization testingLab, - Organization orderingFacility, - Practitioner practitioner, - Device device, - Specimen specimen, - List resultObservations, - Set aoeObservations, - ServiceRequest serviceRequest, - DiagnosticReport diagnosticReport, - Date currentDate, - GitProperties gitProperties, - String processingId) { - var patientFullUrl = ResourceType.Patient + "/" + patient.getId(); + return createFhirBundle( + CreateFhirBundleProps.builder() + .patient(convertToPatient(testEvent.getPatient())) + .testingLab(convertToOrganization(testEvent.getFacility())) + .orderingFacility(null) + .practitioner(convertToPractitioner(testEvent.getProviderData())) + .device(convertToDevice(testEvent.getDeviceType())) + .specimen(convertToSpecimen(testEvent.getSpecimenType())) + .resultObservations( + convertToObservation( + testEvent.getResults(), + testEvent.getDeviceType(), + testEvent.getCorrectionStatus(), + testEvent.getReasonForCorrection())) + .aoeObservations( + convertToAOEObservations( + testEvent.getInternalId().toString(), testEvent.getSurveyData())) + .serviceRequest(convertToServiceRequest(testEvent.getOrder())) + .diagnosticReport(convertToDiagnosticReport(testEvent)) + .currentDate(currentDate) + .gitProperties(gitProperties) + .processingId(processingId) + .build()); + } + + public static Bundle createFhirBundle(CreateFhirBundleProps props) { + var patientFullUrl = ResourceType.Patient + "/" + props.getPatient().getId(); var orderingFacilityFullUrl = - orderingFacility == null + props.getOrderingFacility() == null ? null - : ResourceType.Organization + "/" + orderingFacility.getId(); - var testingLabOrganizationFullUrl = ResourceType.Organization + "/" + testingLab.getId(); - var practitionerFullUrl = ResourceType.Practitioner + "/" + practitioner.getId(); - var specimenFullUrl = ResourceType.Specimen + "/" + specimen.getId(); - var serviceRequestFullUrl = ResourceType.ServiceRequest + "/" + serviceRequest.getId(); - var diagnosticReportFullUrl = ResourceType.DiagnosticReport + "/" + diagnosticReport.getId(); - var deviceFullUrl = ResourceType.Device + "/" + device.getId(); + : ResourceType.Organization + "/" + props.getOrderingFacility().getId(); + var testingLabOrganizationFullUrl = + ResourceType.Organization + "/" + props.getTestingLab().getId(); + var practitionerFullUrl = ResourceType.Practitioner + "/" + props.getPractitioner().getId(); + var specimenFullUrl = ResourceType.Specimen + "/" + props.getSpecimen().getId(); + var serviceRequestFullUrl = + ResourceType.ServiceRequest + "/" + props.getServiceRequest().getId(); + var diagnosticReportFullUrl = + ResourceType.DiagnosticReport + "/" + props.getDiagnosticReport().getId(); + var deviceFullUrl = ResourceType.Device + "/" + props.getDevice().getId(); var practitionerRole = createPractitionerRole( @@ -861,77 +848,81 @@ public static Bundle createFhirBundle( ? testingLabOrganizationFullUrl : orderingFacilityFullUrl, practitionerFullUrl); - var provenance = createProvenance(testingLabOrganizationFullUrl, currentDate); + var provenance = createProvenance(testingLabOrganizationFullUrl, props.getCurrentDate()); var provenanceFullUrl = ResourceType.Provenance + "/" + provenance.getId(); var messageHeader = createMessageHeader( testingLabOrganizationFullUrl, diagnosticReportFullUrl, provenanceFullUrl, - gitProperties, - processingId); + props.getGitProperties(), + props.getProcessingId()); var practitionerRoleFullUrl = ResourceType.PractitionerRole + "/" + practitionerRole.getId(); var messageHeaderFullUrl = ResourceType.MessageHeader + "/" + messageHeader.getId(); - patient.setManagingOrganization(new Reference(testingLabOrganizationFullUrl)); - specimen.setSubject(new Reference(patientFullUrl)); + props.getPatient().setManagingOrganization(new Reference(testingLabOrganizationFullUrl)); + props.getSpecimen().setSubject(new Reference(patientFullUrl)); - serviceRequest.setSubject(new Reference(patientFullUrl)); - serviceRequest.addPerformer(new Reference(testingLabOrganizationFullUrl)); - serviceRequest.setRequester(new Reference(practitionerRoleFullUrl)); - diagnosticReport.addBasedOn(new Reference(serviceRequestFullUrl)); - diagnosticReport.setSubject(new Reference(patientFullUrl)); - diagnosticReport.addSpecimen(new Reference(specimenFullUrl)); + props.getServiceRequest().setSubject(new Reference(patientFullUrl)); + props.getServiceRequest().addPerformer(new Reference(testingLabOrganizationFullUrl)); + props.getServiceRequest().setRequester(new Reference(practitionerRoleFullUrl)); + props.getDiagnosticReport().addBasedOn(new Reference(serviceRequestFullUrl)); + props.getDiagnosticReport().setSubject(new Reference(patientFullUrl)); + props.getDiagnosticReport().addSpecimen(new Reference(specimenFullUrl)); var entryList = new ArrayList>(); entryList.add(Pair.of(messageHeaderFullUrl, messageHeader)); entryList.add(Pair.of(provenanceFullUrl, provenance)); - entryList.add(Pair.of(diagnosticReportFullUrl, diagnosticReport)); - entryList.add(Pair.of(patientFullUrl, patient)); - entryList.add(Pair.of(testingLabOrganizationFullUrl, testingLab)); + entryList.add(Pair.of(diagnosticReportFullUrl, props.getDiagnosticReport())); + entryList.add(Pair.of(patientFullUrl, props.getPatient())); + entryList.add(Pair.of(testingLabOrganizationFullUrl, props.getTestingLab())); if (orderingFacilityFullUrl != null) { - entryList.add(Pair.of(orderingFacilityFullUrl, orderingFacility)); + entryList.add(Pair.of(orderingFacilityFullUrl, props.getOrderingFacility())); } - entryList.add(Pair.of(practitionerFullUrl, practitioner)); - entryList.add(Pair.of(specimenFullUrl, specimen)); - entryList.add(Pair.of(serviceRequestFullUrl, serviceRequest)); - entryList.add(Pair.of(deviceFullUrl, device)); + entryList.add(Pair.of(practitionerFullUrl, props.getPractitioner())); + entryList.add(Pair.of(specimenFullUrl, props.getSpecimen())); + entryList.add(Pair.of(serviceRequestFullUrl, props.getServiceRequest())); + entryList.add(Pair.of(deviceFullUrl, props.getDevice())); entryList.add(Pair.of(practitionerRoleFullUrl, practitionerRole)); entryList.add( Pair.of( ResourceType.Organization + "/" + SIMPLE_REPORT_ORG_ID, new Organization().setName("SimpleReport").setId(SIMPLE_REPORT_ORG_ID))); - resultObservations.forEach( - observation -> { - var observationFullUrl = ResourceType.Observation + "/" + observation.getId(); - - observation.setSubject(new Reference(patientFullUrl)); - observation.addPerformer(new Reference(testingLabOrganizationFullUrl)); - observation.setSpecimen(new Reference(specimenFullUrl)); - observation.setDevice(new Reference(deviceFullUrl)); - - diagnosticReport.addResult(new Reference(observationFullUrl)); - entryList.add(Pair.of(observationFullUrl, observation)); - }); - - if (aoeObservations != null) { - aoeObservations.forEach( - observation -> { - var observationFullUrl = ResourceType.Observation + "/" + observation.getId(); - - observation.setSubject(new Reference(patientFullUrl)); - - serviceRequest.addSupportingInfo(new Reference(observationFullUrl)); - entryList.add(Pair.of(observationFullUrl, observation)); - }); + props + .getResultObservations() + .forEach( + observation -> { + var observationFullUrl = ResourceType.Observation + "/" + observation.getId(); + + observation.setSubject(new Reference(patientFullUrl)); + observation.addPerformer(new Reference(testingLabOrganizationFullUrl)); + observation.setSpecimen(new Reference(specimenFullUrl)); + observation.setDevice(new Reference(deviceFullUrl)); + + props.getDiagnosticReport().addResult(new Reference(observationFullUrl)); + entryList.add(Pair.of(observationFullUrl, observation)); + }); + + if (props.getAoeObservations() != null) { + props + .getAoeObservations() + .forEach( + observation -> { + var observationFullUrl = ResourceType.Observation + "/" + observation.getId(); + + observation.setSubject(new Reference(patientFullUrl)); + + props.getServiceRequest().addSupportingInfo(new Reference(observationFullUrl)); + entryList.add(Pair.of(observationFullUrl, observation)); + }); } var bundle = new Bundle() .setType(BundleType.MESSAGE) - .setTimestamp(currentDate) - .setIdentifier(new Identifier().setValue(diagnosticReport.getId())); + .setTimestamp(props.getCurrentDate()) + .setIdentifier(new Identifier().setValue(props.getDiagnosticReport().getId())); entryList.forEach( pair -> bundle.addEntry( diff --git a/backend/src/main/java/gov/cdc/usds/simplereport/utils/BulkUploadResultsToFhir.java b/backend/src/main/java/gov/cdc/usds/simplereport/utils/BulkUploadResultsToFhir.java index 74e7072ad1..5c4a961449 100644 --- a/backend/src/main/java/gov/cdc/usds/simplereport/utils/BulkUploadResultsToFhir.java +++ b/backend/src/main/java/gov/cdc/usds/simplereport/utils/BulkUploadResultsToFhir.java @@ -7,6 +7,10 @@ import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.parser.IParser; import com.fasterxml.jackson.databind.MappingIterator; +import gov.cdc.usds.simplereport.api.Translators; +import gov.cdc.usds.simplereport.api.converter.ConvertToObservationProps; +import gov.cdc.usds.simplereport.api.converter.ConvertToPatientProps; +import gov.cdc.usds.simplereport.api.converter.CreateFhirBundleProps; import gov.cdc.usds.simplereport.api.converter.FhirConverter; import gov.cdc.usds.simplereport.api.model.errors.CsvProcessingException; import gov.cdc.usds.simplereport.api.model.filerow.TestResultRow; @@ -142,23 +146,28 @@ private Bundle convertRowToFhirBundle(TestResultRow row, UUID orgId) { row.getOrderingFacilityState().value, row.getOrderingProviderZipCode().value, null); + var patient = FhirConverter.convertToPatient( - row.getPatientId().value, - new PersonName( - row.getPatientFirstName().value, - row.getPatientLastName().value, - row.getPatientMiddleName().value, - null), - List.of(new PhoneNumber(PhoneType.MOBILE, row.getPatientPhoneNumber().value)), - List.of(row.getPatientEmail().value), - row.getPatientGender().value, - LocalDate.parse(row.getPatientDob().value, dateTimeFormatter), - patientAddr, - DEFAULT_COUNTRY, - row.getPatientRace().value, - row.getPatientEthnicity().value, - new ArrayList<>()); + ConvertToPatientProps.builder() + .id(row.getPatientId().value) + .name( + new PersonName( + row.getPatientFirstName().value, + row.getPatientLastName().value, + row.getPatientMiddleName().value, + null)) + .phoneNumbers( + List.of(new PhoneNumber(PhoneType.MOBILE, row.getPatientPhoneNumber().value))) + .emails(List.of(row.getPatientEmail().value)) + .gender(row.getPatientGender().value) + .dob(LocalDate.parse(row.getPatientDob().value, dateTimeFormatter)) + .address(patientAddr) + .country(DEFAULT_COUNTRY) + .race(row.getPatientRace().value) + .ethnicity(row.getPatientEthnicity().value) + .tribalAffiliations(new ArrayList<>()) + .build()); var testingLabOrg = FhirConverter.convertToOrganization( orgId.toString(), @@ -244,16 +253,20 @@ private Bundle convertRowToFhirBundle(TestResultRow row, UUID orgId) { var observation = List.of( FhirConverter.convertToObservation( - row.getTestPerformedCode().value, - null, - getTestResultSnomed(row.getTestResult().value), - mapTestResultStatusToSRValue(row.getTestResultStatus().value), - null, - UUID.randomUUID().toString(), - getDescriptionValue(row.getTestResult().value), - testKitNameId, - equipmentUid, - row.getEquipmentModelName().value)); + ConvertToObservationProps.builder() + .diseaseCode(row.getTestPerformedCode().value) + .diseaseName(null) + .resultCode(getTestResultSnomed(row.getTestResult().value)) + .correctionStatus(mapTestResultStatusToSRValue(row.getTestResultStatus().value)) + .correctionReason(null) + .id(UUID.randomUUID().toString()) + .resultDescription( + Translators.convertConceptCodeToConceptName( + getDescriptionValue(row.getTestResult().value))) + .testkitNameId(testKitNameId) + .equipmentUid(equipmentUid) + .deviceModel(row.getEquipmentModelName().value) + .build())); var serviceRequest = FhirConverter.convertToServiceRequest( @@ -271,19 +284,21 @@ private Bundle convertRowToFhirBundle(TestResultRow row, UUID orgId) { new Date()); return FhirConverter.createFhirBundle( - patient, - testingLabOrg, - orderingFacility, - practitioner, - device, - specimen, - observation, - null, - serviceRequest, - diagnosticReport, - new Date(), - gitProperties, - processingModeCode); + CreateFhirBundleProps.builder() + .patient(patient) + .testingLab(testingLabOrg) + .orderingFacility(orderingFacility) + .practitioner(practitioner) + .device(device) + .specimen(specimen) + .resultObservations(observation) + .aoeObservations(null) + .serviceRequest(serviceRequest) + .diagnosticReport(diagnosticReport) + .currentDate(new Date()) + .gitProperties(gitProperties) + .processingId(processingModeCode) + .build()); } private String getTestResultSnomed(String input) { diff --git a/backend/src/test/java/gov/cdc/usds/simplereport/api/converter/FhirConverterTest.java b/backend/src/test/java/gov/cdc/usds/simplereport/api/converter/FhirConverterTest.java index 32c491c2dc..5fc43a29d1 100644 --- a/backend/src/test/java/gov/cdc/usds/simplereport/api/converter/FhirConverterTest.java +++ b/backend/src/test/java/gov/cdc/usds/simplereport/api/converter/FhirConverterTest.java @@ -609,18 +609,21 @@ void convertToSpecimen_SpecimenType_matchesJson() throws IOException { @Test void convertToObservation_Strings_valid() { + var actual = convertToObservation( - "diseaseCode", - "diseaseName", - "resultCode", - TestCorrectionStatus.ORIGINAL, - null, - "id-123", - TestResult.POSITIVE.toString(), - "testKitName", - "equipmentUid", - "modelName"); + ConvertToObservationProps.builder() + .diseaseCode("diseaseCode") + .diseaseName("diseaseName") + .resultCode("resultCode") + .correctionStatus(TestCorrectionStatus.ORIGINAL) + .correctionReason(null) + .id("id-123") + .resultDescription(TestResult.POSITIVE.toString()) + .testkitNameId("testKitName") + .equipmentUid("equipmentUid") + .deviceModel("modelName") + .build()); assertThat(actual.getId()).isEqualTo("id-123"); assertThat(actual.getStatus().getDisplay()).isEqualTo(ObservationStatus.FINAL.getDisplay()); @@ -1183,19 +1186,21 @@ void createFhirBundle_TestEvent_valid() { var actual = createFhirBundle( - patient, - organization, - null, - practitioner, - device, - specimen, - List.of(observation), - Set.of(aoeobservation1, aoeobservation2), - serviceRequest, - diagnosticReport, - date, - gitProperties, - "P"); + CreateFhirBundleProps.builder() + .patient(patient) + .testingLab(organization) + .orderingFacility(null) + .practitioner(practitioner) + .device(device) + .specimen(specimen) + .resultObservations(List.of(observation)) + .aoeObservations(Set.of(aoeobservation1, aoeobservation2)) + .serviceRequest(serviceRequest) + .diagnosticReport(diagnosticReport) + .currentDate(date) + .gitProperties(gitProperties) + .processingId("P") + .build()); var resourceUrls = actual.getEntry().stream() @@ -1346,6 +1351,7 @@ void createFhirBundle_TestEvent_matchesJson() throws IOException { var provider = new Provider(new PersonName("Michaela", null, "Quinn", ""), "1", address, "7735551235"); var organization = new Organization("District", "school", "1", true); + var facility = new Facility( organization,