Skip to content

Commit

Permalink
recreating PR because reasons
Browse files Browse the repository at this point in the history
pr feedback

async fhir conversion + processing for bulk upload

updating test
  • Loading branch information
DanielSass committed Mar 24, 2023
1 parent c559be2 commit de393cf
Show file tree
Hide file tree
Showing 5 changed files with 496 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -306,46 +306,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 @@ -354,13 +415,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 @@ -661,6 +724,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 @@ -679,7 +743,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 @@ -691,31 +756,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 @@ -726,7 +800,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 @@ -742,23 +819,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 @@ -10,4 +10,6 @@ public interface DeviceTypeRepository extends EternalAuditedEntityRepository<Dev
List<DeviceType> findAllByInternalIdIn(Collection<UUID> ids);

DeviceType findDeviceTypeByName(String name);

DeviceType findDeviceTypeByModelIgnoreCase(String model);
}
Loading

0 comments on commit de393cf

Please sign in to comment.