Repository: synthetichealth/synthea
Issue: Latitude and Longitude are reversed

The latitude and longitude of patient coordinates appear to be reversed. It's consistent though as patients are correctly assigned to the geographically closest provider, not some random corner of the state.


From a sample FHIR record for a patient in MA:

```
        "address": [
          {
            "extension": [
              {
                "url": "http://hl7.org/fhir/StructureDefinition/geolocation",
                "extension": [
                  {
                    "url": "latitude",
                    "valueDecimal": -71.026717
                  },
                  {
                    "url": "longitude",
                    "valueDecimal": 42.021617
                  }
                ]
              }
            ],
```


Changed files:
src/main/java/org/mitre/synthea/world/agents/Provider.java
src/main/java/org/mitre/synthea/world/geography/Place.java
src/main/java/org/mitre/synthea/export/FhirStu3.java
src/main/java/org/mitre/synthea/export/FhirDstu2.java

diff --git a/src/main/java/org/mitre/synthea/export/FhirDstu2.java b/src/main/java/org/mitre/synthea/export/FhirDstu2.java
index 036e09c05..37adfd8c1 100644
--- a/src/main/java/org/mitre/synthea/export/FhirDstu2.java
+++ b/src/main/java/org/mitre/synthea/export/FhirDstu2.java
@@ -388,7 +388,7 @@ public class FhirDstu2 {
       addrResource.setCountry(COUNTRY_CODE);
     }
 
-    DirectPosition2D coord = (DirectPosition2D) person.attributes.get(Person.COORDINATE);
+    DirectPosition2D coord = person.getLatLon();
     if (coord != null) {
       ExtensionDt geolocationExtension = new ExtensionDt();
       geolocationExtension.setUrl("http://hl7.org/fhir/StructureDefinition/geolocation");
diff --git a/src/main/java/org/mitre/synthea/export/FhirStu3.java b/src/main/java/org/mitre/synthea/export/FhirStu3.java
index a9f844660..c49d64571 100644
--- a/src/main/java/org/mitre/synthea/export/FhirStu3.java
+++ b/src/main/java/org/mitre/synthea/export/FhirStu3.java
@@ -483,7 +483,7 @@ public class FhirStu3 {
           mapCodeToCodeableConcept(maritalStatusCode, "http://hl7.org/fhir/v3/MaritalStatus"));
     }
 
-    DirectPosition2D coord = (DirectPosition2D) person.attributes.get(Person.COORDINATE);
+    DirectPosition2D coord = person.getLatLon();
     if (coord != null) {
       Extension geolocation = addrResource.addExtension();
       geolocation.setUrl("http://hl7.org/fhir/StructureDefinition/geolocation");
diff --git a/src/main/java/org/mitre/synthea/world/agents/Provider.java b/src/main/java/org/mitre/synthea/world/agents/Provider.java
index db27a6194..293c6bbec 100644
--- a/src/main/java/org/mitre/synthea/world/agents/Provider.java
+++ b/src/main/java/org/mitre/synthea/world/agents/Provider.java
@@ -272,7 +272,7 @@ public class Provider implements QuadTreeData {
     }
     double lat = Double.parseDouble(line.remove("LAT"));
     double lon = Double.parseDouble(line.remove("LON"));
-    d.coordinates = new DirectPosition2D(lat, lon);
+    d.coordinates = new DirectPosition2D(lon, lat);
     return d;
   }
 
diff --git a/src/main/java/org/mitre/synthea/world/geography/Place.java b/src/main/java/org/mitre/synthea/world/geography/Place.java
index c6afdff1f..e270212bd 100644
--- a/src/main/java/org/mitre/synthea/world/geography/Place.java
+++ b/src/main/java/org/mitre/synthea/world/geography/Place.java
@@ -31,7 +31,7 @@ public class Place implements QuadTreeData {
     this.postalCode = row.get("ZCTA5");
     double lat = Double.parseDouble(row.get("LAT"));
     double lon = Double.parseDouble(row.get("LON"));
-    this.coordinate = new DirectPosition2D(lat, lon);
+    this.coordinate = new DirectPosition2D(lon, lat);
   }
   
   /**