Skip to content

Commit

Permalink
chore: Refactor LabCreationListener to add MFL Code as location ident…
Browse files Browse the repository at this point in the history
…ifier
  • Loading branch information
moshonk committed Jun 7, 2024
1 parent 8c3c90d commit cd5efbc
Showing 1 changed file with 19 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,23 +125,27 @@ public Bundle createLabBundle(Task task) {

Bundle.BundleEntryComponent component = transactionBundle.addEntry();
if (resource instanceof Location || resource instanceof Organization) {
Location location = (Location) resource;
if (location != null) {
org.openmrs.Location openmrsLocation = locationService.getLocationByUuid(location.getId());
if (openmrsLocation != null) {
LocationAttributeType mflLocationAttributeType = locationService.getLocationAttributeTypeByUuid(MFL_LOCATION_ATTRIBUTE_TYPE_UUID);
Collection<LocationAttribute> locationAttributeTypes = openmrsLocation.getActiveAttributes();
if (!locationAttributeTypes.isEmpty()) {
locationAttributeTypes.stream().filter(locationAttribute -> locationAttribute.getAttributeType().equals(mflLocationAttributeType)).findFirst().ifPresent(locationAttribute -> {
String mflCode = (String) locationAttribute.getValue();

Identifier mflIdentifier = new Identifier();
mflIdentifier.setSystem(MFL_LOCATION_IDENTIFIER_URI);
mflIdentifier.setValue(mflCode);
org.openmrs.Location openmrsLocation = locationService.getLocationByUuid(location.getId());
if (openmrsLocation != null) {
LocationAttributeType mflLocationAttributeType = locationService.getLocationAttributeTypeByUuid(MFL_LOCATION_ATTRIBUTE_TYPE_UUID);
Collection<LocationAttribute> locationAttributeTypes = openmrsLocation.getActiveAttributes();
if (!locationAttributeTypes.isEmpty()) {
locationAttributeTypes.stream().filter(locationAttribute -> locationAttribute.getAttributeType().equals(mflLocationAttributeType)).findFirst().ifPresent(locationAttribute -> {
String mflCode = (String) locationAttribute.getValue();

Identifier mflIdentifier = new Identifier();
mflIdentifier.setSystem(MFL_LOCATION_IDENTIFIER_URI);
mflIdentifier.setValue(mflCode);
if (resource instanceof Organization) {
Organization organization = (Organization) resource;
organization.addIdentifier(mflIdentifier);
component.setResource(organization);
} else if (resource instanceof Location) {
Location location = (Location) resource;
location.addIdentifier(mflIdentifier);
component.setResource(location);
});
}
}
});
}
}
} else {
Expand Down

0 comments on commit cd5efbc

Please sign in to comment.