Skip to content

Commit 96d151b

Browse files
authored
Merge pull request #208 from DataIntegrationGroup/transfer
Transfer
2 parents a4764ef + 2cac04a commit 96d151b

26 files changed

Lines changed: 130 additions & 98 deletions

api/thing.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@
3232
editor_dependency,
3333
viewer_dependency,
3434
)
35-
from db.thing import Thing, ThingIdLink, WellScreen
3635
from db.deployment import Deployment
36+
from db.thing import Thing, ThingIdLink, WellScreen
37+
from schemas.deployment import DeploymentResponse
3738
from schemas.thing import (
3839
CreateThingIdLink,
3940
CreateWell,
@@ -49,9 +50,9 @@
4950
UpdateThingIdLink,
5051
UpdateWellScreen,
5152
)
52-
from schemas.deployment import DeploymentResponse
5353
from services.crud_helper import model_patcher, model_adder, model_deleter
5454
from services.exceptions_helper import PydanticStyleException
55+
from services.lexicon_helper import get_terms_by_category
5556
from services.query_helper import (
5657
simple_get_by_id,
5758
paginated_all_getter,
@@ -66,7 +67,6 @@
6667
modify_well_descriptor_tables,
6768
WELL_DESCRIPTOR_MODEL_MAP,
6869
)
69-
from services.lexicon_helper import get_terms_by_category
7070

7171
router = APIRouter(prefix="/thing", tags=["thing"])
7272

core/initializers.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
from sqlalchemy import text
1919
from sqlalchemy.exc import DatabaseError
20+
from sqlalchemy.orm import Session
2021

2122
from db import Base
2223
from db.engine import engine, session_ctx
@@ -81,6 +82,19 @@ def init_parameter(path: str = None) -> None:
8182
session.rollback()
8283

8384

85+
def erase_and_rebuild_db(session: Session):
86+
from sqlalchemy import text
87+
88+
with session.bind.connect() as conn:
89+
conn.execute(text("DROP SCHEMA public CASCADE"))
90+
conn.execute(text("CREATE SCHEMA public"))
91+
conn.execute(text("CREATE EXTENSION IF NOT EXISTS postgis"))
92+
conn.commit()
93+
94+
Base.metadata.drop_all(session.bind)
95+
Base.metadata.create_all(session.bind)
96+
97+
8498
def init_lexicon(path: str = None) -> None:
8599
if path is None:
86100
path = Path(__file__).parent / "lexicon.json"

db/contact.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515
# ===============================================================================
16+
from typing import List, TYPE_CHECKING
17+
1618
from sqlalchemy import Integer, ForeignKey, String
1719
from sqlalchemy.ext.associationproxy import association_proxy, AssociationProxy
1820
from sqlalchemy.orm import relationship, Mapped, mapped_column
1921
from sqlalchemy_utils import TSVectorType
20-
from typing import List, TYPE_CHECKING
2122

2223
from db.base import Base, AutoBaseMixin, ReleaseMixin, lexicon_term
2324

24-
2525
if TYPE_CHECKING:
2626
from db.field import FieldEventParticipant, FieldEvent
2727
from db.thing import Thing
@@ -118,7 +118,8 @@ class Phone(Base, AutoBaseMixin, ReleaseMixin):
118118
contact_id: Mapped[int] = mapped_column(
119119
ForeignKey("contact.id", ondelete="CASCADE"), nullable=False
120120
)
121-
phone_number: Mapped[str] = mapped_column(String(20), nullable=False)
121+
nma_phone_number: Mapped[str] = mapped_column(String(20), nullable=True)
122+
phone_number: Mapped[str] = mapped_column(String(20), nullable=True)
122123
phone_type: Mapped[str] = lexicon_term(nullable=False)
123124

124125
contact: Mapped["Contact"] = relationship(

db/geochronology.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515
# ===============================================================================
16-
from db.base import AutoBaseMixin, Base, lexicon_term
1716
from sqlalchemy import Integer, Float
1817
from sqlalchemy.orm import mapped_column
1918

19+
from db.base import AutoBaseMixin, Base, lexicon_term
20+
2021

2122
class GeochronologyAge(Base, AutoBaseMixin):
2223
location_id = mapped_column(Integer, nullable=False)

schemas/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
# limitations under the License.
1515
# ===============================================================================
1616
from datetime import datetime, timezone
17+
1718
from pydantic import BaseModel, ConfigDict, AwareDatetime
1819
from pydantic.json_schema import JsonSchemaValue
1920
from pydantic_core import core_schema

schemas/contact.py

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,26 @@ def validate_phone(cls, phone_number_str: str | None) -> str | None:
6767
region = "US"
6868
try:
6969
phone_number_str = phone_number_str.strip()
70+
parsed_number = phonenumbers.parse(phone_number_str, region)
71+
if phonenumbers.is_valid_number(parsed_number):
72+
formatted_number = phonenumbers.format_number(
73+
parsed_number, phonenumbers.PhoneNumberFormat.E164
74+
)
75+
return formatted_number
76+
7077
# this is a major hack to deal with the phone numbers entered into
7178
# NM_Aquifer without an area code
72-
for p in (phone_number_str, f"505{phone_number_str}"):
73-
parsed_number = phonenumbers.parse(p, region)
74-
if phonenumbers.is_valid_number(parsed_number):
75-
formatted_number = phonenumbers.format_number(
76-
parsed_number, phonenumbers.PhoneNumberFormat.E164
77-
)
78-
return formatted_number
79+
# for p in (
80+
# phone_number_str,
81+
# f"505{phone_number_str}",
82+
# f"575{phone_number_str}",
83+
# ):
84+
# parsed_number = phonenumbers.parse(p, region)
85+
# if phonenumbers.is_valid_number(parsed_number):
86+
# formatted_number = phonenumbers.format_number(
87+
# parsed_number, phonenumbers.PhoneNumberFormat.E164
88+
# )
89+
# return formatted_number
7990
else:
8091
raise ValueError(f"Invalid phone number. {phone_number_str}")
8192
except NumberParseException as e:
@@ -89,7 +100,6 @@ class CreateEmail(BaseCreateModel, ValidateEmail):
89100
"""
90101

91102
contact_id: int | None = None # set to None for when made via POST /contact
92-
email: str
93103
email_type: str = "Primary" # Default to 'Primary'
94104

95105

@@ -99,8 +109,8 @@ class CreatePhone(BaseCreateModel, ValidatePhone):
99109
"""
100110

101111
contact_id: int | None = None # set to None for when made via POST /contact
102-
phone_number: str
103112
phone_type: str = "Primary" # Default to 'Primary'
113+
nma_phone_number: str | None = None
104114

105115

106116
class CreateAddress(BaseCreateModel):
@@ -160,8 +170,9 @@ class PhoneResponse(BaseItemResponse):
160170
Response schema for phone details.
161171
"""
162172

163-
phone_number: str
173+
phone_number: str | None = None
164174
phone_type: str # e.g., 'mobile', 'landline', etc.
175+
nma_phone_number: str | None = None
165176

166177

167178
class EmailResponse(BaseItemResponse):

schemas/lexicon.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515
# ===============================================================================
16-
from pydantic import BaseModel, ConfigDict
1716
from typing import List
17+
18+
from pydantic import BaseModel, ConfigDict
19+
1820
from schemas import UTCAwareDatetime
1921

2022

schemas/observation.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@
1414
# limitations under the License.
1515
# ===============================================================================
1616
from datetime import timezone
17+
from typing import Annotated
18+
1719
from pydantic import (
1820
BaseModel,
1921
AwareDatetime,
2022
PastDatetime,
2123
field_validator,
2224
model_validator,
2325
)
24-
from typing import Annotated
2526
from typing_extensions import Self
2627

2728
from schemas import (

schemas/sample.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@
1414
# limitations under the License.
1515
# ===============================================================================
1616
from datetime import timezone
17+
from typing import Annotated
18+
1719
from pydantic import (
1820
BaseModel,
1921
field_validator,
2022
model_validator,
2123
AwareDatetime,
2224
PastDatetime,
2325
)
24-
from typing import Annotated
2526
from typing_extensions import Self
2627

2728
from schemas import (
@@ -30,9 +31,9 @@
3031
BaseResponseModel,
3132
UTCAwareDatetime,
3233
)
33-
from schemas.thing import ThingResponse
34-
from schemas.field import FieldEventResponse, FieldActivityResponse
3534
from schemas.contact import ContactResponse
35+
from schemas.field import FieldEventResponse, FieldActivityResponse
36+
from schemas.thing import ThingResponse
3637

3738

3839
# -------- VALIDATE ----------

schemas/thing.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from schemas import BaseCreateModel, BaseUpdateModel, BaseResponseModel
2121
from schemas.location import LocationResponse
2222

23+
2324
# -------- VALIDATE ----------
2425

2526

0 commit comments

Comments
 (0)