Skip to content

Commit

Permalink
Merge pull request #32 from AppertaFoundation/fix/dmd-fix
Browse files Browse the repository at this point in the history
fixed DM+D import routines
  • Loading branch information
david-jobling authored May 9, 2024
2 parents c53b9fa + 00c2b3f commit 42519e9
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
14 changes: 12 additions & 2 deletions protected/commands/ImportDrugsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public function getHelp()

private function _getImportDir()
{
return getenv('DMD_EXTRACT_FOLDER') ?? Yii::getPathOfAlias('application') . '/data/dmd_data';
return getenv('DMD_EXTRACT_FOLDER') ?: Yii::getPathOfAlias('application') . '/data/dmd_data';
}

public function getParams($params)
Expand Down Expand Up @@ -473,6 +473,10 @@ public function createInsertSqlCommands($xmlArray, $type, $tablesData)

$k = array_keys($rows);

if (!isset($k[0])) {
continue;
}

if ($k[0] == '0') {
$subsubnode = $rows;
} else {
Expand All @@ -482,7 +486,13 @@ public function createInsertSqlCommands($xmlArray, $type, $tablesData)
$multipleValues = '';
$multipleValuesMaxCount = 100;
$multipleValuesCurrentCount = 0;
$rowCount = sizeof($subsubnode);


if (is_null($subsubnode)) {
continue;
}

$rowCount = count($subsubnode);
foreach ($subsubnode as $rowIndex => $oneRow) {
if ($limit <= $i++ && $limit != 0) {
break;
Expand Down
25 changes: 24 additions & 1 deletion protected/migrations/data/dmd_import/delete.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ SELECT id
FROM medication_set
WHERE `name` = 'DM+D AMP' OR `name` = 'DM+D VMP' OR `name` = 'DM+D VTM';

DELETE FROM medication_set_item_taper WHERE medication_set_item_id in (select id from medication_set_item WHERE medication_id IN (SELECT id FROM medication WHERE source_type='DM+D'));

DELETE FROM medication_set_item WHERE medication_set_id IN (SELECT id FROM tmp_delete_from_sets);

DELETE FROM medication_set_item WHERE medication_id IN (SELECT id FROM medication WHERE source_type='DM+D');
Expand All @@ -15,22 +17,43 @@ DELETE FROM medication_set_auto_rule_set_membership WHERE target_medication_set_

DELETE FROM medication_set_auto_rule_set_membership WHERE source_medication_set_id IN (SELECT id FROM tmp_delete_from_sets);

DELETE FROM medication_set_auto_rule_medication_taper WHERE medication_set_auto_rule_id in (SELECT id FROM medication_set_auto_rule_medication WHERE medication_id IN (SELECT id FROM medication WHERE source_type='DM+D'));

DELETE FROM medication_set_auto_rule_medication WHERE medication_id IN (SELECT id FROM medication WHERE source_type='DM+D');

DELETE FROM event_medication_use WHERE prescription_item_id in (SELECT rmu.id FROM event_medication_use rmu LEFT JOIN medication rm ON rm.id = rmu.medication_id WHERE rm.source_type = 'DM+D');

DELETE FROM ophdrprescription_item_taper WHERE item_id in (SELECT rmu.id FROM event_medication_use rmu LEFT JOIN medication rm ON rm.id = rmu.medication_id WHERE rm.source_type = 'DM+D');

DELETE rmu FROM event_medication_use rmu LEFT JOIN medication rm ON rm.id = rmu.medication_id WHERE rm.source_type = 'DM+D';

DELETE FROM medication_search_index WHERE medication_id IN (SELECT id FROM medication WHERE source_type = 'DM+D');
DELETE FROM medication WHERE source_type = 'DM+D';
DELETE FROM medication_set WHERE `name` IN ('DM+D AMP', 'DM+D VMP', 'DM+D VTM');
DELETE FROM medication_attribute_assignment;
ALTER TABLE medication_attribute_assignment AUTO_INCREMENT = 1;

DELETE FROM medication_set_auto_rule_attribute where medication_attribute_option_id in (SELECT id FROM medication_attribute_option);

DELETE FROM medication_attribute_option;
ALTER TABLE medication_attribute_option AUTO_INCREMENT = 1;
DELETE FROM medication_attribute;
ALTER TABLE medication_attribute AUTO_INCREMENT = 1;
DELETE FROM medication_form WHERE source_type = 'DM+D';

DELETE FROM medication_set_item WHERE default_route_id in (SELECT id FROM medication_route WHERE source_type = 'DM+D');
DELETE FROM medication_set_auto_rule_medication WHERE default_route_id in (SELECT id FROM medication_route WHERE source_type = 'DM+D');
DELETE FROM medication_set_auto_rule_medication where medication_id in (SELECT id FROM medication WHERE default_route_id in (SELECT id FROM medication_route WHERE source_type = 'DM+D'));
DELETE FROM medication_search_index where medication_id in (SELECT id FROM medication WHERE default_route_id in (SELECT id FROM medication_route WHERE source_type = 'DM+D'));
DELETE FROM medication_set_item where medication_id in (SELECT id FROM medication WHERE default_route_id in (SELECT id FROM medication_route WHERE source_type = 'DM+D'));
DELETE FROM event_medication_use WHERE prescription_item_id in (SELECT id FROM event_medication_use where medication_id in (SELECT id FROM medication WHERE default_route_id in (SELECT id FROM medication_route WHERE source_type = 'DM+D')));
DELETE FROM event_medication_use where medication_id in (SELECT id FROM medication WHERE default_route_id in (SELECT id FROM medication_route WHERE source_type = 'DM+D'));
DELETE FROM medication WHERE default_route_id in (SELECT id FROM medication_route WHERE source_type = 'DM+D');
DELETE FROM event_medication_use where route_id in (SELECT id FROM medication_route WHERE source_type = 'DM+D');


DELETE FROM medication_route WHERE source_type = 'DM+D';

DROP TABLE tmp_delete_from_sets;

COMMIT;
COMMIT;

0 comments on commit 42519e9

Please sign in to comment.