Skip to content

Commit

Permalink
49 add fhir resource bundle to cda doc (#60)
Browse files Browse the repository at this point in the history
* Added debugging messages

* Restored ability to attach documents to SOAP requests

* Fixed HL7 parsing error resulting from additional time parameter on the birthdate

* Added provision to filter getMessages request by facility sitecode

* Code formatting changes

* Removed unused unit test

* Replaced invalid characters in the Config file

* COde formatting changes

* Added method override to attach more than 1 additional documents

* Added method override to attach more than 1 additional documents

* Added method override to attach more than 1 additional documents

* Added code stubs for the fhir document builder

* Added jnuit & upgraded maven jaxb version

* Added unit tests

* Code clean-up

* Fixing a failing unit test

* Fixed failing unit tests

* Added a System Identifier to the Patient Resource

* Updated hoe the System Identifier type is handled to support OpenCR MPI integration

* Finalizing 2.1.0

* Finalizing 2.1.1

* Added code stubs for the fhir document builder

* Added a System Identifier to the Patient Resource

* updated local pid global property name

* Assign placeholder System Identifier

* Added code stubs for the fhir document builder

* Added unit tests and provided lnsp-workflow fixes

* Updated unit tests and fixed dependency issues

* Changes to allow attaching FHIR resource to the Xds document

* Fixed the bug preventing processing of Pull Point notification documents

* Added base64 decoding for pull point documents.

* Resolve possisble duplication of ECID identifier types on the XDS document

* Fixed general Lab-lnsp workflow issues and updated

* Fixed merge conflicts

* Updated gitignore file

* Removed test files

* Removed test files and updated gitignore

* Delete settings.json

* Delete id_file

* Updated gitignore
  • Loading branch information
moshonk authored Sep 29, 2021
1 parent d4ca047 commit 26583ee
Show file tree
Hide file tree
Showing 16 changed files with 379 additions and 120 deletions.
10 changes: 9 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,12 @@ target
.DS_Store

# Log Files
*.log
*.log

# test files
api/null/*
null/*

#vs Code
.vscode/*
api/id_file
5 changes: 1 addition & 4 deletions api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<dependency>
<groupId>org.openmrs.module</groupId>
<artifactId>fhir2-api</artifactId>
<version>${fhirModuleVersion}</version>
</dependency>
<dependency>
<groupId>org.openmrs.module</groupId>
Expand Down Expand Up @@ -67,10 +68,6 @@
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
</dependency>
<dependency>
<groupId>javax.xml.ws</groupId>
<artifactId>jaxws-api</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.ws</groupId>
<artifactId>spring-ws-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,17 @@ public final class XdsSenderConstants {
public static final String SCT_TEMPLATE_HISTORY_OF_BLOOD_TRANSFUSIONS = "1.3.6.1.4.1.19376.1.5.3.1.1.9.12";

public static final String LOCATION_SITECODE_ATTRIBUTE_UUID = "6242bf19-207e-4076-9d28-9290525b8ed9";


public static final String SYSTEM_IDENTIFIER_TYPE_NAME = "SYSTEM";

public static final String PROP_PID_LOCAL = "fhir2.uriPrefix";

public static final String IDENTIFIER_SYSTEM = "http://openclientregistry.org/fhir/sourceid";

public static final String SYSTEM_IDENTIFIER_TYPE_UUID = "99F5A4C3-CEEA-4F5F-ABE6-399CD4C9FE24";

public static final String ECID_IDENTIFIER_TYPE_NAME = "ECID";

private XdsSenderConstants() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
import org.openmrs.api.context.Context;
import org.openmrs.module.xdssender.XdsSenderConfig;
import org.openmrs.module.xdssender.XdsSenderConstants;
import org.openmrs.module.xdssender.api.xds.XdsUtil;
import org.openmrs.util.OpenmrsConstants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
Expand All @@ -88,7 +89,7 @@
*/
@Component("xdssender.CdaDataUtil")
public class CdaDataUtil {

// NOK codes
private static final List<String> nextOfKinRelations = Arrays.asList("MTH", "FTH", "GRMTH", "GRFTH", "SIB", "CHILD",
"AUNT", "UNCLE", "PGRMTH", "MGRMTH", "PGRFTH", "MGRFTH", "SON", "DAU", "BRO", "SIS", "DOMPART", "FAMMEMB");
Expand Down Expand Up @@ -464,22 +465,44 @@ public RecordTarget createRecordTarget(Patient patient) {
// Identifiers
patientRole.setId(new SET<II>());
for (PatientIdentifier pid : patient.getActiveIdentifiers()) {
II ii = new II(pid.getIdentifierType().getName(), pid.getIdentifier());
if (!patientRole.getId().contains(ii))
patientRole.getId().add(ii);
// To cater for old records assigned ECID by OpenEMPI, we will Skip adding the ECID identifier type
// if it already exists
if (!pid.getIdentifierType().getName().equals(XdsSenderConstants.ECID_IDENTIFIER_TYPE_NAME) ) {
II ii = new II(pid.getIdentifierType().getName(), pid.getIdentifier());
if (!patientRole.getId().contains(ii))
patientRole.getId().add(ii);
}
}


// Add system identifier
II ii = null;
II iii = null;
try {
ii = new II(XdsSenderConstants.SYSTEM_IDENTIFIER_TYPE_NAME, XdsUtil.getPlaceholderSystemIdentifier(patient).getIdentifier());
patientRole.getId().add(ii);
// Adding an ECID to allow for processing by xds-b-repository in the SHR
iii = new II(XdsSenderConstants.ECID_IDENTIFIER_TYPE_NAME, XdsUtil.getPlaceholderSystemIdentifier(patient).getIdentifier());
patientRole.getId().add(iii);
}
catch (Exception e) {
e.printStackTrace();
}

// Address?
patientRole.setAddr(createAddressSet(patient));

// Telecom?
patientRole.setTelecom(createTelecomSet(patient));

// Marital status?
PersonAttribute civilStatusCode = patient.getAttribute(XdsSenderConstants.ATTRIBUTE_NAME_CIVIL_STATUS);
if (civilStatusCode != null)
hl7Patient.setMaritalStatusCode(metadataUtil.getStandardizedCode((Concept) civilStatusCode.getHydratedObject(),
XdsSenderConstants.CODE_SYSTEM_MARITAL_STATUS, CE.class));
try {
PersonAttribute civilStatusCode = patient.getAttribute(XdsSenderConstants.ATTRIBUTE_NAME_CIVIL_STATUS);
if (civilStatusCode != null)
hl7Patient.setMaritalStatusCode(metadataUtil.getStandardizedCode((Concept) civilStatusCode.getHydratedObject(),
XdsSenderConstants.CODE_SYSTEM_MARITAL_STATUS, CE.class));
} catch (Exception e) {
e.printStackTrace();
}

// Names
hl7Patient.setName(createNameSet(patient));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,14 @@ public DocumentModel buildDocument(Patient patient, Encounter encounter) throws
//relevantObs = Context.getObsService().getObservationsByPerson(builder.getRecordTarget());

for (Obs obs : relevantObs) {
//we want to have all obs groups at the end of the list
if (obs.hasGroupMembers()) {
medicationObs.add(obs);
} else {
medicationObs.add(0, obs); //this probably is some group member
// Ensure that only obs relating to Tests are eliminated from the list
if (!obs.getConcept().getConceptClass().getName().equals("Test")) {
//we want to have all obs groups at the end of the list
if (obs.hasGroupMembers()) {
medicationObs.add(obs);
} else {
medicationObs.add(0, obs); //this probably is some group member
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,9 @@ private void exportEncounter(String encounterUuid) {
LOGGER.warn("Skipped sending Encounter %s (formId is NULL " + "-> probably it's the creating encounter)");
} else {
Patient patient = Context.getPatientService().getPatient(encounter.getPatient().getPatientId());

ecidUpdater.fetchEcidIfRequired(patient);

// TODO: Replace this with a method that queries OpenCR and fetches/updates the patient data
// ecidUpdater.fetchEcidIfRequired(patient);

XdsExportService service = Context.getService(XdsExportService.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.r4.model.Identifier;
import org.hl7.fhir.r4.model.Resource;
import org.marc.everest.datatypes.NullFlavor;
import org.marc.everest.datatypes.TS;
Expand All @@ -14,10 +15,12 @@
import org.openmrs.api.impl.BaseOpenmrsService;
import org.openmrs.module.fhir2.api.translators.PatientTranslator;
import org.openmrs.module.fhir2.api.translators.impl.PatientTranslatorImpl;
import org.openmrs.module.xdssender.XdsSenderConfig;
import org.openmrs.module.xdssender.XdsSenderConstants;
import org.openmrs.module.xdssender.api.cda.CdaDataUtil;
import org.openmrs.module.xdssender.api.cda.model.DocumentModel;
import org.openmrs.module.xdssender.api.fhir.exceptions.ResourceGenerationException;
import org.openmrs.module.xdssender.api.xds.XdsUtil;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
Expand Down Expand Up @@ -82,13 +85,10 @@ public Resource generateFhirResource(Object openmrsEntity) throws ResourceGenera
if (openmrsEntity instanceof Patient) {
Patient patient = (Patient)openmrsEntity;
resource = patientTranslator.toFhirResource(patient);
localPatientId = Context.getAdministrationService().getGlobalProperty(PROP_PID_LOCAL);
if (localPatientId == null) {
throw new ResourceGenerationException("Unable to retrieve the Local PID, ensure that the MPI client module is installed and the \"PID LOCAL\" global property has been set");
}
org.hl7.fhir.r4.model.Patient patientResource = (org.hl7.fhir.r4.model.Patient) resource;
patientResource.addIdentifier().setSystem(IDENTIFIER_SYSTEM).setValue(localPatientId + patient.getUuid());
resource = patientResource;
org.hl7.fhir.r4.model.Patient patientResource;
patientResource = checkAndSetSystemIdentifier(patient, (org.hl7.fhir.r4.model.Patient) resource);

resource = patientResource;
} else {
log.error(String.format("Entity %s not yet implemented", openmrsEntity.getClass().getName()));
throw new ResourceGenerationException("Entity not implemented");
Expand All @@ -97,7 +97,35 @@ public Resource generateFhirResource(Object openmrsEntity) throws ResourceGenera
return resource;
}

/**
private org.hl7.fhir.r4.model.Patient checkAndSetSystemIdentifier(Patient patient, org.hl7.fhir.r4.model.Patient patientResource)
throws ResourceGenerationException {
Boolean isSystemIdentifierDefined = false;
for (Identifier identifer: patientResource.getIdentifier()) {
if(identifer.getSystem() != null) {
if (identifer.getSystem().equals(XdsSenderConstants.IDENTIFIER_SYSTEM)) {
isSystemIdentifierDefined = true;
break;
}
}
}

if (!isSystemIdentifierDefined) {
PatientIdentifier systemPatientIdentifier = null;
try {
systemPatientIdentifier = XdsUtil.getPlaceholderSystemIdentifier(patient);
}
catch (Exception e) {
throw new ResourceGenerationException("Unable to retrieve the Local PID, ensure that the \"PID LOCAL\" global property has been set");
}

patientResource.addIdentifier().setSystem(XdsSenderConfig.getInstance().getEcidRoot()).setValue(systemPatientIdentifier.getIdentifier());
// qpatientResource.addIdentifier().setSystem(XdsSenderConstants.IDENTIFIER_SYSTEM).setValue(systemPatientIdentifier.getIdentifier());
}

return patientResource;
}

/**
* @should return valid document
*/
@Override
Expand Down
Loading

0 comments on commit 26583ee

Please sign in to comment.