Skip to content

Commit

Permalink
contact id fix (#5610)
Browse files Browse the repository at this point in the history
* contact id fix

* only allow 1 contact per foreign table name and foreign id

* getting closer

* minor fix
  • Loading branch information
bradymiller committed Jul 18, 2022
1 parent fe233bc commit b9e0d54
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
27 changes: 23 additions & 4 deletions src/Common/ORDataObject/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,37 @@ class Contact extends ORDataObject
public function __construct($id)
{
parent::__construct("contact");
$this->_id = $id;
$this->id = $id;

if (!empty($id)) {
$this->populate();
}
}

public function setPatientPid($pid)
public function setContactRecord(string $foreign_table_name, int $foreign_id): void
{
// we set our type to be patient_id and our table type here.
$this->foreign_table_name = 'patient_data';
$this->foreign_id = $pid;
$this->foreign_table_name = $foreign_table_name;
$this->foreign_id = $foreign_id;

$this->setContactIdIfExist();
}

public function persist()
{
if (empty($this->id)) {
$this->setContactIdIfExist();
}
return parent::persist();
}

private function setContactIdIfExist(): void
{
$id = sqlQuery("SELECT `id` FROM `contact` WHERE `foreign_table_name` = ? AND `foreign_id` = ?", [$this->foreign_table_name, $this->foreign_id])['id'] ?? null;
if (!empty($id)) {
// the contact entry already exists for this foreign table name and foreign id, so set it
$this->id = $id;
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Services/ContactService.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public function convertArraysToRecords($pid, $contactData)

$contact = $contactAddress->getContact();
// then we will create our contacts record as well
$contact->setPatientPid($pid);
$contact->setContactRecord('patient_data', $pid);

// here we can handle all of our data actions
if ($contactData['data_action'][$i] == 'INACTIVATE') {
Expand Down

0 comments on commit b9e0d54

Please sign in to comment.