Skip to content

Commit

Permalink
Csv export prototype complete
Browse files Browse the repository at this point in the history
  • Loading branch information
cerbeor committed Dec 12, 2023
1 parent e6f0eb5 commit 174ee47
Show file tree
Hide file tree
Showing 14 changed files with 323 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;
Expand All @@ -27,6 +29,9 @@

import javax.servlet.http.HttpServletRequest;

import java.net.InetAddress;
import java.net.UnknownHostException;

import static org.immregistries.iis.kernal.fhir.interceptors.SessionAuthorizationInterceptor.CONNECTATHON_USER;
import static org.immregistries.iis.kernal.fhir.security.ServletHelper.GITHUB_PREFIX;
import static org.immregistries.iis.kernal.fhir.security.ServletHelper.SESSION_TENANT;
Expand All @@ -41,7 +46,9 @@ public class RepositoryClientFactory extends ApacheRestfulClientFactory implemen
private IFhirSystemDao fhirSystemDao;
private final Logger logger = LoggerFactory.getLogger(RepositoryClientFactory.class);
private LoggingInterceptor loggingInterceptor;
private static String serverBase = "";

@Autowired
Environment environment;

@Autowired
public RepositoryClientFactory(){
Expand All @@ -55,14 +62,12 @@ private void asynchInit() {
loggingInterceptor = new LoggingInterceptor();
loggingInterceptor.setLogger(logger);
}
if (serverBase.equals("")) {
serverBase = ServletUriComponentsBuilder.fromCurrentContextPath().build().toUriString() + "/fhir";
}
}

public IGenericClient newGenericClient(Tenant tenant) {
asynchInit();
IGenericClient client = newGenericClient(serverBase + "/" + tenant.getOrganizationName());
IGenericClient client;
client = newGenericClient( "http://" + InetAddress.getLoopbackAddress().getHostAddress() + ":" + environment.getProperty("server.port") + "/iis/fhir/" + tenant.getOrganizationName());
IClientInterceptor authInterceptor;
if (tenant.getOrganizationName().equals(CONNECTATHON_USER) && tenant.getUserAccess().getAccessName() == null) {
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package org.immregistries.iis.kernal.mapping;


import ca.uhn.fhir.util.CanonicalIdentifier;
import org.apache.commons.lang3.StringUtils;
import org.hl7.fhir.instance.model.api.IBaseParameters;
import org.hl7.fhir.r5.model.*;

import java.text.SimpleDateFormat;
Expand All @@ -23,25 +21,31 @@ public class MappingHelper {
public static final SimpleDateFormat sdf = new SimpleDateFormat("E MMM dd HH:mm:ss yyyy");

//TODO choose system id or not
public static Reference getFhirReference(String fhirType, String dbType, String identifier) {
public static Reference getFhirReferenceR5(String fhirType, String dbType, String identifier) {
if (StringUtils.isBlank(identifier)) {
return null;
} else {
return new Reference()
.setType(fhirType)
.setIdentifier(getFhirIdentifier(dbType, identifier));
.setIdentifier(getFhirIdentifierR5(dbType, identifier));
}
}

public static CodeableReference getFhirCodeableReference(String fhirType, String dbType, String identifier) {
public static Reference getFhirReferenceR5(String fhirType, String dbType, String identifier, String fhirId) {
return new Reference(fhirType + "/" + fhirId)
.setType(fhirType)
.setIdentifier(getFhirIdentifierR5(dbType, identifier));
}

public static CodeableReference getFhirCodeableReferenceR5(String fhirType, String dbType, String identifier) {
if (StringUtils.isBlank(identifier)) {
return null;
} else {
return new CodeableReference(getFhirReference(fhirType, dbType, identifier));
return new CodeableReference(getFhirReferenceR5(fhirType, dbType, identifier));
}
}

public static org.hl7.fhir.r4.model.Reference getFhirR4Reference(String fhirType, String dbType, String identifier) {
public static org.hl7.fhir.r4.model.Reference getFhirReferenceR4(String fhirType, String dbType, String identifier) {
if (StringUtils.isBlank(identifier)) {
return null;
} else {
Expand All @@ -52,25 +56,20 @@ public static org.hl7.fhir.r4.model.Reference getFhirR4Reference(String fhirType
.setValue(identifier));
}
}
public static Reference getFhirReference(String fhirType, String dbType, String identifier, String fhirId) {
return new Reference(fhirType + "/" + fhirId)
.setType(fhirType)
.setIdentifier(getFhirIdentifier(dbType,identifier));
}

public static Identifier getFhirIdentifier(String dbType, String identifier) {
public static Identifier getFhirIdentifierR5(String dbType, String identifier) {
return new Identifier()
.setSystem(dbType)
.setValue(identifier);
.setSystem(dbType)
.setValue(identifier);
}

public static org.hl7.fhir.r4.model.Identifier getFhirR4Identifier(String dbType, String identifier) {
public static org.hl7.fhir.r4.model.Identifier getFhirIdentifierR4(String dbType, String identifier) {
return new org.hl7.fhir.r4.model.Identifier()
.setSystem(dbType)
.setValue(identifier);
.setSystem(dbType)
.setValue(identifier);
}

public static String identifierToString(List<Identifier> identifiers) {
public static String identifierToString(List<Identifier> identifiers) {
if (identifiers.size() > 0) {
return identifiers.get(0).getSystem() + "|" + identifiers.get(0).getValue();
} else {
Expand All @@ -82,19 +81,27 @@ public static String identifierToString(List<Identifier> identifiers) {
// return identifiers.stream().filter(identifier -> identifier.getSystemElement().getValue() != null && identifier.getSystemElement().getValue().equals(system)).findFirst().orElse(identifiers.get(0));
// }

public static Identifier filterIdentifier(List<Identifier> identifiers, String system) {
public static Identifier filterIdentifierR5(List<Identifier> identifiers, String system) {
return identifiers.stream().filter(identifier -> identifier.getSystem() != null && identifier.getSystem().equals(system)).findFirst().orElse(null);
}

public static org.hl7.fhir.r4.model.Identifier filterR4Identifier(List<org.hl7.fhir.r4.model.Identifier> identifiers, String system) {
public static org.hl7.fhir.r4.model.Identifier filterIdentifierR4(List<org.hl7.fhir.r4.model.Identifier> identifiers, String system) {
return identifiers.stream().filter(identifier -> identifier.getSystem() != null && identifier.getSystem().equals(system)).findFirst().orElse(null);
}

public static Coding filterCodeableConcept(CodeableConcept concept, String system) {
return filterCodingList(concept.getCoding(), system);
public static Identifier filterIdentifierTypeR5(List<Identifier> identifiers, String type) {
return identifiers.stream().filter(identifier -> identifier.hasType() && identifier.getType().hasCoding() && identifier.getType().getCodingFirstRep().getCode().equals(type)).findFirst().orElse(null);
}

public static org.hl7.fhir.r4.model.Identifier filterIdentifierTypeR4(List<org.hl7.fhir.r4.model.Identifier> identifiers, String type) {
return identifiers.stream().filter(identifier -> identifier.hasType() && identifier.getType().hasCoding() && identifier.getType().getCodingFirstRep().getCode().equals(type)).findFirst().orElse(null);
}

public static Coding filterCodeableConceptR5(CodeableConcept concept, String system) {
return filterCodingListR5(concept.getCoding(), system);
}

public static Coding filterCodingList(List<Coding> codings, String system) {
public static Coding filterCodingListR5(List<Coding> codings, String system) {
return codings.stream().filter(coding -> coding.getSystem().equals(system)).findFirst().get();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public org.hl7.fhir.r4.model.Location getFhirResource(OrgLocation ol) {
if (ol != null) {
org.hl7.fhir.r4.model.Location location = new org.hl7.fhir.r4.model.Location();
location.setId(ol.getOrgLocationId());
location.addIdentifier(MappingHelper.getFhirR4Identifier("", ol.getOrgFacilityCode()));
location.addIdentifier(MappingHelper.getFhirIdentifierR4("", ol.getOrgFacilityCode()));
location.setName(ol.getOrgFacilityName());
if (!ol.getVfcProviderPin().isBlank()) {
location.addExtension().setUrl(VFC_PROVIDER_PIN).setValue(new StringType(ol.getVfcProviderPin()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public Observation getFhirResource(ObservationReported observationReported) {
.setCode(observationReported.getMethodCode())
.setSystem(observationReported.getMethodTable())
.setDisplay(observationReported.getMethodLabel());
o.addIdentifier(MappingHelper.getFhirR4Identifier(
o.addIdentifier(MappingHelper.getFhirIdentifierR4(
observationReported.getIdentifierTable(),observationReported.getIdentifierCode())); //TODO label
o.addComponent().setValue(new org.hl7.fhir.r4.model.DateTimeType(observationReported.getObservationDate()))
.setCode(new org.hl7.fhir.r4.model.CodeableConcept().setText(OBSERVATION_DATE));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ public class OrganizationMapperR4 implements OrganizationMapper<Organization> {

public Organization getFhirResource(Tenant tenant) {
Organization o = new Organization();
o.addIdentifier(MappingHelper.getFhirR4Identifier("Tenant", Integer.toString(tenant.getOrgId())));
o.addIdentifier(MappingHelper.getFhirIdentifierR4("Tenant", Integer.toString(tenant.getOrgId())));
o.setName(tenant.getOrganizationName());
return o;
}

public Tenant getTenant(Organization organization) {
Tenant tenant = new Tenant();
tenant.setOrganizationName(organization.getName());
tenant.setOrgId(Integer.parseInt(MappingHelper.filterR4Identifier(organization.getIdentifier(),"Tenant").getValue()));
tenant.setOrgId(Integer.parseInt(MappingHelper.filterIdentifierR4(organization.getIdentifier(),"Tenant").getValue()));
return tenant;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public Person getFhirResource(ModelPerson modelPerson) {
if ( modelPerson.getProfessionalSuffix() != null) {
name.addSuffix(modelPerson.getProfessionalSuffix());
}
p.setManagingOrganization(MappingHelper.getFhirR4Reference(MappingHelper.ORGANIZATION,ORGANIZATION_ASSIGNING_AUTHORITY, modelPerson.getAssigningAuthority()));
p.setManagingOrganization(MappingHelper.getFhirReferenceR4(MappingHelper.ORGANIZATION,ORGANIZATION_ASSIGNING_AUTHORITY, modelPerson.getAssigningAuthority()));
return p;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public VaccinationMaster getMaster(Immunization i){
*/
public Immunization getFhirResource(VaccinationMaster vr) {
Immunization i = new Immunization();
i.addIdentifier(MappingHelper.getFhirIdentifier(vr.getExternalLinkSystem(), vr.getExternalLink())); // TODO if system empty ?
i.addIdentifier(MappingHelper.getFhirIdentifierR5(vr.getExternalLinkSystem(), vr.getExternalLink())); // TODO if system empty ?
Reference patientReference = new Reference()
.setReference("Patient/" + vr.getPatientReported().getPatientId())
// .setIdentifier(new Identifier()
Expand All @@ -186,7 +186,7 @@ public Immunization getFhirResource(VaccinationMaster vr) {
if (StringUtils.isNotBlank(vr.getVaccineNdcCode())) {
i.getVaccineCode().addCoding().setCode(vr.getVaccineNdcCode()).setSystem(NDC);
}
i.setManufacturer(MappingHelper.getFhirCodeableReference(MappingHelper.ORGANIZATION, MVX, vr.getVaccineMvxCode()));
i.setManufacturer(MappingHelper.getFhirCodeableReferenceR5(MappingHelper.ORGANIZATION, MVX, vr.getVaccineMvxCode()));

i.setDoseQuantity(new Quantity().setValue(new BigDecimal(vr.getAdministeredAmount())));

Expand Down Expand Up @@ -255,7 +255,7 @@ private Immunization.ImmunizationPerformerComponent performer(ModelPerson person
break;
}
default:{
actor = MappingHelper.getFhirReference(MappingHelper.PRACTITIONER, person.getIdentifierTypeCode(), person.getPersonExternalLink(), person.getPersonId());
actor = MappingHelper.getFhirReferenceR5(MappingHelper.PRACTITIONER, person.getIdentifierTypeCode(), person.getPersonExternalLink(), person.getPersonId());
}
}
performer.setActor(actor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public Observation getFhirResource(ObservationReported observationReported) {
.setCode(observationReported.getMethodCode())
.setSystem(observationReported.getMethodTable())
.setDisplay(observationReported.getMethodLabel());
o.addIdentifier(MappingHelper.getFhirIdentifier(
o.addIdentifier(MappingHelper.getFhirIdentifierR5(
observationReported.getIdentifierTable(),observationReported.getIdentifierCode())); //TODO label
o.addComponent().setValue(new DateTimeType(observationReported.getObservationDate()))
.setCode(new CodeableConcept().setText(OBSERVATION_DATE));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ public class OrganizationMapperR5 implements OrganizationMapper<Organization> {

public Organization getFhirResource(Tenant tenant) {
Organization o = new Organization();
o.addIdentifier(MappingHelper.getFhirIdentifier("Tenant", Integer.toString(tenant.getOrgId())));
o.addIdentifier(MappingHelper.getFhirIdentifierR5("Tenant", Integer.toString(tenant.getOrgId())));
o.setName(tenant.getOrganizationName());
return o;
}

public Tenant getTenant(Organization organization) {
Tenant tenant = new Tenant();
tenant.setOrganizationName(organization.getName());
tenant.setOrgId(Integer.parseInt(MappingHelper.filterIdentifier(organization.getIdentifier(),"Tenant").getValue()));
tenant.setOrgId(Integer.parseInt(MappingHelper.filterIdentifierR5(organization.getIdentifier(),"Tenant").getValue()));
return tenant;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ public ModelPerson getModelPerson(org.hl7.fhir.r5.model.Person p) {
public Person getFhirResource(ModelPerson modelPerson) {
org.hl7.fhir.r5.model.Person p = new org.hl7.fhir.r5.model.Person();
p.setId(modelPerson.getPersonId());
p.addIdentifier(MappingHelper.getFhirIdentifier(MappingHelper.PERSON, modelPerson.getPersonExternalLink()));
p.addIdentifier(MappingHelper.getFhirIdentifierR5(MappingHelper.PERSON, modelPerson.getPersonExternalLink()));
HumanName name = p.addName();
name.setFamily(modelPerson.getNameLast());
name.addGiven(modelPerson.getNameFirst());
name.addGiven(modelPerson.getNameMiddle());
if ( modelPerson.getProfessionalSuffix() != null) {
name.addSuffix(modelPerson.getProfessionalSuffix());
}
p.setManagingOrganization(MappingHelper.getFhirReference(MappingHelper.ORGANIZATION, ORGANIZATION_ASSIGNING_AUTHORITY, modelPerson.getAssigningAuthority()));
p.setManagingOrganization(MappingHelper.getFhirReferenceR5(MappingHelper.ORGANIZATION, ORGANIZATION_ASSIGNING_AUTHORITY, modelPerson.getAssigningAuthority()));
return p;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,19 @@ public Practitioner getFhirResource(ModelPerson modelPerson) {
try {
switch (new Reference(modelPerson.getIdentifierTypeCode()).getType()) {
case "Organization": {
practitioner.addIdentifier(MappingHelper.getFhirIdentifier(PRACTITIONER,modelPerson.getPersonExternalLink()).setAssigner(new Reference(modelPerson.getAssigningAuthority())));
practitioner.addIdentifier(MappingHelper.getFhirIdentifierR5(PRACTITIONER,modelPerson.getPersonExternalLink()).setAssigner(new Reference(modelPerson.getAssigningAuthority())));
break;
}
case "System" : {
practitioner.addIdentifier(MappingHelper.getFhirIdentifier(modelPerson.getIdentifierTypeCode(),modelPerson.getPersonExternalLink()));
practitioner.addIdentifier(MappingHelper.getFhirIdentifierR5(modelPerson.getIdentifierTypeCode(),modelPerson.getPersonExternalLink()));
break;
} default: {
practitioner.addIdentifier(MappingHelper.getFhirIdentifier(PRACTITIONER,modelPerson.getPersonExternalLink()));
practitioner.addIdentifier(MappingHelper.getFhirIdentifierR5(PRACTITIONER,modelPerson.getPersonExternalLink()));
break;
}
}
} catch (NullPointerException e) { // If typecode is not reference
practitioner.addIdentifier(MappingHelper.getFhirIdentifier(modelPerson.getIdentifierTypeCode(),modelPerson.getPersonExternalLink()));
practitioner.addIdentifier(MappingHelper.getFhirIdentifierR5(modelPerson.getIdentifierTypeCode(),modelPerson.getPersonExternalLink()));
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.immregistries.iis.kernal.servlet;

import org.apache.commons.codec.binary.Base64;
import org.hibernate.Session;
import org.immregistries.iis.kernal.fhir.security.ServletHelper;
import org.immregistries.iis.kernal.model.Tenant;
import org.springframework.security.authentication.AnonymousAuthenticationToken;
import org.springframework.security.core.Authentication;
Expand Down
Loading

0 comments on commit 174ee47

Please sign in to comment.