Skip to content

Commit

Permalink
Add support for importing inventory and products (#179)
Browse files Browse the repository at this point in the history
* Add functionality to import products as Group resources

* Update read me

* Create images folder if it doesn't already exist

* Mock image binary

* Add support for importing inventories

* Update product-group template

* Update inventory-group

* Update inventory csv and code

* Use GROUP_INDEX_MAPPING in group_extras

* black formatting

* move deletion to outside the condition
  • Loading branch information
Wambere authored Apr 30, 2024
1 parent 96d4bc3 commit 3a19579
Show file tree
Hide file tree
Showing 7 changed files with 854 additions and 132 deletions.
15 changes: 14 additions & 1 deletion importer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,17 @@ The coverage report `coverage.html` will be at the working directory
- The `value` is where you pass the actual parameter value to filter the resources. The set default value is "gt2023-01-01", other examples include, "Good Health Clinic 1"
- The `limit` is the number of resources exported at a time. The set default value is '1000'
- Specify the `resource_type` you want to export, different resource_types are exported to different csv_files
- The csv_file containing the exported resources is labelled using the current time, to know when the resources were exported for example, csv/exports/2024-02-21-12-21-export_Location.csv
- The csv_file containing the exported resources is labelled using the current time, to know when the resources were exported for example, csv/exports/2024-02-21-12-21-export_Location.csv

### 10. Import products from openSRP 1
- Run `python3 main.py --csv_file csv/import/product.csv --setup products --log_level info`
- See example csv [here](/importer/csv/import/product.csv)
- This creates a Group resource for each product imported
- The first two columns __name__ and __active__ is the minimum required
- The last column __imageSourceUrl__ contains a url to the product image. If this source requires authentication, then you need to provide the `product_access_token` in the config file. The image is added as a binary resource and referenced in the product's Group resource

### 11. Import inventories from openSRP 1
- Run `python3 main.py --csv_file csv/import/inventory.csv --setup inventories --log_level info`
- See example csv [here](/importer/csv/import/inventory.csv)
- This creates a Group resource for each inventory imported
- The first two columns __name__ and __active__ is the minimum required
2 changes: 2 additions & 0 deletions importer/csv/import/inventory.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
name,active,method,id,poNumber,serialNumber,usualId,actual,productId,deliveryDate,accountabilityDate,quantity,unicefSection,donor
Bishop Magua - Bed nets,true,create,8adfcfe0-41d0-4f0a-9a89-909c72fbf330,123523,989682,a065c211-cf3e-4b5b-972f-fdac0e45fef7,false,1d86d0e2-bac8-4424-90ae-e2298900ac3c,2024-02-01T00:00:00.00Z,2025-02-01T00:00:00.00Z,34,Health,GAVI
3 changes: 3 additions & 0 deletions importer/csv/import/product.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name,active,method,id,previousId,isAttractiveItem,availability,condition,appropriateUsage,accountabilityPeriod,imageSourceUrl
thermometer,true,create,1d86d0e2-bac8-4424-90ae-e2298900ac3c,10,true,yes,good,ok,12,https://ona.io/home/wp-content//uploads/2022/06/spotlight-fhir.png
sterilizer,true,create,,53209452,true,no,,,,
128 changes: 128 additions & 0 deletions importer/json_payloads/inventory_group_payload.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
{
"request": {
"method": "PUT",
"url": "Group/$unique_uuid",
"ifMatch": "$version"
},
"resource": {
"resourceType": "Group",
"id": "$unique_uuid",
"identifier": [
{
"type": {
"coding": [
{
"system": "http://smartregister.org/codes",
"code": "SERNUM",
"display": "Serial Number"
}
],
"text": "Serial Number"
},
"use": "official",
"value": "$serial_number"
},
{
"type": {
"coding": [
{
"system": "http://smartregister.org/codes",
"code": "PONUM",
"display": "PO Number"
}
],
"text": "PO Number"
},
"use": "secondary",
"value": "$po_number"
},
{
"use": "usual",
"value": "$usual_id"
}
],
"active": "$active",
"type": "substance",
"actual": "$actual",
"code": {
"coding": [
{
"system": "http://smartregister.org/codes",
"code": "78991122",
"display": "Supply Inventory"
}
]
},
"name": "$name",
"member": [
{
"entity": {
"reference": "Group/$product_id"
},
"period": {
"start": "$delivery_date",
"end": "$accountability_date"
},
"inactive": false
}
],
"characteristic": [
{
"code": {
"coding": [
{
"system": "http://smartregister.org/codes",
"code": "33467722",
"display": "Quantity"
}
]
},
"valueQuantity": {
"value": "$quantity"
}
},
{
"code": {
"coding": [
{
"system": "http://smartregister.org/codes",
"code": "98734231",
"display": "Unicef Section"
}
]
},
"valueCodeableConcept": {
"coding": [
{
"system": "http://smartregister.org/codes",
"code": "98734231-1",
"display": "Value entered on the unicef section"
}
],
"text": "$unicef_section"
}
},
{
"code": {
"coding": [
{
"system": "http://smartregister.org/codes",
"code": "45981276",
"display": "Donor"
}
]
},
"valueCodeableConcept": {
"coding": [
{
"system": "http://smartregister.org/codes",
"code": "45981276-1",
"display": "Value entered on the donor"
}
],
"text": "$donor"
}
}
]
}
}
145 changes: 145 additions & 0 deletions importer/json_payloads/product_group_payload.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
{
"request": {
"method": "PUT",
"url": "Group/$unique_uuid",
"ifMatch" : "$version"
},
"resource": {
"resourceType": "Group",
"id": "$unique_uuid",
"identifier": [
{
"type":{
"coding": {
"system" : "http://smartregister.org/codes",
"code" : "MATNUM" ,
"display": "Material Number"
}
},
"use": "official",
"value": "$unique_uuid"
},
{
"use": "secondary",
"value": "$previous_id"
}
],
"active": "$active",
"type": "substance",
"code": {
"coding": [
{
"system": "http://snomed.info/sct",
"code": "386452003",
"display": "Supply management"
}
]
},
"name": "$name",
"characteristic": [
{
"code": {
"coding": [
{
"system": "http://smartregister.org/codes",
"code": "23435363",
"display": "Attractive Item code"
}
]
},
"valueBoolean": "$isAttractiveItem"
},
{
"code": {
"coding": [
{
"system": "http://smartregister.org/codes",
"code": "34536373",
"display": "Is it there code"
}
]
},
"valueCodeableConcept": {
"coding": [
{
"system": "http://smartregister.org/codes",
"code": "34536373-1",
"display": "Value entered on the It is there code"
}
],
"text": "$availability"
}
},
{
"code": {
"coding": [
{
"system": "http://smartregister.org/codes",
"code": "45647484",
"display": "Is it in good condition? (optional)"
}
]
},
"valueCodeableConcept": {
"coding": [
{
"system": "http://smartregister.org/codes",
"code": "45647484-1",
"display": "Value entered on the Is it in good condition? (optional)"
}
],
"text": "$condition"
}
},
{
"code": {
"coding": [
{
"system": "http://smartregister.org/codes",
"code": "56758595",
"display": "Is it being used appropriately?"
}
]
},
"valueCodeableConcept": {
"coding": [
{
"system": "http://smartregister.org/codes",
"code": "56758595-1",
"display": "Value entered on the Is it being used appropriately?"
}
],
"text": "$appropriateUsage"
}
},
{
"code": {
"coding": [
{
"system": "http://smartregister.org/codes",
"code": "67869606",
"display": "Accountability period (in months)"
}
]
},
"valueQuantity": {
"value": "$accountabilityPeriod"
}
},
{
"code": {
"coding": [
{
"system": "http://smartregister.org/codes",
"code": "12314156",
"display": "Product Image code"
}
]
},
"valueReference": {
"reference": "Binary/$image-binary"
}
}
]
}
}
Loading

0 comments on commit 3a19579

Please sign in to comment.