Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed DM+D import routines #32

Merged
merged 1 commit into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Loading