use of org.hisp.dhis.web.ohie.csd.domain.OtherID in project dhis2-core by dhis2.
the class CsdController method createCsd.
private Csd createCsd(Iterable<OrganisationUnit> organisationUnits) {
Csd csd = new Csd();
csd.getFacilityDirectory().setFacilities(new ArrayList<>());
for (OrganisationUnit organisationUnit : organisationUnits) {
boolean isFacility = false;
for (OrganisationUnitGroup group : organisationUnit.getGroups()) {
if (group.getName().equals(FACILITY_DISCRIMINATOR_GROUP)) {
isFacility = true;
break;
}
}
// skip if orgunit is not a health facility
if (!isFacility) {
continue;
}
Facility facility = new Facility();
facility.setOid("urn:x-dhis:facility." + organisationUnit.getUid());
facility.getOtherID().add(new OtherID(organisationUnit.getUid(), "dhis2-uid"));
if (organisationUnit.getCode() != null) {
facility.getOtherID().add(new OtherID(organisationUnit.getCode(), "dhis2-code"));
}
facility.setPrimaryName(organisationUnit.getDisplayName());
if (organisationUnit.getContactPerson() != null) {
Contact contact = new Contact();
Person person = new Person();
Name name = new Name();
contact.setPerson(person);
person.setName(name);
name.getCommonNames().add(new CommonName(organisationUnit.getContactPerson()));
facility.getContacts().add(contact);
}
String facilityStatus = "Open";
for (OrganisationUnitGroup organisationUnitGroup : organisationUnit.getGroups()) {
if (organisationUnitGroup == null) {
continue;
}
Set<String> groupSetNames = organisationUnitGroup.getGroupSets().stream().map(OrganisationUnitGroupSet::getName).collect(Collectors.toSet());
if (groupSetNames.contains(FACILITY_STATUS_GROUPSET)) {
facilityStatus = organisationUnitGroup.getCode();
continue;
}
if (groupSetNames.contains(FACILITY_TYPE_GROUPSET)) {
if (organisationUnitGroup.getCode() == null) {
continue;
}
CodedType codedType = new CodedType();
codedType.setCode(organisationUnitGroup.getCode());
codedType.setCodingSchema("Unknown");
for (AttributeValue attributeValue : organisationUnitGroup.getAttributeValues()) {
if (attributeValue.getAttribute().getName().equals("code_system")) {
codedType.setCodingSchema(attributeValue.getValue());
break;
}
}
codedType.setValue(organisationUnitGroup.getDisplayName());
facility.getCodedTypes().add(codedType);
}
if (groupSetNames.contains(FACILITY_OWNERSHIP_GROUPSET)) {
Organization organization = new Organization("urn:x-dhis:ownership." + organisationUnitGroup.getUid());
facility.getOrganizations().add(organization);
for (DataSet dataSet : organisationUnit.getDataSets()) {
for (AttributeValue attributeValue : dataSet.getAttributeValues()) {
if (attributeValue.getAttribute().getName().equals(DATASET_SERVICE_ATTRIBUTE)) {
Service service = new Service();
service.setOid("urn:x-dhis:dataSet." + dataSet.getUid());
service.getNames().add(new Name(new CommonName(attributeValue.getValue())));
organization.getServices().add(service);
break;
}
}
}
}
}
if (organisationUnit.getFeatureType() == FeatureType.POINT) {
Geocode geocode = new Geocode();
try {
GeoUtils.Coordinates coordinates = GeoUtils.parseCoordinates(organisationUnit.getCoordinates());
geocode.setLongitude(coordinates.lng);
geocode.setLatitude(coordinates.lat);
facility.setGeocode(geocode);
} catch (NumberFormatException ignored) {
}
}
Record record = new Record();
record.setCreated(organisationUnit.getCreated());
record.setUpdated(organisationUnit.getLastUpdated());
record.setStatus(facilityStatus);
facility.setRecord(record);
Map<String, List<AddressLine>> addressLines = Maps.newHashMap();
List<AttributeValue> attributeValues = new ArrayList<>(organisationUnit.getAttributeValues());
Collections.sort(attributeValues, AttributeValueSortOrderComparator.INSTANCE);
for (AttributeValue attributeValue : attributeValues) {
if (attributeValue.getAttribute().getName().startsWith("Address_")) {
String[] attributeSplit = attributeValue.getAttribute().getName().split("_");
if (attributeSplit.length > 3) {
continue;
}
if (addressLines.get(attributeSplit[1]) == null) {
addressLines.put(attributeSplit[1], Lists.<AddressLine>newArrayList());
}
AddressLine addressLine = new AddressLine();
addressLine.setComponent(attributeSplit[2]);
addressLine.setValue(attributeValue.getValue());
addressLines.get(attributeSplit[1]).add(addressLine);
}
}
for (String key : addressLines.keySet()) {
Address address = new Address(key);
address.setAddressLines(addressLines.get(key));
facility.getAddresses().add(address);
}
csd.getFacilityDirectory().getFacilities().add(facility);
}
return csd;
}
Aggregations