Skip to content

Commit

Permalink
transfer logic to fhirtransform
Browse files Browse the repository at this point in the history
  • Loading branch information
mherman22 committed Sep 2, 2024
1 parent 1539e4f commit e04b7b4
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ public class PatientSearchResultsForm implements IPagingForm {
@Setter
private List<PatientSearchResults> patientSearchResults;

@Setter
@Getter
private List<PatientSearchResults> externalSearchResults;

@Override
public void setPaging(PagingBean pagingBean) {
this.paging = pagingBean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import ca.uhn.fhir.rest.param.TokenParam;
import java.lang.reflect.InvocationTargetException;
import java.math.BigDecimal;
import java.sql.Timestamp;
import java.util.*;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletRequest;
Expand All @@ -23,20 +22,20 @@
import org.openelisglobal.common.rest.util.PatientSearchResultsPaging;
import org.openelisglobal.common.util.ConfigurationProperties;
import org.openelisglobal.common.util.ConfigurationProperties.Property;
import org.openelisglobal.common.util.DateUtil;
import org.openelisglobal.dataexchange.fhir.FhirConfig;
import org.openelisglobal.dataexchange.fhir.FhirUtil;
import org.openelisglobal.dataexchange.fhir.service.FhirTransformService;
import org.openelisglobal.internationalization.MessageUtil;
import org.openelisglobal.observationhistory.service.ObservationHistoryService;
import org.openelisglobal.observationhistory.service.ObservationHistoryServiceImpl.ObservationType;
import org.openelisglobal.patient.service.PatientService;
import org.openelisglobal.patient.valueholder.Patient;
import org.openelisglobal.person.service.PersonService;
import org.openelisglobal.person.valueholder.Person;
import org.openelisglobal.sample.service.SampleService;
import org.openelisglobal.sample.valueholder.Sample;
import org.openelisglobal.samplehuman.service.SampleHumanService;
import org.openelisglobal.search.service.SearchResultsService;
import org.openelisglobal.spring.util.SpringContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -112,7 +111,6 @@ public PatientSearchResultsForm getPatientResults(HttpServletRequest request,
if (request.getParameter("crResult") != null && request.getParameter("crResult").contains("true")) {
List<PatientSearchResults> fhirResults = searchPatientInClientRegistry(nationalID);
results.addAll(fhirResults);
form.setExternalSearchResults(fhirResults);
}

paging.setDatabaseResults(request, form, results);
Expand Down Expand Up @@ -173,72 +171,6 @@ private List<org.hl7.fhir.r4.model.Patient> parseCRPatientSearchResults(Bundle p
.map(entry -> (org.hl7.fhir.r4.model.Patient) entry.getResource()).collect(Collectors.toList());
}

public Patient transformFhirPatientObjectToOpenElisPatientObject(Patient openELISPatient,
org.hl7.fhir.r4.model.Patient fhirPatient) {
for (Identifier identifier : fhirPatient.getIdentifier()) {
String system = identifier.getSystem();
String value = identifier.getValue();
if ("http://openelis-global.org/pat_nationalId".equals(system)) {
openELISPatient.setNationalId(value);
} else if ("http://openelis-global.org/pat_guid".equals(system)) {
openELISPatient.setExternalId(value);
} else if ("http://openelis-global.org/pat_uuid".equals(system)) {
openELISPatient.setFhirUuid(UUID.fromString(value));
}
}

if (!fhirPatient.getName().isEmpty()) {
HumanName name = fhirPatient.getNameFirstRep();
openELISPatient.setEpiFirstName(name.getGivenAsSingleString());
openELISPatient.setEpiLastName(name.getFamily());
}

if (!fhirPatient.getTelecom().isEmpty()) {
ContactPoint telecom = fhirPatient.getTelecomFirstRep();
if (ContactPoint.ContactPointSystem.PHONE.equals(telecom.getSystem())) {
Person person = openELISPatient.getPerson();
if (person == null) {
person = new Person();
openELISPatient.setPerson(person);
}
person.setPrimaryPhone(telecom.getValue());
}
}

switch (fhirPatient.getGender()) {
case MALE:
openELISPatient.setGender("M");
break;
case FEMALE:
openELISPatient.setGender("F");
break;
default:
openELISPatient.setGender(null);
break;
}

if (fhirPatient.getBirthDate() != null) {
openELISPatient.setBirthDate(new Timestamp(fhirPatient.getBirthDate().getTime()));
openELISPatient.setBirthDateForDisplay(
DateUtil.convertTimestampToStringDate(new Timestamp(fhirPatient.getBirthDate().getTime())));
}

if (!fhirPatient.getAddress().isEmpty()) {
Address fhirAddress = fhirPatient.getAddressFirstRep();
Person person = openELISPatient.getPerson();
if (person == null) {
person = new Person();
openELISPatient.setPerson(person);
}
person.setStreetAddress(fhirAddress.getLine().isEmpty() ? null : fhirAddress.getLine().get(0).toString());
person.setCity(fhirAddress.getCity());
person.setState(fhirAddress.getState());
person.setCountry(fhirAddress.getCountry());
}

return openELISPatient;
}

private List<PatientSearchResults> searchPatientInClientRegistry(String nationalID) {
if (isClientRegistryConfigInvalid()) {
return new ArrayList<>();
Expand Down Expand Up @@ -278,7 +210,7 @@ private List<PatientSearchResults> searchPatientInClientRegistry(String national
List<PatientSearchResults> results = new ArrayList<>();

for (org.hl7.fhir.r4.model.Patient externalPatient : externalPatients) {
Patient openElisPatient = transformFhirPatientObjectToOpenElisPatientObject(patient, externalPatient);
Patient openElisPatient = SpringContext.getBean(FhirTransformService.class).transformToOpenElisPatient(patient, externalPatient);
PatientSearchResults searchResult = getSearchResultsForPatient(openElisPatient, null);
searchResult.setDataSourceName(MessageUtil.getMessage("patient.cr.source"));
results.add(searchResult);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.openelisglobal.note.valueholder.Note;
import org.openelisglobal.organization.valueholder.Organization;
import org.openelisglobal.patient.action.bean.PatientManagementInfo;
import org.openelisglobal.patient.valueholder.Patient;
import org.openelisglobal.provider.valueholder.Provider;
import org.openelisglobal.referral.action.beanitems.ReferralItem;
import org.openelisglobal.result.action.util.ResultsUpdateDataSet;
Expand Down Expand Up @@ -70,4 +71,6 @@ void transformPersistResultValidationFhirObjects(List<Result> deletableList, Lis
Practitioner transformProviderToPractitioner(Provider provider);

Provider transformToProvider(Practitioner practitioner);

Patient transformToOpenElisPatient(Patient patient, org.hl7.fhir.r4.model.Patient externalPatient);
}
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,72 @@ private org.hl7.fhir.r4.model.Patient transformToFhirPatient(Patient patient) {
return fhirPatient;
}

@Override
public Patient transformToOpenElisPatient(Patient openELISPatient, org.hl7.fhir.r4.model.Patient fhirPatient) {
for (Identifier identifier : fhirPatient.getIdentifier()) {
String system = identifier.getSystem();
String value = identifier.getValue();
if ("http://openelis-global.org/pat_nationalId".equals(system)) {
openELISPatient.setNationalId(value);
} else if ("http://openelis-global.org/pat_guid".equals(system)) {
openELISPatient.setExternalId(value);
} else if ("http://openelis-global.org/pat_uuid".equals(system)) {
openELISPatient.setFhirUuid(UUID.fromString(value));
}
}

if (!fhirPatient.getName().isEmpty()) {
HumanName name = fhirPatient.getNameFirstRep();
openELISPatient.setEpiFirstName(name.getGivenAsSingleString());
openELISPatient.setEpiLastName(name.getFamily());
}

if (!fhirPatient.getTelecom().isEmpty()) {
ContactPoint telecom = fhirPatient.getTelecomFirstRep();
if (ContactPoint.ContactPointSystem.PHONE.equals(telecom.getSystem())) {
Person person = openELISPatient.getPerson();
if (person == null) {
person = new Person();
openELISPatient.setPerson(person);
}
person.setPrimaryPhone(telecom.getValue());
}
}

switch (fhirPatient.getGender()) {
case MALE:
openELISPatient.setGender("M");
break;
case FEMALE:
openELISPatient.setGender("F");
break;
default:
openELISPatient.setGender(null);
break;
}

if (fhirPatient.getBirthDate() != null) {
openELISPatient.setBirthDate(new Timestamp(fhirPatient.getBirthDate().getTime()));
openELISPatient.setBirthDateForDisplay(
DateUtil.convertTimestampToStringDate(new Timestamp(fhirPatient.getBirthDate().getTime())));
}

if (!fhirPatient.getAddress().isEmpty()) {
Address fhirAddress = fhirPatient.getAddressFirstRep();
Person person = openELISPatient.getPerson();
if (person == null) {
person = new Person();
openELISPatient.setPerson(person);
}
person.setStreetAddress(fhirAddress.getLine().isEmpty() ? null : fhirAddress.getLine().get(0).toString());
person.setCity(fhirAddress.getCity());
person.setState(fhirAddress.getState());
person.setCountry(fhirAddress.getCountry());
}

return openELISPatient;
}

private Address transformToAddress(Person person) {
@SuppressWarnings("unused")
PersonAddress village = null;
Expand Down

0 comments on commit e04b7b4

Please sign in to comment.