Skip to content

Commit

Permalink
Merge pull request #915 from Shreeja-dev/745-csv-validate-new
Browse files Browse the repository at this point in the history
feat:added missing fields#745
  • Loading branch information
ratheesh-kr authored Dec 19, 2024
2 parents 6a04cdd + 3978b41 commit 7e00bca
Show file tree
Hide file tree
Showing 13 changed files with 69 additions and 103 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public ResourceType getResourceType() {
*/
public Bundle generateEmptyBundle(String interactionId,String igVersion,DemographicData demographicData) {
Bundle bundle = new Bundle();
bundle.setId("AHCHRSNScreeningResponse-"+CsvConversionUtil.sha256(demographicData.getPatientMrIdValue()));
bundle.setId(CsvConversionUtil.sha256(demographicData.getPatientMrIdValue()));
bundle.setType(Bundle.BundleType.TRANSACTION);
Meta meta = new Meta();
meta.setLastUpdated(DateUtil.parseDate(demographicData.getPatientLastUpdated()));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package org.techbd.service.converters.shinny;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.hl7.fhir.r4.model.Attachment;
import org.hl7.fhir.r4.model.Bundle;
import org.hl7.fhir.r4.model.Bundle.BundleEntryComponent;
import org.hl7.fhir.r4.model.Bundle.HTTPVerb;
import org.hl7.fhir.r4.model.CodeableConcept;
import org.hl7.fhir.r4.model.Coding;
import org.hl7.fhir.r4.model.Consent;
Expand Down Expand Up @@ -78,7 +76,7 @@ public List<BundleEntryComponent> convert(Bundle bundle,DemographicData demogra
consent.setId(CsvConversionUtil.sha256(screeningProfileData.getEncounterId()));

Meta meta = consent.getMeta();
meta.setLastUpdated(getLastUpdatedDate(screeningProfileData));
meta.setLastUpdated(DateUtil.parseDate(screeningProfileData.getConsentLastUpdated()));

populateConsentStatusAndScope(consent, screeningProfileData);

Expand All @@ -103,6 +101,7 @@ public List<BundleEntryComponent> convert(Bundle bundle,DemographicData demogra
String fullUrl = "http://shinny.org/us/ny/hrsn/Consent/" + consent.getId();
BundleEntryComponent bundleEntryComponent = new BundleEntryComponent();
bundleEntryComponent.setFullUrl(fullUrl);
bundleEntryComponent.setRequest(new Bundle.BundleEntryRequestComponent().setMethod(HTTPVerb.POST).setUrl("http://shinny.org/us/ny/hrsn/Consent/" + consent.getId()));
bundleEntryComponent.setResource(consent);
return List.of(bundleEntryComponent);
}
Expand Down Expand Up @@ -193,26 +192,6 @@ public static void populateConsentDateTime(Consent consent, ScreeningProfileData
consent.setDateTime(DateUtil.convertStringToDate(consentDateTime));
}

/**
* Get the last updated date for the consent based on its data from QeAdminData.
*
* @param qrAdminData The QeAdminData object containing the consent's last
* updated date.
* @return The last updated date.
*/
private Date getLastUpdatedDate(ScreeningProfileData screeningResourceData) {
if (screeningResourceData != null && screeningResourceData.getConsentLastUpdated() != null
&& !screeningResourceData.getConsentLastUpdated().isEmpty()) {
try {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
return dateFormat.parse(screeningResourceData.getConsentLastUpdated());
} catch (ParseException e) {
LOG.error("Error parsing last updated date", e);
}
}
return new Date();
}

private void populateSourceAttachment(Consent consent) {
Attachment attachment = new Attachment();
attachment.setContentType("application/pdf");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package org.techbd.service.converters.shinny;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.hl7.fhir.r4.model.Bundle;
import org.hl7.fhir.r4.model.Bundle.BundleEntryComponent;
import org.hl7.fhir.r4.model.Bundle.HTTPVerb;
import org.hl7.fhir.r4.model.CodeableConcept;
import org.hl7.fhir.r4.model.Coding;
import org.hl7.fhir.r4.model.Encounter;
Expand Down Expand Up @@ -76,7 +74,7 @@ public List<BundleEntryComponent> convert(Bundle bundle, DemographicData demogra
String fullUrl = "http://shinny.org/us/ny/hrsn/Encounter/" + encounter.getId();

Meta meta = encounter.getMeta();
meta.setLastUpdated(getLastUpdatedDate(qeAdminData));
meta.setLastUpdated(DateUtil.parseDate(qeAdminData.getFacilityLastUpdated()));

populateEncounterStatus(encounter, screeningProfileData);

Expand All @@ -95,6 +93,7 @@ public List<BundleEntryComponent> convert(Bundle bundle, DemographicData demogra

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.setResource(encounter);
return List.of(bundleEntryComponent);
}
Expand Down Expand Up @@ -161,25 +160,4 @@ private void populateLocationReference(Encounter encounter, ScreeningProfileData
.setLocation(new Reference("Location/" + "LocationExample-SCN")));
}
}

/**
* Get the last updated date for the encounter based on its data from
* QeAdminData.
*
* @param qrAdminData The QeAdminData object containing the encounter's last
* updated date.
* @return The last updated date.
*/
private Date getLastUpdatedDate(QeAdminData qrAdminData) {
if (qrAdminData != null && qrAdminData.getFacilityLastUpdated() != null
&& !qrAdminData.getFacilityLastUpdated().isEmpty()) {
try {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
return dateFormat.parse(qrAdminData.getFacilityLastUpdated());
} catch (ParseException e) {
LOG.error("Error parsing last updated date", e);
}
}
return new Date();
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
package org.techbd.service.converters.shinny;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.hl7.fhir.r4.model.Address;
import org.hl7.fhir.r4.model.Bundle;
import org.hl7.fhir.r4.model.Bundle.BundleEntryComponent;
import org.hl7.fhir.r4.model.Bundle.HTTPVerb;
import org.hl7.fhir.r4.model.CodeableConcept;
import org.hl7.fhir.r4.model.Coding;
import org.hl7.fhir.r4.model.Identifier;
Expand All @@ -28,6 +26,7 @@
import org.techbd.model.csv.ScreeningProfileData;
import org.techbd.util.CsvConstants;
import org.techbd.util.CsvConversionUtil;
import org.techbd.util.DateUtil;

/**
* Converts data related to an Organization into a FHIR Organization resource.
Expand Down Expand Up @@ -70,14 +69,17 @@ public List<BundleEntryComponent> convert(Bundle bundle,DemographicData demogra
setMeta(organization);
organization.setId(CsvConversionUtil.sha256(qeAdminData.getFacilityId())); // Assuming qrAdminData contains orgId
idsGenerated.put(CsvConstants.ORGANIZATION_ID,organization.getId());
String fullUrl = "http://shinny.org/us/ny/hrsn/Organization/" + organization.getId();
Meta meta = organization.getMeta();
meta.setLastUpdated(getLastUpdatedDate(qeAdminData));
meta.setLastUpdated(DateUtil.parseDate(qeAdminData.getFacilityLastUpdated()));
populateOrganizationName(organization, qeAdminData);
populateOrganizationIdentifier(organization, qeAdminData);
populateIsActive(organization, qeAdminData);
populateOrganizationType(organization, qeAdminData);
populateOrganizationAddress(organization, qeAdminData);
BundleEntryComponent bundleEntryComponent = new BundleEntryComponent();
bundleEntryComponent.setFullUrl(fullUrl);
bundleEntryComponent.setRequest(new Bundle.BundleEntryRequestComponent().setMethod(HTTPVerb.POST).setUrl("http://shinny.org/us/ny/hrsn/Organization/" + organization.getId()));
bundleEntryComponent.setResource(organization);
return List.of(bundleEntryComponent);
}
Expand Down Expand Up @@ -155,28 +157,4 @@ private static void populateIsActive(Organization organization, QeAdminData qrAd
organization.setActive(Boolean.parseBoolean("TRUE"));
}
}

/**
* Get the last updated date for the organization based on its data from
* QeAdminData.
*
* @param qrAdminData The QeAdminData object containing the facility's last
* updated date.
* @return The last updated date.
*/
private Date getLastUpdatedDate(QeAdminData qrAdminData) {
// Check if the facilityLastUpdated field in QeAdminData is not null or empty
if (qrAdminData != null && qrAdminData.getFacilityLastUpdated() != null
&& !qrAdminData.getFacilityLastUpdated().isEmpty()) {
try {
// Example: Assuming the format is "yyyy-MM-dd'T'HH:mm:ss'Z'" (ISO 8601 format)
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
return dateFormat.parse(qrAdminData.getFacilityLastUpdated()); // Return the parsed date
} catch (ParseException e) {
return new Date();
}
}
return new Date();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.hl7.fhir.r4.model.Address;
import org.hl7.fhir.r4.model.Bundle;
import org.hl7.fhir.r4.model.Bundle.BundleEntryComponent;
import org.hl7.fhir.r4.model.Bundle.HTTPVerb;
import org.hl7.fhir.r4.model.CodeableConcept;
import org.hl7.fhir.r4.model.Coding;
import org.hl7.fhir.r4.model.ContactPoint;
Expand Down Expand Up @@ -97,6 +98,7 @@ public List<BundleEntryComponent> convert(Bundle bundle, DemographicData demogra
// populatePatientText(patient, demographicData);
BundleEntryComponent bundleEntryComponent = new BundleEntryComponent();
bundleEntryComponent.setFullUrl(fullUrl);
bundleEntryComponent.setRequest(new Bundle.BundleEntryRequestComponent().setMethod(HTTPVerb.POST).setUrl("http://shinny.org/us/ny/hrsn/Patient/" + patient.getId()));
bundleEntryComponent.setResource(patient);
LOG.info("PatientConverter :: convert END for transaction id :{}", interactionId);
return List.of(bundleEntryComponent);
Expand Down Expand Up @@ -246,7 +248,7 @@ private static void populateSsnIdentifier(Patient patient, DemographicData data)
Identifier identifier = new Identifier();
Coding coding = new Coding();
coding.setSystem("http://terminology.hl7.org/CodeSystem/v2-0203"); // TODO : remove static reference
coding.setCode("SSN");
coding.setCode("SS");
coding.setDisplay("Social Security Number");
CodeableConcept type = new CodeableConcept();
type.addCoding(coding);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import org.hl7.fhir.r4.model.Bundle;
import org.hl7.fhir.r4.model.Bundle.BundleEntryComponent;
import org.hl7.fhir.r4.model.Bundle.HTTPVerb;
import org.hl7.fhir.r4.model.CodeableConcept;
import org.hl7.fhir.r4.model.Coding;
import org.hl7.fhir.r4.model.DateTimeType;
Expand Down Expand Up @@ -52,8 +53,9 @@ public List<BundleEntryComponent> convert(

for (ScreeningObservationData data : screeningObservationDataList) {
Observation observation = new Observation();
String observationId = CsvConversionUtil.sha256(data.getEncounterId()+data.getScreeningCode()); // Use screening code as ID
String fullUrl = "http://shinny.org/us/ny/hrsn/Observation/" + observationId;
String observationId = CsvConversionUtil.sha256(data.getEncounterId()+data.getScreeningCode()); // Use screening code as ID'
observation.setId(observationId);
String fullUrl = "http://shinny.org/us/ny/hrsn/Observation/" + data.getQuestionCode();
setMeta(observation);
Meta meta = observation.getMeta();
meta.setLastUpdated(DateUtil.parseDate(demographicData.getPatientLastUpdated())); // max date available in all
Expand All @@ -70,7 +72,7 @@ public List<BundleEntryComponent> convert(
observation.addCategory(createCategory("http://terminology.hl7.org/CodeSystem/observation-category",
"survey", null));
CodeableConcept code = new CodeableConcept();
code.addCoding(new Coding("http://loinc.org", data.getScreeningCode(), data.getScreeningCodeDescription()));
code.addCoding(new Coding("http://loinc.org", data.getQuestionCode(), data.getQuestionCodeDisplay()));
code.setText(data.getQuestionCodeText());
observation.setCode(code);
observation.setSubject(new Reference("Patient/" +idsGenerated.get(CsvConstants.PATIENT_ID)));
Expand All @@ -83,6 +85,7 @@ public List<BundleEntryComponent> convert(
observation.setValue(value);
BundleEntryComponent entry = new BundleEntryComponent();
entry.setFullUrl(fullUrl);
entry.setRequest(new Bundle.BundleEntryRequestComponent().setMethod(HTTPVerb.POST).setUrl("http://shinny.org/us/ny/hrsn/Observation/" + observationId));
entry.setResource(observation);
bundleEntryComponents.add(entry);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import org.hl7.fhir.r4.model.Bundle;
import org.hl7.fhir.r4.model.Bundle.BundleEntryComponent;
import org.hl7.fhir.r4.model.Bundle.HTTPVerb;
import org.hl7.fhir.r4.model.CanonicalType;
import org.hl7.fhir.r4.model.CodeableConcept;
import org.hl7.fhir.r4.model.Coding;
Expand Down Expand Up @@ -48,8 +49,7 @@ public List<BundleEntryComponent> convert(Bundle bundle,DemographicData demogr
setMeta(observation);
observation.setId("SexualOrientation-" +CsvConversionUtil.sha256(screeningProfileData.getEncounterId()));
Meta meta = observation.getMeta();
String fullUrl = "http://shinny.org/us/ny/hrsn/Observation" + observation.getId();
meta.setLastUpdated(DateUtil.parseDate(demographicData.getPatientLastUpdated()));
String fullUrl = "http://shinny.org/us/ny/hrsn/Observation/" + observation.getId();
meta.setLastUpdated(DateUtil.parseDate(demographicData.getPatientLastUpdated()));
observation.setStatus(Observation.ObservationStatus.fromCode("final")); //TODO : remove static reference
Reference subjectReference = new Reference();
Expand All @@ -71,6 +71,7 @@ public List<BundleEntryComponent> convert(Bundle bundle,DemographicData demogr
observation.setText(text);
BundleEntryComponent entry = new BundleEntryComponent();
entry.setFullUrl(fullUrl);
entry.setRequest(new Bundle.BundleEntryRequestComponent().setMethod(HTTPVerb.POST).setUrl("http://shinny.org/us/ny/hrsn/Observation/" + observation.getId()));
entry.setResource(observation);
LOG.info("SexualOrientationObservationConverter:: convert END for interaction id :{} ", interactionId);
return List.of(entry);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.assertj.core.api.SoftAssertions;
import org.hl7.fhir.r4.model.Bundle;
Expand Down Expand Up @@ -40,11 +42,12 @@ void testConvert() throws Exception {
final DemographicData demographicData = CsvTestHelper.createDemographicData();
final List<ScreeningObservationData> screeningDataList = CsvTestHelper.createScreeningObservationData();
final QeAdminData qrAdminData = CsvTestHelper.createQeAdminData();
final Map<String, String> idsGenerated = new HashMap<>();
final ScreeningProfileData screeningResourceData = CsvTestHelper.createScreeningProfileData();

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

// Create soft assertions to verify the result
final SoftAssertions softly = new SoftAssertions();
Expand Down Expand Up @@ -80,11 +83,12 @@ void testGeneratedJson() throws Exception {
final var demographicData = CsvTestHelper.createDemographicData();
final var screeningDataList = CsvTestHelper.createScreeningObservationData();
final var qrAdminData = CsvTestHelper.createQeAdminData();
final Map<String, String> idsGenerated = new HashMap<>();
final ScreeningProfileData screeningResourceData = CsvTestHelper.createScreeningProfileData();

final var result = consentConverter.convert(bundle, demographicData, qrAdminData, screeningResourceData,
screeningDataList,
"interactionId",null);
"interactionId", idsGenerated);

final Consent consent = (Consent) result.get(0).getResource();
final var filePath = "src/test/resources/org/techbd/csv/generated-json/consent.json";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.assertj.core.api.SoftAssertions;
import org.hl7.fhir.r4.model.Bundle;
Expand Down Expand Up @@ -36,18 +38,19 @@ class EncounterConverterTest {
@Disabled
void testConvert() throws Exception {
// Create necessary data objects for the test
final Bundle bundle = new Bundle(); // Ensure this is populated with relevant data
final DemographicData demographicData = CsvTestHelper.createDemographicData(); // Create DemographicData instance
final List<ScreeningObservationData> screeningDataList = CsvTestHelper.createScreeningObservationData(); // Create list of ScreeningData
final QeAdminData qrAdminData = CsvTestHelper.createQeAdminData(); // Create QeAdminData instance
final ScreeningProfileData screeningResourceData = CsvTestHelper.createScreeningProfileData(); // Create ScreeningResourceData
final Bundle bundle = new Bundle();
final DemographicData demographicData = CsvTestHelper.createDemographicData();
final List<ScreeningObservationData> screeningDataList = CsvTestHelper.createScreeningObservationData();
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", null).get(0);;
screeningDataList, "interactionId", idsGenerated).get(0);;

// Create soft assertions to verify the result
final SoftAssertions softly = new SoftAssertions();
Expand Down Expand Up @@ -84,11 +87,12 @@ void testGeneratedJson() throws Exception {
final var demographicData = CsvTestHelper.createDemographicData();
final var screeningDataList = CsvTestHelper.createScreeningObservationData();
final var qrAdminData = CsvTestHelper.createQeAdminData();
final Map<String, String> idsGenerated = new HashMap<>();
final ScreeningProfileData screeningResourceData = CsvTestHelper.createScreeningProfileData();

final var result = encounterConverter.convert(bundle, demographicData, qrAdminData, screeningResourceData,
screeningDataList,
"interactionId", null);
"interactionId", idsGenerated);

final Encounter encounter = (Encounter) result.get(0).getResource();
final var filePath = "src/test/resources/org/techbd/csv/generated-json/encounter.json";
Expand Down
Loading

0 comments on commit 7e00bca

Please sign in to comment.