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

Bulk Upload Fhir Conversion #5511

Merged
merged 3 commits into from
Mar 27, 2023
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 @@ -308,46 +308,107 @@ public static Optional<Extension> convertToTribalAffiliationExtension(String tri
}

public static Practitioner convertToPractitioner(Provider provider) {
var practitioner = new Practitioner();
practitioner.setId(provider.getInternalId().toString());
practitioner.addName(convertToHumanName(provider.getNameInfo()));
practitioner.addAddress(convertToAddress(provider.getAddress(), DEFAULT_COUNTRY));
practitioner.addTelecom(convertToContactPoint(ContactPointUse.WORK, provider.getTelephone()));
return convertToPractitioner(
provider.getInternalId().toString(),
provider.getNameInfo(),
provider.getTelephone(),
provider.getAddress(),
DEFAULT_COUNTRY);
}

public static Practitioner convertToPractitioner(
String id, PersonName name, String telephone, StreetAddress addr, String country) {
var practitioner =
new Practitioner()
.addName(convertToHumanName(name))
.addAddress(convertToAddress(addr, country))
.addTelecom(convertToContactPoint(ContactPointUse.WORK, telephone));
practitioner.setId(id);
return practitioner;
}

public static Organization convertToOrganization(Facility facility) {
var org = new Organization();
org.setId(facility.getInternalId().toString());
return convertToOrganization(
facility.getInternalId().toString(),
facility.getFacilityName(),
facility.getCliaNumber(),
facility.getTelephone(),
facility.getEmail(),
facility.getAddress(),
DEFAULT_COUNTRY);
}

public static Organization convertToOrganization(
String id,
String name,
String clia,
String telephone,
String email,
StreetAddress addr,
String country) {
var org =
new Organization()
.setName(name)
.addAddress(convertToAddress(addr, country))
.addTelecom(convertToContactPoint(ContactPointUse.WORK, telephone));

org.addIdentifier()
.setUse(IdentifierUse.OFFICIAL)
.setValue(facility.getCliaNumber())
.setValue(clia)
.getType()
.addCoding()
.setSystem(UNIVERSAL_ID_SYSTEM)
.setCode("CLIA");
org.setName(facility.getFacilityName());
org.addTelecom(convertToContactPoint(ContactPointUse.WORK, facility.getTelephone()));
org.addTelecom(convertEmailToContactPoint(ContactPointUse.WORK, facility.getEmail()));
org.addAddress(convertToAddress(facility.getAddress(), DEFAULT_COUNTRY));

if (email != null && !email.isBlank()) {
org.addTelecom(convertEmailToContactPoint(ContactPointUse.WORK, email));
}
org.setId(id);
return org;
}

public static Patient convertToPatient(Person person) {
var patient = new Patient();
patient.setId(person.getInternalId().toString());
patient.addIdentifier().setValue(person.getInternalId().toString());
patient.addName(convertToHumanName(person.getNameInfo()));
convertPhoneNumbersToContactPoint(person.getPhoneNumbers()).forEach(patient::addTelecom);
convertEmailsToContactPoint(ContactPointUse.HOME, person.getEmails())
.forEach(patient::addTelecom);
patient.setGender(convertToAdministrativeGender(person.getGender()));
patient.setBirthDate(convertToDate(person.getBirthDate()));
patient.addAddress(convertToAddress(person.getAddress(), person.getCountry()));
patient.addExtension(convertToRaceExtension(person.getRace()));
patient.addExtension(convertToEthnicityExtension(person.getEthnicity()));
patient.addExtension(
convertToTribalAffiliationExtension(person.getTribalAffiliation()).orElse(null));
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<PhoneNumber> phoneNumbers,
List<String> emails,
String gender,
LocalDate dob,
StreetAddress address,
String country,
String race,
String ethnicity,
List<String> tribalAffiliations) {
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);
return patient;
}

Expand All @@ -356,13 +417,15 @@ public static Device convertToDevice(@NotNull DeviceType deviceType) {
deviceType.getManufacturer(), deviceType.getModel(), deviceType.getInternalId().toString());
}

public static Device convertToDevice(
@NotNull String manufacturer, @NotNull String model, String id) {
public static Device convertToDevice(String manufacturer, @NotNull String model, String id) {
var device =
new Device()
.setManufacturer(manufacturer)
.addDeviceName(
new DeviceDeviceNameComponent().setName(model).setType(DeviceNameType.MODELNAME));
if (manufacturer != null) {
device.setManufacturer(manufacturer);
}

device.setId(id);
return device;
}
Expand Down Expand Up @@ -696,6 +759,7 @@ public static Bundle createFhirBundle(
return createFhirBundle(
convertToPatient(testEvent.getPatient()),
convertToOrganization(testEvent.getFacility()),
null,
convertToPractitioner(testEvent.getProviderData()),
convertToDevice(testEvent.getDeviceType()),
convertToSpecimen(testEvent.getSpecimenType()),
Expand All @@ -714,7 +778,8 @@ public static Bundle createFhirBundle(

public static Bundle createFhirBundle(
Patient patient,
Organization organization,
Organization testingLab,
Organization orderingFacility,
Practitioner practitioner,
Device device,
Specimen specimen,
Expand All @@ -726,31 +791,40 @@ public static Bundle createFhirBundle(
GitProperties gitProperties,
String processingId) {
var patientFullUrl = ResourceType.Patient + "/" + patient.getId();
var organizationFullUrl = ResourceType.Organization + "/" + organization.getId();
var orderingFacilityFullUrl =
orderingFacility == 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();

var practitionerRole = createPractitionerRole(organizationFullUrl, practitionerFullUrl);
var provenance = createProvenance(organizationFullUrl, currentDate);
var practitionerRole =
createPractitionerRole(
orderingFacilityFullUrl == null
? testingLabOrganizationFullUrl
: orderingFacilityFullUrl,
practitionerFullUrl);
var provenance = createProvenance(testingLabOrganizationFullUrl, currentDate);
var provenanceFullUrl = ResourceType.Provenance + "/" + provenance.getId();
var messageHeader =
createMessageHeader(
organizationFullUrl,
testingLabOrganizationFullUrl,
diagnosticReportFullUrl,
provenanceFullUrl,
gitProperties,
processingId);
var practitionerRoleFullUrl = ResourceType.PractitionerRole + "/" + practitionerRole.getId();
var messageHeaderFullUrl = ResourceType.MessageHeader + "/" + messageHeader.getId();

patient.setManagingOrganization(new Reference(organizationFullUrl));
patient.setManagingOrganization(new Reference(testingLabOrganizationFullUrl));
specimen.setSubject(new Reference(patientFullUrl));

serviceRequest.setSubject(new Reference(patientFullUrl));
serviceRequest.addPerformer(new Reference(organizationFullUrl));
serviceRequest.addPerformer(new Reference(testingLabOrganizationFullUrl));
serviceRequest.setRequester(new Reference(practitionerRoleFullUrl));
diagnosticReport.addBasedOn(new Reference(serviceRequestFullUrl));
diagnosticReport.setSubject(new Reference(patientFullUrl));
Expand All @@ -761,7 +835,10 @@ public static Bundle createFhirBundle(
entryList.add(Pair.of(provenanceFullUrl, provenance));
entryList.add(Pair.of(diagnosticReportFullUrl, diagnosticReport));
entryList.add(Pair.of(patientFullUrl, patient));
entryList.add(Pair.of(organizationFullUrl, organization));
entryList.add(Pair.of(testingLabOrganizationFullUrl, testingLab));
if (orderingFacilityFullUrl != null) {
entryList.add(Pair.of(orderingFacilityFullUrl, orderingFacility));
}
entryList.add(Pair.of(practitionerFullUrl, practitioner));
entryList.add(Pair.of(specimenFullUrl, specimen));
entryList.add(Pair.of(serviceRequestFullUrl, serviceRequest));
Expand All @@ -777,23 +854,25 @@ public static Bundle createFhirBundle(
var observationFullUrl = ResourceType.Observation + "/" + observation.getId();

observation.setSubject(new Reference(patientFullUrl));
observation.addPerformer(new Reference(organizationFullUrl));
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));
});

aoeObservations.forEach(
observation -> {
var observationFullUrl = ResourceType.Observation + "/" + observation.getId();
if (aoeObservations != null) {
aoeObservations.forEach(
observation -> {
var observationFullUrl = ResourceType.Observation + "/" + observation.getId();

observation.setSubject(new Reference(patientFullUrl));
observation.setSubject(new Reference(patientFullUrl));

serviceRequest.addSupportingInfo(new Reference(observationFullUrl));
entryList.add(Pair.of(observationFullUrl, observation));
});
serviceRequest.addSupportingInfo(new Reference(observationFullUrl));
entryList.add(Pair.of(observationFullUrl, observation));
});
}

var bundle =
new Bundle()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,18 @@
import java.util.Collection;
import java.util.List;
import java.util.UUID;
import org.springframework.data.jpa.repository.EntityGraph;

/** Specification of EternalAuditedEntityRepository for {@link DeviceType} manipulation. */
public interface DeviceTypeRepository extends EternalAuditedEntityRepository<DeviceType> {
List<DeviceType> findAllByInternalIdIn(Collection<UUID> ids);

DeviceType findDeviceTypeByName(String name);

@EntityGraph(
attributePaths = {
"supportedDiseaseTestPerformed",
"supportedDiseaseTestPerformed.supportedDisease"
})
DeviceType findDeviceTypeByModelIgnoreCase(String model);
}
Loading