I have a small application where I need to read data from a JSON file, display it, and allow users to add records to it. Specifically, I have an array called condition
within the patient
object, and I want to insert a new item into this array based on user input. The added data does not need to be stored or submitted via POST request.
I am unsure whether I should retrieve information from the Patient
object or from $scope. There is no data submission involved.
Is the implementation of function addCondition
correct?
/* Data */
angular.module('prototypeApp')
.factory('MedicalRecords', function($http) {
return $http.get('scripts/data/patient_record.json');
});
/* Add more Information to Patients Conditions */
angular.module('prototypeApp')
.controller('PatientExtConditionCtrl', function ($scope, MedicalRecords) {
MedicalRecords.success(function(data) {
$scope.patient = data;
});
});
/* Confirm Patients Conditions */
angular.module('prototypeApp')
.controller('PatientConditionCtrl', function ($scope, MedicalRecords) {
MedicalRecords.success(function(data) {
$scope.patient = data;
});
});
/* FormController */
angular.module('prototypeApp')
.controller('AddConditionCtrl', function () {
this.condition = {};
this.addCondition = function(patient){
patient.patientCondition.push(this.condition);
};
});
/* in my template */
<form name="AddConditionForm" ng-controller="AddConditionCtrl" ng-submit="AddConditionCtrl.addCondition(patient)">
<input type="text" class="form-control" ng-model="AddConditionCtrl.condition.hcc">
<input type="text" class="form-control" id="input_description" ng-model="AddConditionCtrl.condition.description">
<input type="text" class="form-control" ng-model="AddConditionCtrl.condition.last_report">
<button type="submit" class="btn btn-primary">Add</button>
</form>
<table class="table table-striped">
<tr>
<th>Code</th>
<th>Condition</th>
<th>Last Reported</th>
<th>Check</th>
</tr>
<tr ng-repeat="condition in patient.patientCondition">
<td>{{ condition.hcc }} </td>
<td>{{ condition.description }}</td>
<td>{{ condition.last_report | date }}</td>
<td> Check </td>
</tr>
</table>
<form action="/#/patient/conditions/ext">
<button type="submit" class="btn btn-primary pull-right">Next</button>
</form>