Skip to content

Commit

Permalink
Merge pull request #933 from jewelbonnie/jb-jb-feature-techbdspring-c…
Browse files Browse the repository at this point in the history
…svfix-fourfilesmissinggroup

fix: Enable lazy resolution of multipart files in Spring configuration and solve data mapping issues in bundle api #745
  • Loading branch information
ratheesh-kr authored Dec 20, 2024
2 parents f5020b6 + 9f038a2 commit bd1f154
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,6 @@ public Map<String, Object> generateValidationResults(final String masterInteract
result.put("validationResults", combinedValidationResult);
result.put("requestUri", request.getRequestURI());
result.put("zipFileSize", zipFileSize);
result.put("noOfScreenings", combinedValidationResult.size());
result.put("userAgent", userAgent);
result.put("device", Map.of(
"deviceId", device.deviceId(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,29 +35,42 @@ public CsvToFhirConverter(AppConfig appConfig, BundleConverter bundleConverter,
}

public String convert(DemographicData demographicData,
QeAdminData qeAdminData, ScreeningProfileData screeningProfileData, List<ScreeningObservationData> screeningDataList, String interactionId) {
QeAdminData qeAdminData, ScreeningProfileData screeningProfileData,
List<ScreeningObservationData> screeningDataList, String interactionId) {
Bundle bundle = null;
try {
LOG.info("CsvToFhirConvereter::convert - BEGIN for interactionId :{}", interactionId);
bundle = bundleConverter.generateEmptyBundle(interactionId, appConfig.getIgVersion(),demographicData);
bundle = bundleConverter.generateEmptyBundle(interactionId, appConfig.getIgVersion(), demographicData);
LOG.debug("CsvToFhirConvereter::convert - Bundle entry created :{}", interactionId);
LOG.debug("Conversion of resources - BEGIN for interactionId :{}", interactionId);
addEntries(bundle, demographicData, screeningDataList, qeAdminData, screeningProfileData,interactionId);
addEntries(bundle, demographicData, screeningDataList, qeAdminData, screeningProfileData, interactionId);
LOG.debug("Conversion of resources - END for interactionId :{}", interactionId);
LOG.info("CsvToFhirConvereter::convert - END for interactionId :{}", interactionId);
} catch (Exception ex) {
LOG.error("Exception in Csv conversion for interaction id : {}", interactionId, ex);
}
return FhirContext.forR4().newJsonParser().encodeResourceToString(bundle);
}
private void addEntries(Bundle bundle, DemographicData demographicData, List<ScreeningObservationData> screeningObservationData,
QeAdminData qeAdminData,ScreeningProfileData screeningProfileData, String interactionId) {

private void addEntries(Bundle bundle, DemographicData demographicData,
List<ScreeningObservationData> screeningObservationData,
QeAdminData qeAdminData, ScreeningProfileData screeningProfileData, String interactionId) {
List<BundleEntryComponent> entries = new ArrayList<>();
Map<String,String> idsGenerated = new HashMap<>();
Map<String, String> idsGenerated = new HashMap<>();

// Iterate over the converters
converters.stream().forEach(converter -> {
entries.addAll(converter.convert(bundle, demographicData, qeAdminData,screeningProfileData,screeningObservationData, interactionId,idsGenerated));
try {
// Attempt to process using the current converter
entries.addAll(converter.convert(bundle, demographicData, qeAdminData, screeningProfileData,
screeningObservationData, interactionId, idsGenerated));
} catch (Exception e) {
// Log the error and continue with other converters
LOG.error("Error occurred while processing converter: " + converter.getClass().getName(), e);
}
});

// Add all successful entries to the bundle
bundle.getEntry().addAll(entries);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import org.techbd.util.CsvConversionUtil;
import org.techbd.util.DateUtil;

import ca.uhn.fhir.context.FhirContext;

/**
* Converts data into a FHIR Encounter resource.
*/
Expand Down Expand Up @@ -90,11 +92,12 @@ public List<BundleEntryComponent> convert(Bundle bundle, DemographicData demogra
Narrative text = new Narrative();
text.setStatus(NarrativeStatus.GENERATED);
encounter.setText(text);

BundleEntryComponent bundleEntryComponent = new BundleEntryComponent();
bundleEntryComponent.setFullUrl(fullUrl);
bundleEntryComponent.setRequest(new Bundle.BundleEntryRequestComponent().setMethod(HTTPVerb.POST).setUrl("http://shinny.org/us/ny/hrsn/Encounter/" + encounter.getId()));
bundleEntryComponent.setRequest(new Bundle.BundleEntryRequestComponent().setMethod(HTTPVerb.POST)
.setUrl("http://shinny.org/us/ny/hrsn/Encounter/" + encounter.getId()));
bundleEntryComponent.setResource(encounter);

return List.of(bundleEntryComponent);
}

Expand All @@ -117,7 +120,7 @@ private static void populateEncounterType(Encounter encounter, ScreeningProfileD

if (data.getEncounterTypeCode() != null) {
Coding coding = new Coding();
coding.setCode(data.getEncounterClassCode());
coding.setCode(data.getEncounterTypeCode());
coding.setSystem(data.getEncounterTypeCodeSystem());
coding.setDisplay(data.getEncounterTypeCodeDescription());
encounterType.addCoding(coding);
Expand Down Expand Up @@ -154,7 +157,8 @@ private void populateEncounterPeriod(Encounter encounter, ScreeningProfileData s
}
}

private void populateLocationReference(Encounter encounter, ScreeningProfileData screeningResourceData, Map<String, String> idsGenerated) {
private void populateLocationReference(Encounter encounter, ScreeningProfileData screeningResourceData,
Map<String, String> idsGenerated) {
if (screeningResourceData != null) {
encounter.addLocation(new Encounter.EncounterLocationComponent()
.setLocation(new Reference("Location/" + idsGenerated.get(CsvConstants.PATIENT_ID))));
Expand Down
1 change: 1 addition & 0 deletions hub-prime/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ spring:
max-file-size: 10MB
max-request-size: 10MB
file-size-threshold: 2MB
resolve-lazily: true
springdoc:
api-docs:
path: /docs/api/openapi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class ConsentConverterTest {
private ConsentConverter consentConverter;

@Test
@Disabled
//@Disabled
void testConvert() throws Exception {
// Create the necessary data objects for the test
final Bundle bundle = new Bundle();
Expand Down Expand Up @@ -63,7 +63,8 @@ void testConvert() throws Exception {

// Assert that the consent ID is not null or empty and matches expected
softly.assertThat(consent.getId()).isNotEmpty();
softly.assertThat(consent.getId()).isEqualTo("Consent-interactionId");
softly.assertThat(consent.getId()).matches("[a-f0-9]{64}");
// softly.assertThat(consent.getId()).isEqualTo("Consent-interactionId");

// Assert that the consent status is active
softly.assertThat(consent.getStatus()).isEqualTo(Consent.ConsentState.ACTIVE);
Expand All @@ -77,7 +78,7 @@ void testConvert() throws Exception {
}

@Test
@Disabled
// @Disabled
void testGeneratedJson() throws Exception {
final var bundle = new Bundle();
final var demographicData = CsvTestHelper.createDemographicData();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class EncounterConverterTest {
private EncounterConverter encounterConverter;

@Test
@Disabled
// @Disabled
void testConvert() throws Exception {
// Create necessary data objects for the test
final Bundle bundle = new Bundle();
Expand All @@ -44,44 +44,46 @@ void testConvert() throws Exception {
final QeAdminData qrAdminData = CsvTestHelper.createQeAdminData();
final ScreeningProfileData screeningResourceData = CsvTestHelper.createScreeningProfileData();
final Map<String, String> idsGenerated = new HashMap<>();

// Instantiate the EncounterConverter
EncounterConverter encounterConverter = new EncounterConverter();

// Call the convert method of the encounter converter
final BundleEntryComponent result = encounterConverter.convert(bundle, demographicData, qrAdminData, screeningResourceData,
screeningDataList, "interactionId", idsGenerated).get(0);;

final BundleEntryComponent result = encounterConverter
.convert(bundle, demographicData, qrAdminData, screeningResourceData,
screeningDataList, "interactionId", idsGenerated)
.get(0);
;

// Create soft assertions to verify the result
final SoftAssertions softly = new SoftAssertions();

// Assert that the result is not null
softly.assertThat(result).isNotNull();

// Assert that the result resource is an instance of Encounter
softly.assertThat(result.getResource()).isInstanceOf(Encounter.class);

// Cast the result to Encounter and assert various properties
final Encounter encounter = (Encounter) result.getResource();

// Assert that the encounter ID is not null or empty and matches expected
softly.assertThat(encounter.getId()).isNotEmpty();
softly.assertThat(encounter.getId()).isEqualTo("Encounter-interactionId");
softly.assertThat(encounter.getId()).matches("[a-f0-9]{64}");

// Assert that the encounter status is active (FINISHED)
//softly.assertThat(encounter.getStatus()).isEqualTo("FINISHED");
// softly.assertThat(encounter.getStatus()).isEqualTo("FINISHED");

// Assert that the encounter has the correct encounter type
softly.assertThat(encounter.getType()).hasSize(1);
softly.assertThat(encounter.getTypeFirstRep().getCodingFirstRep().getCode()).isEqualTo("405672008");

// Assert all soft assertions
softly.assertAll();
}


@Test
@Disabled
//@Disabled
void testGeneratedJson() throws Exception {
final var bundle = new Bundle();
final var demographicData = CsvTestHelper.createDemographicData();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class SexualOrientationObservationConverterTest {
private SexualOrientationObservationConverter sexualOrientationObservationConverter;

@Test
@Disabled
//@Disabled
void testConvert() throws Exception {
final Bundle bundle = new Bundle();
final List<ScreeningObservationData> screeningDataList = CsvTestHelper.createScreeningObservationData();
Expand Down Expand Up @@ -69,7 +69,7 @@ void testConvert() throws Exception {
}

@Test
@Disabled
//@Disabled
void testGeneratedJson() throws Exception {
final var bundle = new Bundle();
final var demographicData = CsvTestHelper.createDemographicData();
Expand Down

0 comments on commit bd1f154

Please sign in to comment.